Tasker and Weather Underground - Use JAVA instead of the confusing variable splitting.

522 views
Skip to first unread message

Joe Costa

unread,
Apr 15, 2015, 9:53:45 PM4/15/15
to tas...@googlegroups.com
HTTP Get and Variable Split was a little confusing to me and so I found an easier way.

This is the easiest way to get the data from Wunderground and show it using java.  I disabled the task that loads java from a file and loaded it through tasker instead but you can use it either way.

This will get the json data from wunderground and get an animated map from weather.gov and also show you an icon of the current weather conditions.  The images are downloaded to your download directory on your phone. Map and weather data can be moved/scrolled to view.

3 things to change.
1) Change the program name in case you export it as an APP (not necessary to run)
Find "<pkg>com.google.xxxxxxxxxxxx.weatherconditionsandmap</pkg>" and change if you want to make your own app using tasker app factory

2)  Change the API to the one you have and change the STATE and ZIPCODE.  I X'ed out my API number. (necessary to run)
Find "/api/xxxxxxxxxxxxxxxx/forecast/q/MI/49015.json</Str>" and change your API.

3)  Change the map to your favorite weather map (not necessary to run)
Find <Str sr="arg0" ve="3">radar.weather.gov</Str> 
Find <Str sr="arg1" ve="3">Conus/Loop/centgrtlakes_loop.gif</Str> and change if you live somewhere else




<TaskerData sr="" dvi="1" tv="4.6u3m">
	<dmetric>1440.0,2560.0</dmetric>
	<Project sr="proj0" ve="2">
		<cdate>1429042043410</cdate>
		<name>Weather Conditions and Map</name>
		<scenes>WU Window</scenes>
		<tids>2</tids>
		<Kid sr="Kid">
			<launchID>41</launchID>
			<pkg>com.google.xxxxxxxxxxxx.weatherconditionsandmap</pkg>
			<vnme>1.0</vnme>
			<vnum>3</vnum>
		</Kid>
		<Img sr="icon" ve="2">
			<fle>/storage/sdcard0/Download/mostlycloudy.gif</fle>
		</Img>
	</Project>
	<Scene sr="sceneWU Window">
		<cdate>1429053695004</cdate>
		<edate>1429146227255</edate>
		<gridSize>20</gridSize>
		<heightLand>1187</heightLand>
		<heightPort>2520</heightPort>
		<nme>WU Window</nme>
		<widthLand>1593</widthLand>
		<widthPort>1440</widthPort>
		<RectElement sr="elements0">
			<flags>6</flags>
			<geom>0,0,1440,2520,0,0,1591,1187</geom>
			<Str sr="arg0" ve="3">Background</Str>
			<Int sr="arg1" val="0"/>
			<Str sr="arg2" ve="3">#FF333333</Str>
			<Str sr="arg3" ve="3"/>
			<Int sr="arg4" val="0"/>
			<Str sr="arg5" ve="3">#FF000000</Str>
			<Int sr="arg6" val="0"/>
			<Int sr="arg7" val="0"/>
		</RectElement>
		<TextElement sr="elements1" ve="3">
			<flags>4</flags>
			<geom>0,2020,1440,500,3,618,310,568</geom>
			<Str sr="arg0" ve="3">Text Low</Str>
			<Str sr="arg1" ve="3">Current Conditions:
