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 stores listed here are so-called affiliate links. If you click on such an affiliate link and store via this link, Nerdiy.de receives a commission from the online store 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":"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":[ ]}]
In the OpenWeatherMap nodes, your OpenWeatherMap API key must be entered.

Additional information

https://openweathermap.org/


Have fun with the project

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. 🙂

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

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
    like "The current weather in..." or "The wind is blowing from that 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 it 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 spend 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