ACC help - Weather Underground PWS Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
elbeau
Posts: 18
Joined: 08 Aug 2020, 18:20

ACC help - Weather Underground PWS

07 Nov 2020, 13:54

I'm trying to figure out how to export selected data from a weather underground personal weather station (that isn't mine) now that they've removed public access from their API.
Let's say the page is https://www.wunderground.com/dashboard/pws/KNEOMAHA130
I've been able to get the text from the "name" of wind gusts. However, I can't figure out how to get the name/path of that to poll it without hovering my mouse over it.
The script I used is pasted below.

Code: Select all

*^t:: Msgbox % GetTextUnderMouse() 

GetTextUnderMouse(){
      Acc := Acc_ObjectFromPoint(child)
      try value := Acc.accValue(child)
      if Not value
                  try value := Acc.accName(child)
                 return value
}
return
I am just looking for a way to poll that info so I can then set up an alert to roll up my shades when it gets windy!
Last edited by BoBo on 11 Nov 2020, 02:21, edited 2 times in total.
Reason: Fixed broken link.
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: ACC help - Weather Underground PWS

07 Nov 2020, 14:01

I will just offer an alternative in case it helps you: I use OpenWeather-- very easy and reliable to get the weather in text form with their API. I wrote a WeatherAlert AHK script to do what you are saying, but I use a temperature alert instead of wind. I will be posting the script on the forum. My script allows the user to enter an absolute temperature or a temperature change to get an alert that then appears on screen and also can be sent via e-mail.

Getting text from a Web page display can be messy. I'm not sure how that URL downloads-- how it looks-- but that is sometimes easier than trying to grab from the screen.

You can probably use OpenWeather for your own needs, too, with your script.

https://openweathermap.org/
elbeau
Posts: 18
Joined: 08 Aug 2020, 18:20

Re: ACC help - Weather Underground PWS

07 Nov 2020, 14:42

mikeyww wrote:
07 Nov 2020, 14:01
I will just offer an alternative in case it helps you: I use OpenWeather-- very easy and reliable to get the weather in text form with their API. I wrote a WeatherAlert AHK script to do what you are saying, but I use a temperature alert instead of wind. I will be posting the script on the forum. My script allows the user to enter an absolute temperature or a temperature change to get an alert that then appears on screen and also can be sent via e-mail.
Thank you for your input - that sounds like it will be helpful for a slightly different use case.
I'm lucky enough that there's a personal weather station virtually across the street from me, so I can get pretty accurate information about the wind speeds if I could just figure out how to pull the ACC info.
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: ACC help - Weather Underground PWS

07 Nov 2020, 16:03

Code: Select all

url = https://www.wunderground.com/dashboard/pws/KNEOMAHA130
out = %TEMP%\weather.html
SplashTextOn, 300, 100, Please wait, `nChecking....
UrlDownloadToFile, %url%, %out%
SplashTextOff
FileRead, weather, %out%
RegExMatch(weather, "WIND &amp; GUST.+?;"">\K.+?(?=</span>)", m)
MsgBox, 64, Wind speed, %m% mph
elbeau
Posts: 18
Joined: 08 Aug 2020, 18:20

Re: ACC help - Weather Underground PWS

07 Nov 2020, 17:29

mikeyww wrote:
07 Nov 2020, 16:03

Code: Select all

url = https www.wunderground.com /dashboard/pws/KNEOMAHA130  Broken Link for safety
out = %TEMP%\weather.html
SplashTextOn, 300, 100, Please wait, `nChecking....
UrlDownloadToFile, %url%, %out%
SplashTextOff
FileRead, weather, %out%
RegExMatch(weather, "WIND &amp; GUST.+?;"">\K.+?(?=</span>)", m)
MsgBox, 64, Wind speed, %m% mph
That works - thank you!
I tried to decipher the code, but I'm lost when it comes to RegEX - how can I add the wind gusts?
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: ACC help - Weather Underground PWS

07 Nov 2020, 17:45

Code: Select all

