How To: Node Red – Get current weather data from OpenWeatherMap

It is not always possible to directly measure environmental data such as the outside temperature. Nevertheless, it is sometimes practical. For example, you can make sure that the radiators inside are only turned on when it’s cold outside. Heaters that automatically switch on in the summer cost not only money and make you sweat. 🙂

In order to get to this environment data one would actually need an own weather station, which feeds the SmartHome with the appropriate data.
This money can be saved. Thanks to free weather services from which you only need to get this data. One of these weather services is OpenWeatherMap.org.

How to get weather data from OpenWeatherMap.org and use it for your SmartHome is explained in the following article.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/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 shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
Of course NodeRed should already be installed so that you can take over this configuration.
How to prepare a RaspberryPi and then install NodeRed on it, is described in the following articles.
RaspberryPi – Setting up for Nerdiys!
RaspberryPi – The first configuration
RaspberryPi – Controlling the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi
NodeRed – Install New Nodes
NodeRed – Import and Export Node Code

Required tools:
-none-

Required material:

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


Log in to the NodeRed configuration interface

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

View of the login screen. Here you have to enter the login details that you entered during the configuration of the login. Information about this can be found in the article NodeRed - User Login Setup.

Register the openWeatherMap API Key

To get your current weather data from openWeahterMap.org, you need an API key. How to register for free is described in this article: Register OpenWeatherMap.org API Key

Later this API key needs to be deposited in the openWeatherMap node. So save it somewhere. 🙂


Install openWeatherMap Node

In order to retrieve data from OpenWeatherMap.Org you need to install the node “node-red-node-openweathermap”. How to install Nodes is explained in the article NodeRed – Install New Nodes.


Import Node Code

The first step is to simply import the following Node code into your NodeRed installation. How to do this is explained in the article NodeRed – Importing and Exporting Node Code.

Immediately thereafter – as described below – you must add the previously registered API key to the configuration.

View of the configuration in the editor.

Node-Code:

[{"id":"85dcceee.5ca84","type":"change","z":"5ebf035f.49459c","name":"außenTemperatur","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":"Daten manuell abrufen","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":"außenLuftfeuchtigkeit","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.main.humidity","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":320,"wires":[["b9f93625.5051b8"]]},{"id":"7aa148d5.934fb8","type":"change","z":"5ebf035f.49459c","name":"außenLuftdruck","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":"Rohdaten","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":680,"y":160,"wires":[]},{"id":"6ab6bc17.16a144","type":"debug","z":"5ebf035f.49459c","name":"außenTemperatur","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":990,"y":200,"wires":[]},{"id":"b9f93625.5051b8","type":"debug","z":"5ebf035f.49459c","name":"außenLuftfeuchtigkeit","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1000,"y":320,"wires":[]},{"id":"fbf0a415.6ed9c8","type":"debug","z":"5ebf035f.49459c","name":"außenLuftdruck","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":980,"y":360,"wires":[]},{"id":"52536e82.1cb05","type":"change","z":"5ebf035f.49459c","name":"Windstärke","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":"Windrichtung","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":"Windstärke","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":970,"y":400,"wires":[]},{"id":"d755f34d.fdefa","type":"debug","z":"5ebf035f.49459c","name":"Windrichtung","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":970,"y":440,"wires":[]},{"id":"bcdf0d32.be17a","type":"change","z":"5ebf035f.49459c","name":"wetterBeschreibung","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":"wetterBeschreibung","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1000,"y":480,"wires":[]},{"id":"95d0a7a8.66b9e8","type":"change","z":"5ebf035f.49459c","name":"außenTempMin","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":"außenTempMax","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":"außenTempMin","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":980,"y":240,"wires":[]},{"id":"455148a8.ce5168","type":"debug","z":"5ebf035f.49459c","name":"außenTempMax","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":980,"y":280,"wires":[]}]
In the OpenWeatherMap nodes, your OpenWeatherMap API key must be entered.

Additional information

https://openweathermap.org/


I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. 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 appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

4 comments

  1. HI,
    Coole sache, danke für deine Tutorials 🙂

    Ich habe ein Problem.
    Wenn ich die Temperaturen als Text ausgebe, erhalte ich zu viele Kommastellen dahinter….
    Wie kann ich das Runden?

    Vielen Dank!

    1. Hey Adrian,
      danke. 🙂
      ich mache sowas immer mit einer function Node und etwas JavaScript. (Gibt bestimmt auch noch andere potentiell bessere Wege).
      Ich habe Dir ein Beispiel hier hochgeladen: https://pastebin.com/UesZyP2N
      Den Code solltest du einfach importieren können. Ist hoffentlich selbsterklärend. Ansonsten frag gerne nochmal. 🙂
      Beste Grüße
      Fabian

Leave a Reply

Your email address will not be published. Required fields are marked *