High: %wuhigh Low: %wulow
Max Wind: %wumaxwindmph
Avg Wind: %wuavewindmph
Avg Wind Dir: %wuavewinddir
Avg Humidity: %wuavehumidity</Str>
			<Int sr="arg2" val="14"/>
			<Int sr="arg3" val="100"/>
			<Str sr="arg4" ve="3">#FFFFFFFF</Str>
			<Str sr="arg5" ve="3"/>
			<Int sr="arg6" val="5"/>
			<Int sr="arg7" val="0"/>
			<Int sr="arg8" val="0"/>
		</TextElement>
		<TextElement sr="elements2" ve="3">
			<flags>4</flags>
			<geom>0,1520,1440,500,0,0,687,1187</geom>
			<Str sr="arg0" ve="3">Text High</Str>
			<Str sr="arg1" ve="3">Today is %wutitle1. %wufcttext1. Later for %wutitle2, %wufcttext2.</Str>
			<Int sr="arg2" val="18"/>
			<Int sr="arg3" val="100"/>
			<Str sr="arg4" ve="3">#FFFFFFFF</Str>
			<Str sr="arg5" ve="3"/>
			<Int sr="arg6" val="5"/>
			<Int sr="arg7" val="0"/>
			<Int sr="arg8" val="0"/>
		</TextElement>
		<WebElement sr="elements3" ve="2">
			<flags>4</flags>
			<geom>0,0,1440,1520,0,0,1531,1187</geom>
			<Str sr="arg0" ve="3">WebView Map</Str>
			<Int sr="arg1" val="0"/>
			<Str sr="arg2" ve="3">file:///sdcard/Download/weatherloop.gif</Str>
			<Int sr="arg3" val="0"/>
			<Int sr="arg4" val="0"/>
			<Int sr="arg5" val="0"/>
			<Int sr="arg6" val="0"/>
		</WebElement>
		<WebElement sr="elements4" ve="2">
			<flags>4</flags>
			<geom>0,0,215,216,-1,-1,-1,-1</geom>
			<Str sr="arg0" ve="3">WebView Weather Icon</Str>
			<Int sr="arg1" val="0"/>
			<Str sr="arg2" ve="3">file:///sdcard/Download/wuicon.gif</Str>
			<Int sr="arg3" val="0"/>
			<Int sr="arg4" val="0"/>
			<Int sr="arg5" val="0"/>
			<Int sr="arg6" val="0"/>
		</WebElement>
	</Scene>
	<Task sr="task2">
		<cdate>1399067203285</cdate>
		<edate>1429146259470</edate>
		<id>2</id>
		<nme>Weather Conditions and Map</nme>
		<pri>10</pri>
		<Action sr="act0" ve="7">
			<code>548</code>
			<Str sr="arg0" ve="3">Getting map</Str>
			<Int sr="arg1" val="0"/>
		</Action>
		<Action sr="act1" ve="7">
			<code>118</code>
			<Str sr="arg0" ve="3">radar.weather.gov</Str>
			<Str sr="arg1" ve="3">Conus/Loop/centgrtlakes_loop.gif</Str>
			<Str sr="arg2" ve="3"/>
			<Str sr="arg3" ve="3"/>
			<Str sr="arg4" ve="3"/>
			<Int sr="arg5" val="10"/>
			<Str sr="arg6" ve="3">image/*</Str>
			<Str sr="arg7" ve="3">Download/weatherloop.gif</Str>
			<Int sr="arg8" val="0"/>
		</Action>
		<Action sr="act2" ve="7">
			<code>118</code>
			<Str sr="arg0" ve="3">api.wunderground.com</Str>
			<Str sr="arg1" ve="3">/api/xxxxxxxxxxxxxxxx/forecast/q/MI/49015.json</Str>
			<Str sr="arg2" ve="3"/>
			<Str sr="arg3" ve="3"/>
			<Str sr="arg4" ve="3"/>
			<Int sr="arg5" val="30"/>
			<Str sr="arg6" ve="3"/>
			<Str sr="arg7" ve="3"/>
			<Int sr="arg8" val="0"/>
		</Action>
		<Action sr="act3" ve="7">
			<code>37</code>
			<ConditionList sr="if">
				<Condition sr="c0" ve="3">
					<lhs>%HTTPR</lhs>
					<op>0</op>
					<rhs>200</rhs>
				</Condition>
			</ConditionList>
		</Action>
		<Action sr="act4" ve="7">
			<code>129</code>
			<label>www.jsoneditoronline.org to easilly find variables</label>
			<Str sr="arg0" ve="3">var arr = [];
arr = JSON.parse(global("HTTPD"));
var wuconditions = arr.forecast.simpleforecast.forecastday[0].conditions;
var wuicon = arr.forecast.simpleforecast.forecastday[0].icon;
var wuiconurl = arr.forecast.simpleforecast.forecastday[0].icon_url;
var wuhigh = arr.forecast.simpleforecast.forecastday[0].high.fahrenheit;
var wulow = arr.forecast.simpleforecast.forecastday[0].low.fahrenheit;
var wutitle1 = arr.forecast.txt_forecast.forecastday[0].title;
var wutitle2 = arr.forecast.txt_forecast.forecastday[1].title;
var wufcttext1 = arr.forecast.txt_forecast.forecastday[0].fcttext;
var wufcttext2 = arr.forecast.txt_forecast.forecastday[1].fcttext;
var wumaxwindmph = arr.forecast.simpleforecast.forecastday[0].maxwind.mph;
var wuavewindmph = arr.forecast.simpleforecast.forecastday[0].avewind.mph;
var wuavewinddir = arr.forecast.simpleforecast.forecastday[0].avewind.dir;
var wumaxwinddir = arr.forecast.simpleforecast.forecastday[0].maxwind.dir;
var wuavehumidity = arr.forecast.simpleforecast.forecastday[0].avehumidity;</Str>
			<Str sr="arg1" ve="3"/>
			<Int sr="arg2" val="1"/>
			<Int sr="arg3" val="45"/>
		</Action>
		<Action sr="act5" ve="7">
			<code>118</code>
			<Str sr="arg0" ve="3">icons.wxug.com</Str>
			<Str sr="arg1" ve="3">i/c/f/%wuicon.gif</Str>
			<Str sr="arg2" ve="3"/>
			<Str sr="arg3" ve="3"/>
			<Str sr="arg4" ve="3"/>
			<Int sr="arg5" val="10"/>
			<Str sr="arg6" ve="3">image/*</Str>
			<Str sr="arg7" ve="3">Download/wuicon.gif</Str>
			<Int sr="arg8" val="0"/>
		</Action>
		<Action sr="act6" ve="7">
			<code>131</code>
			<label>Use this if you would rather edit a text document for the Javascript</label>
			<on>false</on>
			<Str sr="arg0" ve="3">Tasker/javascripts/getweather.js</Str>
			<Str sr="arg1" ve="3"/>
			<Int sr="arg2" val="1"/>
			<Int sr="arg3" val="45"/>
		</Action>
		<Action sr="act7" ve="7">
			<code>47</code>
			<Str sr="arg0" ve="3">WU Window</Str>
			<Int sr="arg1" val="3"/>
			<Int sr="arg2" val="100"/>
			<Int sr="arg3" val="100"/>
			<Int sr="arg4" val="0"/>
			<Int sr="arg5" val="1"/>
			<Int sr="arg6" val="1"/>
		</Action>
		<Action sr="act8" ve="7">
			<code>38</code>
		</Action>
		<Img sr="icn" ve="2">
			<nme>cust_star</nme>
		</Img>
	</Task>
</TaskerData>
Screenshot_2015-04-15-21-47-17.png

Rob

unread,
Apr 16, 2015, 4:37:28 AM4/16/15
to tas...@googlegroups.com
Hello Joe,

Variable splitting seems confusing but I solved the issue of getting the correct info from an XML response by using a small task (Routine in fact) that returnes the string I want or a specifiec value when the key is not found. That task only needs a few variable splits to get the right value.
You can perform this task for as may keys as you need.

Task Input: %par1=XML response data, %par2=search key, %result=found value or error value to return

That works well for me.

regards, Rob

Op donderdag 16 april 2015 03:53:45 UTC+2 schreef Joe Costa:

John Doe

unread,
Apr 16, 2015, 9:56:16 AM4/16/15
to tas...@googlegroups.com
...or you could use meteotask :D It manages context and task actions, data caching, retry and power management policies.

easiuser

unread,
Apr 16, 2015, 1:41:17 PM4/16/15
to tas...@googlegroups.com
Any chance of sharing your parsing routine?

Joe Costa

unread,
Apr 16, 2015, 3:51:04 PM4/16/15
to tas...@googlegroups.com
Add,Code,JavaScriptlet
Code
arr = JSON.parse(global("HTTPD"));
var wuconditions = arr.forecast.simpleforecast.forecastday[0].conditions;
var wuicon = arr.forecast.simpleforecast.forecastday[0].icon;
var wuiconurl = arr.forecast.simpleforecast.forecastday[0].icon_url;
var wuhigh = arr.forecast.simpleforecast.forecastday[0].high.fahrenheit;
var wulow = arr.forecast.simpleforecast.forecastday[0].low.fahrenheit;
var wutitle1 = arr.forecast.txt_forecast.forecastday[0].title;
var wutitle2 = arr.forecast.txt_forecast.forecastday[1].title;
var wufcttext1 = arr.forecast.txt_forecast.forecastday[0].fcttext;
var wufcttext2 = arr.forecast.txt_forecast.forecastday[1].fcttext;
var wumaxwindmph = arr.forecast.simpleforecast.forecastday[0].maxwind.mph;
var wuavewindmph = arr.forecast.simpleforecast.forecastday[0].avewind.mph;
var wuavewinddir = arr.forecast.simpleforecast.forecastday[0].avewind.dir;
var wumaxwinddir = arr.forecast.simpleforecast.forecastday[0].maxwind.dir;
var wuavehumidity = arr.forecast.simpleforecast.forecastday[0].avehumidity;
Autoexit checked

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/j0okqP8NmEs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Joe Costa

unread,
Apr 16, 2015, 3:51:28 PM4/16/15
to tas...@googlegroups.com
Add,Code,JavaScriptlet
Code
arr = JSON.parse(global("HTTPD"));
var wuconditions = arr.forecast.simpleforecast.forecastday[0].conditions;
var wuicon = arr.forecast.simpleforecast.forecastday[0].icon;
var wuiconurl = arr.forecast.simpleforecast.forecastday[0].icon_url;
var wuhigh = arr.forecast.simpleforecast.forecastday[0].high.fahrenheit;
var wulow = arr.forecast.simpleforecast.forecastday[0].low.fahrenheit;
var wutitle1 = arr.forecast.txt_forecast.forecastday[0].title;
var wutitle2 = arr.forecast.txt_forecast.forecastday[1].title;
var wufcttext1 = arr.forecast.txt_forecast.forecastday[0].fcttext;
var wufcttext2 = arr.forecast.txt_forecast.forecastday[1].fcttext;
var wumaxwindmph = arr.forecast.simpleforecast.forecastday[0].maxwind.mph;
var wuavewindmph = arr.forecast.simpleforecast.forecastday[0].avewind.mph;
var wuavewinddir = arr.forecast.simpleforecast.forecastday[0].avewind.dir;
var wumaxwinddir = arr.forecast.simpleforecast.forecastday[0].maxwind.dir;
var wuavehumidity = arr.forecast.simpleforecast.forecastday[0].avehumidity;
Autoexit checked

On Thu, Apr 16, 2015 at 1:41 PM, easiuser <ron.d....@gmail.com> wrote:

--

Joe Costa

unread,
Apr 16, 2015, 3:53:07 PM4/16/15
to tas...@googlegroups.com
Add,Code,JavaScriptlet

Code

arr = JSON.parse(global("HTTPD"));
var wuconditions = arr.forecast.simpleforecast.forecastday[0].conditions;
var wuicon = arr.forecast.simpleforecast.forecastday[0].icon;
var wuiconurl = arr.forecast.simpleforecast.forecastday[0].icon_url;
var wuhigh = arr.forecast.simpleforecast.forecastday[0].high.fahrenheit;
var wulow = arr.forecast.simpleforecast.forecastday[0].low.fahrenheit;
var wutitle1 = arr.forecast.txt_forecast.forecastday[0].title;
var wutitle2 = arr.forecast.txt_forecast.forecastday[1].title;
var wufcttext1 = arr.forecast.txt_forecast.forecastday[0].fcttext;
var wufcttext2 = arr.forecast.txt_forecast.forecastday[1].fcttext;
var wumaxwindmph = arr.forecast.simpleforecast.forecastday[0].maxwind.mph;
var wuavewindmph = arr.forecast.simpleforecast.forecastday[0].avewind.mph;
var wuavewinddir = arr.forecast.simpleforecast.forecastday[0].avewind.dir;
var wumaxwinddir = arr.forecast.simpleforecast.forecastday[0].maxwind.dir;
var wuavehumidity = arr.forecast.simpleforecast.forecastday[0].avehumidity;

Autoexit checked

On Thu, Apr 16, 2015 at 1:41 PM, easiuser <ron.d....@gmail.com> wrote:

--

Joe Costa

unread,
Apr 16, 2015, 3:56:53 PM4/16/15
to tas...@googlegroups.com
Never tried that. The javascriptlet seemed so easy to use to parse the json data so I went that route.

--

Joe Costa

unread,
Apr 16, 2015, 4:02:31 PM4/16/15
to tas...@googlegroups.com
TASK
Inline image 1


Javascriptlet
Inline image 2
Scene Edit
Inline image 4

Result
Inline image 3



On Thu, Apr 16, 2015 at 1:41 PM, easiuser <ron.d....@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages