Daily weather forecast based on OwnTracks location

Publishes weather forecast messages based on the last known location provided by OwnTracks. The default location if none is provided by OwnTracks is injected on startup by the 'default location' node.

The forecast messages are published to the MQTT topic notifications/weather where they can be pushed to a mobile device by mqttwarn.

Multiple users are not yet supported, the location is stored in global.location.$username as {lat: "xx.xxxx", lon: "yy.yyyyy"} JSON object.

[{"id":"35c57467.ca3a8c","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":"nodered"},{"id":"c4b992a2.3b467","type":"mqtt in","name":"Location input","topic":"owntracks/#","broker":"35c57467.ca3a8c","x":550,"y":488.57142448425293,"z":"27070cfe.d8f8f4","wires":[["ee93c6ed.116c38"]]},{"id":"e3fa4bc6.1c05b8","type":"mqtt out","name":"","topic":"notifications/weather","broker":"35c57467.ca3a8c","x":1305.0142974853516,"y":661.0142822265625,"z":"27070cfe.d8f8f4","wires":[]},{"id":"ee93c6ed.116c38","type":"switch","name":"filter location messages","property":"payload","rules":[{"t":"cont","v":"\"location\""}],"checkall":"true","outputs":1,"x":732.5142936706543,"y":488.6571378707886,"z":"27070cfe.d8f8f4","wires":[["8169ee94.7e961"]]},{"id":"6a4311f3.95bcf","type":"inject","name":"forecast","topic":"","payload":"","payloadType":"string","repeat":"","crontab":"20 6 * * *","once":false,"x":575.0143089294434,"y":664.0142784118652,"z":"27070cfe.d8f8f4","wires":[["21254595.dedaba"]]},{"id":"1ae87ce2.e51783","type":"httpget","name":"forecast","baseurl":"http://api.openweathermap.org/data/2.5/forecast/daily?lang=de&units=metric&","append":"","x":916.5142364501953,"y":662.7643432617188,"z":"27070cfe.d8f8f4","wires":[["a78962d2.5876a"]]},{"id":"a78962d2.5876a","type":"function","name":"to text","func":"var weather = JSON.parse(msg.payload);\nvar temps = weather['list'][0]['temp'];\nvar d = weather['list'][0]['weather'][0]['description'];\nvar desc = d[0].toUpperCase() + d.slice(1)\n\nvar min = temps['min'];\nvar max = temps['max'];\n\nreturn {payload: desc + \" \" + min + \"°C - \" +max + \"°C \"};","outputs":"1","x":1113.2642364501953,"y":662.0142822265625,"z":"27070cfe.d8f8f4","wires":[["e3fa4bc6.1c05b8"]]},{"id":"8169ee94.7e961","type":"function","name":"store location in global scope","func":"context.global.createNestedObject( context, [\"global\", \"location\", \"bucks\"]);\n\nvar json = JSON.parse(msg.payload);\ncontext['global']['location']['bucks'] = {lat: json['lat'], lon: json['lon']};\nreturn {payload: context['global']['location']['bucks']};","outputs":1,"x":1035.764289855957,"y":563.764274597168,"z":"27070cfe.d8f8f4","wires":[["567f5272.a980ac"]]},{"id":"567f5272.a980ac","type":"debug","name":"","active":false,"complete":"false","x":1227.014289855957,"y":564.514274597168,"z":"27070cfe.d8f8f4","wires":[]},{"id":"23347757.dccb88","type":"inject","name":"insert helper functions","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":598.5142974853516,"y":793.7642822265625,"z":"27070cfe.d8f8f4","wires":[["dad21131.252df"]]},{"id":"dad21131.252df","type":"function","name":"createNestedObject","func":"context.global.createNestedObject = function( base, names ) {\n    for( var i = 0; i < names.length; i++ ) {\n        base = base[ names[i] ] = base[ names[i] ] || {};\n    }\n};","outputs":1,"x":801.3714485168457,"y":794.7642593383789,"z":"27070cfe.d8f8f4","wires":[[]]},{"id":"3162e06b.ce9d2","type":"inject","name":"default location","topic":"","payload":"{\"lat\": \"52.0000000\", \"lon\": \"9.000000\"}","payloadType":"string","repeat":"","crontab":"","once":true,"x":555.5142688751221,"y":564.3714237213135,"z":"27070cfe.d8f8f4","wires":[["8169ee94.7e961"]]},{"id":"21254595.dedaba","type":"function","name":"get location","func":"return {payload: \"lat=\" +context.global.location.bucks.lat + \"&lon=\" +context.global.location.bucks.lon};","outputs":1,"x":764.5142974853516,"y":662.7642822265625,"z":"27070cfe.d8f8f4","wires":[["1ae87ce2.e51783"]]}]

Flow Info

Created 10 years, 11 months ago
Updated 9 years, 3 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x4)
  • inject (x3)
  • mqtt in (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • switch (x1)
Other
  • httpget (x1)

Tags

  • owntracks
  • weather
  • forecast
  • location
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option