NEWB HELP !... Extract value from Weather API to use on Node red Gauges now working ?

278 views
Skip to first unread message

DJ S

unread,
Aug 6, 2017, 11:20:15 PM8/6/17
to Node-RED
Hello chaps.

I have tried everything i can find on this issue. looked back through the forums and scanned the node red programming tutorials and come to a dead end. :(

I'm subscribed to  a weather API that returns values for, temp,wind,humidity, and so on. I'm trying to extract the values individually so i can use them on the Node red gauges.
I have managed to split the message and output the strings using a switch node. However the gauges cannot use msg.payload as it has more than just the numeric value.
I have tried using a function node with return {values: msg.payload.values.tempc}; Still not working. On the debug screen you can see what an untouched message looks like. The below is my individual messages returned after going through the Splt-switch node.

Flow is at the bottom. Any advice help ,pointers would be appreciated.


Thank you




[{"id":"3d119dce.660d72","type":"wunderground in","z":"e08cc8d.d212c38","name":"SmithTek","lon":"","lat":"","city":"fremantle","country":"Australia","x":120,"y":520,"wires":[["d165f300.4007e8","cfd8b3cb.b7db8"]]},{"id":"a6f1c897.019d7","type":"debug","z":"e08cc8d.d212c38","name":"Weather","active":true,"console":"false","complete":"payload","x":960,"y":300,"wires":[]},{"id":"734f2887.7d6688","type":"debug","z":"e08cc8d.d212c38","name":"Wind Direction","active":true,"console":"false","complete":"payload","x":980,"y":440,"wires":[]},{"id":"f3b70efd.c86da","type":"debug","z":"e08cc8d.d212c38","name":"Humidity","active":true,"console":"false","complete":"payload","x":960,"y":740,"wires":[]},{"id":"f76fa582.6696e","type":"split","z":"e08cc8d.d212c38","name":"","splt":",","x":430,"y":520,"wires":[["86fabd31.7a6888"]]},{"id":"86fabd31.7a6888","type":"switch","z":"e08cc8d.d212c38","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"\"weather\"","vt":"str"},{"t":"cont","v":"\"winddirection\"","vt":"str"},{"t":"cont","v":"\"tempc\"","vt":"str"},{"t":"cont","v":"humidity","vt":"str"}],"checkall":"true","outputs":4,"x":570,"y":520,"wires":[["a6f1c897.019d7","93560cb1.b2bb18"],["734f2887.7d6688","4e05c6a7.4f21a8"],["66b92cf8.351ad4","c5b18ca4.81ae9"],["f3b70efd.c86da","7e4029ca.4bd06"]]},{"id":"d165f300.4007e8","type":"debug","z":"e08cc8d.d212c38","name":"","active":true,"console":"false","complete":"false","x":350,"y":720,"wires":[]},{"id":"cfd8b3cb.b7db8","type":"json","z":"e08cc8d.d212c38","name":"","x":290,"y":520,"wires":[["f76fa582.6696e","3fef0231.544586"]]},{"id":"7e4029ca.4bd06","type":"ui_gauge","z":"e08cc8d.d212c38","name":"","group":"40ca7741.66712","order":0,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":960,"y":780,"wires":[]},{"id":"c5b18ca4.81ae9","type":"ui_gauge","z":"e08cc8d.d212c38","name":"","group":"40ca7741.66712","order":0,"width":0,"height":0,"gtype":"gage","title":"Temp","label":"°C","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":950,"y":620,"wires":[]},{"id":"4e05c6a7.4f21a8","type":"ui_gauge","z":"e08cc8d.d212c38","name":"","group":"40ca7741.66712","order":0,"width":0,"height":0,"gtype":"compass","title":"Wind Direction","label":"Degrees","format":"{{value}}","min":0,"max":"360","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":980,"y":480,"wires":[]},{"id":"93560cb1.b2bb18","type":"ui_text","z":"e08cc8d.d212c38","group":"40ca7741.66712","order":0,"width":0,"height":0,"name":"","label":"Forecast","format":"{{msg.payload}}","layout":"row-spread","x":960,"y":340,"wires":[]},{"id":"66b92cf8.351ad4","type":"debug","z":"e08cc8d.d212c38","name":"","active":true,"console":"false","complete":"false","x":970,"y":580,"wires":[]},{"id":"d4397f77.b25a1","type":"debug","z":"e08cc8d.d212c38","name":"Weather","active":true,"console":"false","complete":"payload","x":600,"y":220,"wires":[]},{"id":"3fef0231.544586","type":"function","z":"e08cc8d.d212c38","name":"","func":"return {values: msg.payload.values.tempc};\n","outputs":1,"noerr":0,"x":480,"y":340,"wires":[["d4397f77.b25a1"]]},{"id":"40ca7741.66712","type":"ui_group","z":"","name":"Weather Station","tab":"a91cc6f1.67eaf","disp":true,"width":"6"},{"id":"a91cc6f1.67eaf","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]



