Saturday, December 28, 2013

Freezing Temp Alert

I created an alert on my phone to tell me when the temperature outside drops below freezing. Since I don't have my own network accessible thermometer, I am using the wunderground api to query the closest weather station, a couple of miles away. It should be close enough.

I used this blog post as a guide for accessing the wunderground api:  http://www.pocketables.com/2012/07/tasker-task-that-speaks-the-weather-forecast-download.html

I set up a wunderground developer account here: http://www.wunderground.com/weather/api/

In Tasker:

The profile runs every hour.

The task is as follows:

A1: HTTP Get [ Server:Port:api.wunderground.com Path:/api/[mykey]/conditions/q/[my state abbrev]/[the town or neigborhood with the station I wanted to query].xml Attributes: Cookies: Timeout:10 Mime Type:text/plain Output File: ]

A2: Variable Set [ Name:%wunderresults To:%HTTPD Do Maths:Off Append:Off ]

A3: Variable Search Replace [ Variable:%wunderresults Search:\<temp\_f\>\d\d.\d\<\/temp\_f\> Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%matchedtemp Replace Matches:Off Replace With:a ]

A4: Variable Search Replace [ Variable:%matchedtemp1 Search:\d\d.\d Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%matchedtemptwo Replace Matches:Off Replace With: ]

A5: Variable Set [ Name:%oakbrookTemp To:%matchedtemptwo1 Do Maths:Off Append:Off ]

A6: Flash [ Text:%myTemp Long:Off ]

A7: If [ %myTemp < 33 ]

A8: Notify [ Title:Temperature Warning Text:%myTemp Icon:hd_alerts_and_states_warning Number:0 Permanent:Off Priority:3 ]



I had to do some parsing gymnastics to get the temperature out of the xml returned from wunderground (actions 3 and 4).

I also have the temp display on a MimialistText widget so I can see the temp anytime, not just when it's freezing.

No comments:

Post a Comment