[newbie] Using message properties as the source for openweathermap settings

I was wondering whether it is possible to use a msg.payload from a node-red flow as the input
of a field in the settings of a node. As an example I added a screenshot of the settings of an openweathermap-node. You can see the field for the City is now filled out with the word Brussels,
but I'd like this rather to be a msg.payload or a variable related to a msg.payload from somewhere else
in the flow. That way I wouldn't have to make an openweathermapnode for each city I'd like to check the weather of.
openweathermapnodesettings

kind regards,
hugo

Hi Hugo,

you should always read the built in help...

So try adding a change node and setting these values in a change node & passing the msg to the map node.

1 Like

Thank you for answering my question. I have made a flow in which I tried to follow you suggestion but
I didn't succeed. Could you help me further. The idea is to inject a city name to get the weather report of that city.
Here is my attempt:

[{"id":"ae46cfb1.dce128","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"e0b1dccc.971618","type":"inject","z":"ae46cfb1.dce128","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Gent","payloadType":"str","x":190,"y":260,"wires":[["13f1b9bb.30627e"]]},{"id":"1c8c4efc.9c3f29","type":"debug","z":"ae46cfb1.dce128","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":950,"y":260,"wires":[]},{"id":"2264ad42.461f4a","type":"inject","z":"ae46cfb1.dce128","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Brussel","payloadType":"str","x":190,"y":220,"wires":[["13f1b9bb.30627e"]]},{"id":"88831334.c3e4d8","type":"inject","z":"ae46cfb1.dce128","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Aalst","payloadType":"str","x":190,"y":300,"wires":[["13f1b9bb.30627e"]]},{"id":"c927ea1f.01c138","type":"openweathermap","z":"ae46cfb1.dce128","name":"CurrentOpenWeatherReportCity","wtype":"current","lon":"","lat":"","city":"","country":"Belgium","language":"msg","x":690,"y":260,"wires":[["1c8c4efc.9c3f29"]]},{"id":"13f1b9bb.30627e","type":"change","z":"ae46cfb1.dce128","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"location.city","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":260,"wires":[["c927ea1f.01c138"]]}]

or via this link:
https://www.dropbox.com/s/e8h8dncbrjrkd4v/wheatherflow.json?dl=1

kind regards,
Hugo

You have these the wrong way around...
image
It reads as Set msg.payload to the value of msg.location.city

What you need is Set msg.location.city to the value of msg.payload

also, you will need to set the msg.location to an object before trying to add the city property.

e.g...

image

Thanks Steve for being patient with me. I tried to follow your suggestions but it still does not work,
I get the error-message "Invalid location information provided" in the debug-node at the output.
Here is my adapted flow:

[{"id":"e66a1702.7b949","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"c746b31c.76bd","type":"inject","z":"e66a1702.7b949","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Gent","payloadType":"str","x":230,"y":180,"wires":[["202d9c26.2b8abc"]]},{"id":"604d3752.81f1a","type":"debug","z":"e66a1702.7b949","name":"payloadout","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":200,"wires":[]},{"id":"6ebb087.515f4f8","type":"inject","z":"e66a1702.7b949","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Brussel","payloadType":"str","x":230,"y":140,"wires":[["202d9c26.2b8abc"]]},{"id":"eba44b57.a25ad","type":"inject","z":"e66a1702.7b949","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Aalst","payloadType":"str","x":230,"y":220,"wires":[["202d9c26.2b8abc"]]},{"id":"a897b695.e9883","type":"openweathermap","z":"e66a1702.7b949","name":"CurrentOpenWeatherReportCity","wtype":"current","lon":"","lat":"","city":"","country":"Belgium","language":"msg","x":731.3333129882812,"y":130.16666412353516,"wires":[["604d3752.81f1a"]]},{"id":"202d9c26.2b8abc","type":"change","z":"e66a1702.7b949","name":"WhichCity?","rules":[{"t":"set","p":"location","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"location.city","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":180,"wires":[["a897b695.e9883"]]}]

kind regards,
hugo

Alternatively, if you use Move msg.payload To msg.location.city then you don't need to create msg.location first.

To paste a flow here you should use the </> button and paste it in, otherwise it is not importable.

[Edit] I have corrected it for you.

I haven't used that node but the help suggests you need country as well as city.

Your flow is now correctly setting msg.location.city

However, I am not familiar with that node nor its internal workings.

You might have to ALSO leave country (empty on the UI) and pass that in msg.location.country

e.g..


image

... but i am guessing now

OK, I was not totally sure about using the block quote or the </> button, I'll take care of it in the future.

kind regards,
Hugo

Thanks a lot for helping me out, I appreciate it very much.
Het is my final flow:

[{"id":"8bb43132.919c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"5dfcb174.eded28","type":"inject","z":"8bb43132.919c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Gent","payloadType":"str","x":190,"y":260,"wires":[["c5ddd569.f17f6"]]},{"id":"7cb699e8.641a1","type":"debug","z":"8bb43132.919c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":950,"y":260,"wires":[]},{"id":"d3e1d838.101d78","type":"inject","z":"8bb43132.919c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Brussel","payloadType":"str","x":190,"y":220,"wires":[["c5ddd569.f17f6"]]},{"id":"8b355116.4dc3e8","type":"inject","z":"8bb43132.919c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Aalst","payloadType":"str","x":190,"y":300,"wires":[["c5ddd569.f17f6"]]},{"id":"d70b1257.1c61f","type":"openweathermap","z":"8bb43132.919c","name":"CurrentOpenWeatherReportCity","wtype":"current","lon":"","lat":"","city":"","country":"","language":"msg","x":690,"y":260,"wires":[["7cb699e8.641a1"]]},{"id":"c5ddd569.f17f6","type":"change","z":"8bb43132.919c","name":"","rules":[{"t":"set","p":"location","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"location.city","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"location.country","pt":"msg","to":"Belgium","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":260,"wires":[["d70b1257.1c61f"]]}]

thanks again and kind regards,
Hugo

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.