url = https://www.wunderground.com/dashboard/pws/KNEOMAHA130
out = %TEMP%\weather.html
SplashTextOn, 300, 100, Please wait, `nChecking....
UrlDownloadToFile, %url%, %out%
SplashTextOff
FileRead, weather, %out%
RegExMatch(weather, "WIND &amp; GUST.+?;"">(.+?)</span>.+?;"">(.+?)</span>", m)
MsgBox, 64, Wind speed, Wind: %m1% mph`nGust: %m2% mph
elbeau
Posts: 18
Joined: 08 Aug 2020, 18:20

Re: ACC help - Weather Underground PWS

07 Nov 2020, 19:01

mikeyww wrote:
07 Nov 2020, 17:45

Code: Select all

url = https://www.wunderground.com/dashboard/pws/KNEOMAHA130
out = %TEMP%\weather.html
SplashTextOn, 300, 100, Please wait, `nChecking....
UrlDownloadToFile, %url%, %out%
SplashTextOff
FileRead, weather, %out%
RegExMatch(weather, "WIND &amp; GUST.+?;"">(.+?)</span>.+?;"">(.+?)</span>", m)
MsgBox, 64, Wind speed, Wind: %m1% mph`nGust: %m2% mph
Nice job- thank you. I'm still hoping to learn how to track it down through ACC, but this is darn cool, too. Thanks again!
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: ACC help - Weather Underground PWS

10 Nov 2020, 23:53

Not for me. ;)
https://api.weather.com/v2/pws/observat ... on&units=e
apiKey - is public key.
Last edited by BoBo on 11 Nov 2020, 02:17, edited 2 times in total.
Reason: Removed the API key by of privacy concerns (just in case you’ve posted it by mistake?). Feel free to add it again. Added its output instead. Rgds, Bo
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: ACC help - Weather Underground PWS

11 Nov 2020, 05:18

Yes, I've mentioned OpenWeather as well. The API calls are easy, reliable, and fast. They return a simple text string that is easy to parse. The issue here seemed to be that there was a weather station of interest especially nearby. I'm not sure how much weather conditions differ over a range of one or two kilometers, but both methods will work in any case. Just about all of the big weather service providers have an API service.

Code: Select all

; https://www.weather.gov/documentation/services-web-api
RegExMatch(webGet("https://api.weather.gov/gridpoints/OAX/75,56/forecast"), "Speed"": ""\K\d+ mph", m)
MsgBox, 64, Wind speed, %m%

webGet(url) {
 ; https://jacks-autohotkey-blog.com/2019/05/06/autohotkey-web-data-extraction-regex-trick/
 whr := ComObjCreate("WinHttp.WinHttpRequest.5.1"), whr.Open("GET", url)
 Try {
  whr.Send()
  Sleep 100
  response := whr.ResponseText
 }
 Catch, err
  errMsg := "Problem:  " err.Extra
   . "`nFile:          " err.File
   . "`nLine:         " err.Line
   . "`n              " err.What
   . "`nError:                       " err.Message
 Return response
}
Last edited by mikeyww on 11 Nov 2020, 05:44, edited 5 times in total.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: ACC help - Weather Underground PWS

11 Nov 2020, 05:25

wunderground.com uses json from weather.com
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: ACC help - Weather Underground PWS  Topic is solved

11 Nov 2020, 05:59

Code: Select all

station := "KNEOMAHA130", key := "6532d6454b8aa370768e63d6ba5a832e"
url := "https://api.weather.com/v2/pws/observations/current"
     . "?apiKey=" key "&stationId=" station "&numericPrecision=decimal&format=json&units=e"
SplashTextOn, 300, 100, Working, `nPlease wait....
RegExMatch(webGet(url), "Speed"":(.+?),.+Gust"":(.+?),", m)
SplashTextOff
MsgBox, 64, Wind, Speed: %m1%`n`n   Gust: %m2%

webGet(url) {
 ; https://jacks-autohotkey-blog.com/2019/05/06/autohotkey-web-data-extraction-regex-trick/
 whr := ComObjCreate("WinHttp.WinHttpRequest.5.1"), whr.Open("GET", url)
 Try {
  whr.Send()
  Sleep 100
  response := whr.ResponseText
 }
 Catch, err
  errMsg := "Problem:  " err.Extra
   . "`nFile:          " err.File
   . "`nLine:         " err.Line
   . "`n              " err.What
   . "`nError:                       " err.Message
 Return response
}
elbeau
Posts: 18
Joined: 08 Aug 2020, 18:20

