HowTo: Node Red – Get current weather data from OpenWeatherMap

It is not always possible to directly measure environmental data such as the outside temperature. Still, sometimes it comes in handy. For example, you can ensure that the radiators inside are only switched on when it is cold outside. Heaters that switch on automatically in summer not only cost money but also sweat. 🙂

In order to get this environmental data, you would actually need your own weather station, which feeds the SmartHome with the corresponding data.
However, you can save this money. Thanks to free weather services from which you only have to obtain this data. One of these weather services is OpenWeatherMap.org.

How you can obtain weather data from OpenWeatherMap.org and use it for your SmartHome is explained in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
To be able to use this configuration, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.

The following articles describe what has to be done to prepare the RaspberryPi so far:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi
NodeRed – Install new nodes

NodeRed - import and export node code

Required tool:
-no-

Required material:

In the following list you will find all the parts you need to implement this article.


Log into the NodeRed configuration interface

Before you can edit your NodeRed configuration, you must - if activated - first log into the NodeRed configuration interface.

View of the login dialog. Here you have to enter the login data that you specified during the configuration of the login. You can find information about this in the article NodeRed - set up user login.

Register openWeatherMap API key

In order to access current weather data from openWeahterMap.org, you need an API key. How you can register it for free is described in this article: Register OpenWeatherMap.org API key
This must later be stored in the openWeatherMap node. So remember it well. 🙂

Install openWeatherMap node

So that you can retrieve the data from OpenWeatherMap.Org, you have to install the node “node-red-node-openweathermap”. How to install nodes is in the article NodeRed – Install new nodes explained.

Import node code

The following configuration should help you get started. To do this, simply import the following node code into your NodeRed installation. How to do this is in the article NodeRed - import and export node code explained.

Immediately afterwards you have to add the previously registered API key to the configuration, as described below.

View of the configuration in the editor.

Node code:

[{"id":"85dcceee.5ca84","type":"change","z":"5ebf035f.49459c","name":"outside temperature","rules":[{"t":"set ","p":"payload","pt":"msg","to":"data.main.temp-273.15","tot":"jsonata"}],"action":""," property":"","from":"","to":"","reg":false,"x":710,"y":200,"wires":[["6ab6bc17.16a144"] ]},{"id":"b36beeac.014ba","type":"json","z":"5ebf035f.49459c","name":"","property":"payload","action" :"","pretty":false,"x":510,"y":200,"wires":[["85dcceee.5ca84","a0fb594.6e02ea8","7aa148d5.934fb8","8e550228.aae02 ","52536e82.1cb05","b22dec0e.d53f3","bcdf0d32.be17a","95d0a7a8.66b9e8","514584f.458327c"]]},{"id":"34eee9ed.b64d36","type": "inject","z":"5ebf035f.49459c","name":"Retrieve data manually","topic":"","payload":"","payloadType":"date","repeat": "","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":260,"wires":[["d5a8c5aa.82b3c8"]]},{ "id":"a0fb594.6e02ea8","type":"change","z":"5ebf035f.49459c","name":"outsidehumidity","rules":[{"t":"set", "p":"payload","pt":"msg","to":"data.main.humidity","tot":"jsona ta"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":320 ,"wires":[["b9f93625.5051b8"]]},{"id":"7aa148d5.934fb8","type":"change","z":"5ebf035f.49459c","name":" external air pressure","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.main.pressure","tot":" jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":360 ,"wires":[["fbf0a415.6ed9c8"]]},{"id":"d5a8c5aa.82b3c8","type":"openweathermap","z":"5ebf035f.49459c","name":" ","wtype":"current","lon":"","lat":"","city":"Bochum","country":"Germany","language":"de","x ":410,"y":260,"wires":[["b36beeac.014ba"]]},{"id":"67bf25e3.d1ce1c","type":"openweathermap in","z":" 5ebf035f.49459c","name":"","wtype":"current","lon":"","lat":"","city":"Bochum","country":"Germany", "language":"de","x":160,"y":200,"wires":[["b36beeac.014ba"]]},{"id":"8e550228.aae02","type": "debug","z":"5ebf035f.49459c","name":"Raw data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete": "true","x":680,"y":160,"wires ":[]},{"id":"6ab6bc17.16a144","type":"debug","z":"5ebf035f.49459c","name":"outsidetemperature","active":true," tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":990,"y":200,"wires":[]},{"id": "b9f93625.5051b8","type":"debug","z":"5ebf035f.49459c","name":"outside humidity","active":true,"tosidebar":true,"console":false, "tostatus":false,"complete":"payload","x":1000,"y":320,"wires":[]},{"id":"fbf0a415.6ed9c8","type":" debug","z":"5ebf035f.49459c","name":"Outside air pressure","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":" payload","x":980,"y":360,"wires":[]},{"id":"52536e82.1cb05","type":"change","z":"5ebf035f.49459c ","name":"Wind speed","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.wind.speed ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x": 690,"y":400,"wires":[["93256619.92a1b8"]]},{"id":"b22dec0e.d53f3","type":"change","z":"5ebf035f.49459c" ,"name":"Wind direction","rules":[{"t":"set","p":"payload","pt" :"msg","to":"data.wind.deg","tot":"jsonata"}],"action":"","property":"","from":"","to ":"","reg":false,"x":690,"y":440,"wires":[["d755f34d.fdefa"]]},{"id":"93256619.92a1b8","type ":"debug","z":"5ebf035f.49459c","name":"Wind force","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete ":"payload","x":970,"y":400,"wires":[]},{"id":"d755f34d.fdefa","type":"debug","z":" 5ebf035f.49459c","name":"Wind direction","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":970 ,"y":440,"wires":[]},{"id":"bcdf0d32.be17a","type":"change","z":"5ebf035f.49459c","name":"wetterDescription ","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.weather[0].description","tot" :"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y" :480,"wires":[["a9876b9d.5e5be8"]]},{"id":"a9876b9d.5e5be8","type":"debug","z":"5ebf035f.49459c","name" :"weatherDescription","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload" ,"x":1000,"y":480,"wires":[]},{"id":"95d0a7a8.66b9e8","type":"change","z":"5ebf035f.49459c", "name":"outsideTempMin","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.main.temp_min-273.15 ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x": 700,"y":240,"wires":[["751ba810.fd1938"]]},{"id":"514584f.458327c","type":"change","z":"5ebf035f.49459c ","name":"outsideTempMax","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.main.temp_max -273.15","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x ":700,"y":280,"wires":[["455148a8.ce5168"]]},{"id":"751ba810.fd1938","type":"debug","z":"5ebf035f .49459c","name":"outsideTempMin","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":980, "y":240,"wires":[]},{"id":"455148a8.ce5168","type":"debug","z":"5ebf035f.49459c","name":"outsideTempMax" ,"active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":980,"y":280,"wires":[ ]}]
Your OpenWeatherMap API key must be entered in the OpenWeatherMap nodes so that the data retrieval works.

Further information

https://openweathermap.org/


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

10 comments

  1. HI,
    Cool thing, thanks for your tutorials 🙂

    I have a problem.
    When I output the temperatures as text, I get too many decimal places behind it....
    How can I round?

    Thanks very much!

    1. Hey Adrian,
      Thanks. 🙂
      I always do this with a function node and some JavaScript. (I'm sure there are other potentially better ways).
      I uploaded an example for you here: https://pastebin.com/UesZyP2N
      You should be able to import the code easily. Hopefully it's self-explanatory. Otherwise please ask again. 🙂
      Best regards
      Fabian

  2. hi all

    The post is a bit old, but it helped me a lot, thank you!
    I'm currently building Rhasspy on an OrangePi, the voice output of the weather data
    take shape thanks to the node code :). My problem is that I have the individual
    I can't summarize queries in one output, I still have to use static text
    add something like “The current weather in…” or “The wind is blowing from the direction..” and then forward it to the server as msg.payload. I would be very open to a tip, thank you.

    Greetings Michael

  3. Yes exactly Fab, he was spot on with the tip, works very well, thank you very much.
    Now I would like to round off the “data.main.temp-273.15”, for me that is the msg.payload2, I saw your tip from above “parseFloat(msg.payload).toFixed(2)”.
    Can you help me where to go or is there another way?
    Greetings Michael

    1. Hi Michael,
      you can basically put that in the same function node. For example like this:
      var value=parseFloat(msg.payload2).toFixed(2)
      msg.payload “Here is the sentence you want to output with the rounded value: “+String(value);

      I hope that works.
      Best regards
      Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.