Auto Generated Inline Image 1

DJ S

unread,
Aug 7, 2017, 1:35:30 AM8/7/17
to Node-RED
Hi Chaps. 

Has been solved now. i went back to the function node route and this worked .
return {payload:msg.payload.weather};   when i tried this originally i used     return {payload:msg.payload.values.weather};


Regards

Stephen Mann

unread,
Nov 23, 2017, 1:30:39 AM11/23/17
to Node-RED
DJS- You are leagues ahead of me.  I am trying to do the same thing and I would appreciate seeing your nodes export.
I have been trying for days to get WeatherUnderground nodes to install on my Pi3/Jessie, but I keep getting warnings from the npm install.  However, I do see the files in ~/.node-red/node
_modules/node-red-node-weather_underground, just no nodes in my pallette.

TIA,
Steve (Newbie)

Zenofmud

unread,
Nov 23, 2017, 5:50:33 AM11/23/17
to node...@googlegroups.com
Stephen,
1) what version of NP?
2) what version of node.js?
3) what version of npm?
4) what are the warning messages you get?
5) do you have a weatherunderground API key? (don’t show it, just verify you have one)

On Nov 23, 2017, at 1:30 AM, Stephen Mann <mann....@gmail.com> wrote:

WeatherUnderground

Stephen Mann

unread,
Nov 26, 2017, 11:20:12 AM11/26/17
to Node-RED
Paul-
Thanks for the reply.  In my attempts to fix the WU node install, I manager to kill my Node-red.

I saved my project by moving my nodes to another Pi, where Weather Underground installed without issue.

I've since built a dashboard page to show the weather details, and a function to turn a humidifier on if the humidity drops below 50%.

Just for reference, how do I find the versions that you requested below?

Steve

Stephen Mann

unread,
Nov 26, 2017, 11:26:23 AM11/26/17
to Node-RED
Can you explain your use of the Split and Switch functions?  I did the same with separate functions for each value.  How did you finally get it to work?

Steve