Re: ACC help - Weather Underground PWS

12 Nov 2020, 15:32

I had not discovered that I could use the weather.com API to access the local PWS stations near my home. Thank you to malcev for sharing that nugget and many thanks to Mikeyww who put it all together so only the data I wanted is parsed out.

Now that I have that, I can work on a script that'll poll the data and alert me if the wind gusts pass a certain threshold. The end goal is to automate my motorized outdoor shades for inclement weather. I've got some zemismart RF roller shade motors coming to integrate with the open-source smart Home Assistant.https://www.home-assistant.io/

Thank you guys again — I appreciate it!

~Beau
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: ACC help - Weather Underground PWS

12 Nov 2020, 15:49

Sounds good. An example is below in case useful.

Code: Select all

#Persistent
SetTimer, WindCheck, 4000
Return

WindCheck:
wind := getWind("KNEOMAHA130")
message := (wind.speed > 2 || wind.gust > 2) ? "It's too windy!" : "Where's the wind?"
MsgBox, 64, % "Speed: " wind.speed ", Gust: " wind.gust, %message%, 2
Return

getWind(station) {
 url := "https://api.weather.com/v2/pws/observations/current?"
      . "numericPrecision=decimal&format=json&units=e&apiKey=6532d6454b8aa370768e63d6ba5a832e&"
      . "stationId=" station
 If RegExMatch(webGet(url), "Speed"":(.+?),.+Gust"":(.+?),", m)
  Return {speed: m1, gust: m2}
}

webGet(url) {
 ; https://jacks-autohotkey-blog.com/2019/05/06/autohotkey-web-data-extraction-regex-trick/
 whr := ComObjCreate("WinHttp.WinHttpRequest.5.1"), whr.Open("GET", url)
 Try {
  whr.Send()
  Sleep 100
  response := whr.ResponseText
 }
 Catch, err
  errMsg := "Problem:  " err.Extra
   . "`nFile:          " err.File
   . "`nLine:         " err.Line
   . "`n              " err.What
   . "`nError:                       " err.Message
 Return response
}
I would suggest setting the timer for 15 minutes or so to avoid overburdening the weather server.
elbeau
Posts: 18
Joined: 08 Aug 2020, 18:20

Re: ACC help - Weather Underground PWS

13 Nov 2020, 12:21

That's very helpful @mikeyww. I modified the script to run every 15 minutes. It'll be a month before I get my roller blind motors, but looking forward to incorporating this upon their arrival. :xmas:
joekingcool
Posts: 238
Joined: 14 Dec 2019, 20:21

Re: ACC help - Weather Underground PWS

17 Jul 2021, 16:58

hi i was wanting to make a basic weather app that shows the feel like temp for the next 3 days. i found this script very helpful and functional. most other ahk scripts for weather dont work anymore. i was tring to figure out how you got the wind speed and gusts from weather.com. could you explain please?
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: ACC help - Weather Underground PWS

18 Jul 2021, 06:42

If you display the string returned from webget, you will see something like the following.

{"observations":[{"stationID":"KNEOMAHA130","obsTimeUtc":"2021-07-18T11:40:29Z","obsTimeLocal":"2021-07-18 06:40:29","neighborhood":" Stoneybrook South","softwareType":"Cumulus v3.2.4","country":"US","solarRadiation":null,"lon":-96.131027,"realtimeFrequency":null,"epoch":1626608429,"lat":41.190483,"uv":null,"winddir":0,"humidity":92.0,"qcStatus":1,"imperial":{"temp":66.3,"heatIndex":66.3,"dewpt":63.9,"windChill":66.3,"windSpeed":0.0,"windGust":0.0,"pressure":30.20,"precipRate":0.00,"precipTotal":0.00,"elev":1142.0}}]}

The RegExMatch then looks for the numbers corresponding to those key names (or partial strings).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, DaveT1, Joey5, KolaBorat, Thorlian and 164 guests