[{"id":"3cca129d.7d398e","type":"tab","label":"Weather","disabled":false,"info":""},{"id":"9c3c16c2.abb798","type":"wunderground","z":"3cca129d.7d398e","name":"Westford Weather ","lon":"","lat":"","city":"Westford","country":"Massachusetts","x":232,"y":478,"wires":[["56a38dd7.2c8e34","d52a21d6.37ee7","dce20e4.e7f99f","25043e08.b9d622","22f26897.8fd1b8","f2d46123.d9239","dd1f3489.6a4048","651321f9.6c527","dceeba61.5c7858","e7c63f8e.a5853","bd40d8ae.88f308"]]},{"id":"18397a92.25d0d5","type":"inject","z":"3cca129d.7d398e","name":"Every 30 Minutes","topic":"","payload":"","payloadType":"date","repeat":"900","crontab":"","once":true,"x":151,"y":410,"wires":[["9c3c16c2.abb798"]]},{"id":"56a38dd7.2c8e34","type":"function","z":"3cca129d.7d398e","name":"Temperature","func":"msg.payload = Number(msg.payload.tempf) ;\ndelete msg.time;\nreturn msg;","outputs":1,"noerr":0,"x":411,"y":86,"wires":[["85291d27.a36e6"]]},{"id":"d52a21d6.37ee7","type":"function","z":"3cca129d.7d398e","name":"Humidity","func":"msg.payload = parseInt(msg.payload.humidity) ;\ndelete msg.time;\nreturn msg;","outputs":1,"noerr":0,"x":425,"y":131,"wires":[["6f1b4862.9ea468","fd1749f4.dca998"]]},{"id":"dce20e4.e7f99f","type":"function","z":"3cca129d.7d398e","name":"Windspeed","func":"msg.payload = parseFloat(msg.payload.windspeed).toFixed(0);\ndelete msg.time;\nreturn msg;","outputs":1,"noerr":0,"x":487,"y":228,"wires":[["bc85dab2.79e248","cdf4f3cb.f643e"]]},{"id":"11fa2656.e3d4ba","type":"comment","z":"3cca129d.7d398e","name":"Westford Weather","info":"","x":154,"y":356,"wires":[]},{"id":"25043e08.b9d622","type":"function","z":"3cca129d.7d398e","name":"Wind Direction","func":"msg.payload = parseInt(msg.payload.winddirection).toFixed(0);\ndelete msg.time;\nreturn msg;","outputs":1,"noerr":0,"x":517,"y":320,"wires":[["52585bfc.ec7e34","280eb81e.60ccb8"]]},{"id":"52585bfc.ec7e34","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":4,"width":0,"height":0,"name":"Wind Direction","label":"Wind Direction","format":"{{msg.payload}} degrees","layout":"row-spread","x":849,"y":320,"wires":[]},{"id":"bc85dab2.79e248","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":6,"width":0,"height":0,"name":"","label":"Windspeed","format":"{{msg.payload}} MPH","layout":"row-spread","x":831,"y":225,"wires":[]},{"id":"6f1b4862.9ea468","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":7,"width":0,"height":0,"name":"","label":"Humidity","format":"{{msg.payload}} %","layout":"row-spread","x":869,"y":114,"wires":[]},{"id":"85291d27.a36e6","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":8,"width":0,"height":0,"name":"","label":"Temperature","format":"{{msg.payload}} °F","layout":"row-spread","x":835,"y":79,"wires":[]},{"id":"cd96e680.b508b8","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":9,"width":0,"height":0,"name":"","label":"Barometer","format":"{{msg.payload}} in.","layout":"row-spread","x":832,"y":431,"wires":[]},{"id":"22f26897.8fd1b8","type":"function","z":"3cca129d.7d398e","name":"Barometer","func":"msg.payload = Number(msg.data.current_observation.pressure_in) ;\ndelete msg.time;\nreturn msg;","outputs":1,"noerr":0,"x":568,"y":432,"wires":[["cd96e680.b508b8"]]},{"id":"f2d46123.d9239","type":"function","z":"3cca129d.7d398e","name":"Observation Time","func":"var now = \"Current time: <i>\" + new Date().toString();\nvar pos = now.indexOf(\"GMT\",0);\nvar res = now.slice(0, pos-1) + \"</i\";  //Strip the GMT\nmsg.payload = res;\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":42,"wires":[["472e005d.dc22b"]]},{"id":"472e005d.dc22b","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":2,"width":0,"height":0,"name":"Observation Time","label":"","format":"{{msg.payload}}","layout":"col-center","x":855,"y":42,"wires":[]},{"id":"dd1f3489.6a4048","type":"function","z":"3cca129d.7d398e","name":"Forecast Today","func":"var str = msg.data.forecast.txt_forecast.forecastday[0].fcttext;\nmsg.payload = str;\nreturn msg;","outputs":1,"noerr":0,"x":599,"y":551,"wires":[["3c1bc74f.6b3008"]]},{"id":"3c1bc74f.6b3008","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":3,"width":0,"height":0,"name":"Forecast 0","label":"{{msg.data.forecast.txt_forecast.forecastday[0].title}}","format":"{{msg.payload}}","layout":"col-center","x":831,"y":553,"wires":[]},{"id":"651321f9.6c527","type":"function","z":"3cca129d.7d398e","name":"Forecast 1","func":"var str = msg.data.forecast.txt_forecast.forecastday[1].fcttext;\nmsg.payload = str;\nreturn msg;","outputs":1,"noerr":0,"x":577,"y":593,"wires":[["5b8323c.17b2edc"]]},{"id":"5b8323c.17b2edc","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":3,"width":0,"height":0,"name":"Forecast 1","label":"{{msg.data.forecast.txt_forecast.forecastday[1].title}}","format":"{{msg.payload}}","layout":"col-center","x":831,"y":590,"wires":[]},{"id":"dceeba61.5c7858","type":"function","z":"3cca129d.7d398e","name":"Forecast 2","func":"var str = msg.data.forecast.txt_forecast.forecastday[2].fcttext;\nmsg.payload = str;\nreturn msg;","outputs":1,"noerr":0,"x":577,"y":636,"wires":[["3068be6b.57cc32"]]},{"id":"3068be6b.57cc32","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":3,"width":0,"height":0,"name":"Forecast 2","label":"{{msg.data.forecast.txt_forecast.forecastday[2].title}}","format":"{{msg.payload}}","layout":"col-center","x":835,"y":634,"wires":[]},{"id":"ac01bd3.a39224","type":"ui_text","z":"3cca129d.7d398e","group":"f019cc3b.9d085","order":9,"width":0,"height":0,"name":"","label":"Trend","format":"{{msg.payload}}","layout":"row-spread","x":881,"y":481,"wires":[]},{"id":"e7c63f8e.a5853","type":"function","z":"3cca129d.7d398e","name":"  Trend","func":"msg.payload = msg.data.current_observation.pressure_trend ;\ndelete msg.time;\nreturn msg;","outputs":1,"noerr":0,"x":575,"y":483,"wires":[["8edafa07.3d6048"]]},{"id":"8edafa07.3d6048","type":"function","z":"3cca129d.7d398e","name":"Trending","func":"if (msg.payload === \"0\") {\n    msg.payload = \"Stable\";\n}else if (msg.payload === \"-\"){\n    msg.payload = \"Falling\";\n}else if (msg.payload === \"+\"){\n    msg.payload = \"Rising\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":725,"y":479,"wires":[["ac01bd3.a39224"]]},{"id":"280eb81e.60ccb8","type":"ui_gauge","z":"3cca129d.7d398e","name":"","group":"f019cc3b.9d085","order":0,"width":0,"height":0,"gtype":"compass","title":"Wind Direction","label":"degrees","format":"{{value}}","min":0,"max":"360","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":854,"y":365,"wires":[]},{"id":"cdf4f3cb.f643e","type":"ui_gauge","z":"3cca129d.7d398e","name":"","group":"f019cc3b.9d085","order":0,"width":0,"height":0,"gtype":"gage","title":"WindSpeed","label":"MPH","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":835,"y":268,"wires":[]},{"id":"fd1749f4.dca998","type":"function","z":"3cca129d.7d398e","name":"Humidifier?","func":"// If the humidity is < 50%, turn on the humidifier.\nif (msg.payload < 50) {\n    msg.payload = \"on\";\n}else{\n    msg.payload = \"off\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":607,"y":169,"wires":[["b9f3dd4a.36a2c"]]},{"id":"b9f3dd4a.36a2c","type":"mqtt out","z":"3cca129d.7d398e","name":"","topic":"humidifier","qos":"0","retain":"","broker":"94aed639.3a1338","x":824,"y":168,"wires":[]},{"id":"bd40d8ae.88f308","type":"debug","z":"3cca129d.7d398e","name":"","active":false,"console":"false","complete":"true","x":429,"y":726,"wires":[]},{"id":"f019cc3b.9d085","type":"ui_group","z":"","name":"Weather","tab":"88b203d3.eff78","order":1,"disp":true,"width":"6"},{"id":"94aed639.3a1338","type":"mqtt-broker","z":"","broker":"192.168.1.124","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"88b203d3.eff78","type":"ui_tab","z":"","name":"Weather","icon":"dashboard","order":2}]

Zenofmud

unread,
Nov 26, 2017, 1:50:47 PM11/26/17
to node...@googlegroups.com
Steve,
to find the versions use
npm -v
node -v
and look at the startup log to find the node-red version (you can also see node.js’s version in the log)
Paul

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/734ab140-5c37-44d9-aaa5-5f2a01d62b36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages