Join info to a JSON

Hello,

I try to grap Wheater Data to forward this to my NSPanel running with tasmota.

I have an JSON input and need to use the right parameters and join them again to have the right thing, but i have a huge Problem...

I need to added 2 vaues to tehe "range" parameter, the lower first than the higher one, but jon will only use one.
On the other heand i not able to make teh JSOn correct, maybe some one can give me a hand?

I use the openwheatermap.or node and the API as input.

i change all icons to NSPanle one.

The ID is for more Icons later.... not needed now.

here is my test:

[{"id":"d8b3e6a00ee508a7","type":"debug","z":"b0fa554.12ee8a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":1680,"wires":[]},{"id":"b735b83c99137d7b","type":"change","z":"b0fa554.12ee8a8","name":"temperatur","rules":[{"t":"move","p":"payload.tempc","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"HMI_outdoorTemp.current","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":1680,"wires":[["75afc5fb7e4fcc35"]]},{"id":"87f88dbeba9eda77","type":"change","z":"b0fa554.12ee8a8","name":"temperur max","rules":[{"t":"move","p":"payload.temp_maxc","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"HMI_outdoorTemp.range","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":1720,"wires":[["75afc5fb7e4fcc35"]]},{"id":"78b95b25bf7f223c","type":"change","z":"b0fa554.12ee8a8","name":"temperur min","rules":[{"t":"move","p":"payload.temp_minc","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"HMI_outdoorTemp.range","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":1760,"wires":[["75afc5fb7e4fcc35"]]},{"id":"93b8e7bfab311f65","type":"debug","z":"b0fa554.12ee8a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":1840,"wires":[]},{"id":"75afc5fb7e4fcc35","type":"join","z":"b0fa554.12ee8a8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":790,"y":1680,"wires":[["d8b3e6a00ee508a7"]]},{"id":"fd77f0e34c91249a","type":"inject","z":"b0fa554.12ee8a8","name":"Final request","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"HMI_weather\":1,\"HMI_outdoorTemp\":{\"current\":6,\"range\":\" 7, 10\"}}","payloadType":"json","x":240,"y":1840,"wires":[["93b8e7bfab311f65"]]}]

Does the data start off in one message or are they coming from three separate sources?

You have not said what is not working with the flow you have posted. Does it not give the output you expect? If not then what does it give and what do you want?

For the future please see this post for how to post your flow - How to share code or flow json

Are the joins needed, can you not just construct the json object you require using change, function or template node.
e.g.

[{"id":"b735b83c99137d7b","type":"change","z":"bf9e1e33.030598","name":"temperatur","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t   \"HMI_weather\": 1,\t   \"HMI_outdoorTemp\": {\t       \"current\": $$.payload.tempc,\t       \"range\": $$.payload.temp_minc & \", \" & $$.payload.temp_maxc   \t   }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":60,"wires":[["d8b3e6a00ee508a7"]]},{"id":"89fbc28.b41b8c","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":800,\"weather\":\"Clear\",\"detail\":\"clear sky\",\"icon\":\"01d\",\"tempk\":283.9,\"tempc\":10.7,\"temp_maxc\":12.9,\"temp_minc\":9.4,\"humidity\":69,\"pressure\":1037,\"maxtemp\":286.08,\"mintemp\":282.58,\"windspeed\":4.02,\"winddirection\":69,\"location\":\"test\",\"sunrise\":1647559855,\"sunset\":1647777347,\"clouds\":0,\"description\":\"The weather in test at coordinates: 50.7687, 12.2845 is Clear (clear sky).\"}","payloadType":"json","x":80,"y":60,"wires":[["b735b83c99137d7b","93b8e7bfab311f65"]]},{"id":"d8b3e6a00ee508a7","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":60,"wires":[]}]

Hello,

the injector "wettertest" is the complete answer from the API, that is the input i get.

the "Final Request" injector is the Working massage that i need.

I try to split the "wettertest" to seperate the "Picture, Temperture and Range min and max" Than try to join them like the "Final Reqest" to send this to my Panel.

Sorry for the bad discription, i hope this info help.

i think about to send all single data to a own variable, to send them in the right order ...?

THAT is a BIG Step, the last was missing is now the Icon for my panel, it is possiable to change the the "HMI_weather" bevor the input?

the "icon NSpanel" is the needed changes.

Please explain where the icon comes from, as it is not clear to me.

The Icon is Part of the Firmware,

The api will send a numer like "100" for sun (Weather Conditions - OpenWeatherMap) I used the (picture for simple test at the moment)
But my Panel would like to have for sun "1" so i need to change the Input to the correct output what the Display like to have. I tryed with this line:

[{"id":"7b9e70398f11aae2","type":"change","z":"b0fa554.12ee8a8","name":"Icon","rules":[{"t":"move","p":"payload.icon","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"HMI_weather","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1600,"wires":[["2a463341746cd039"]]},{"id":"2a463341746cd039","type":"change","z":"b0fa554.12ee8a8","name":"icon NSpanel","rules":[{"t":"change","p":"payload","pt":"msg","from":"01d","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"02d","fromt":"str","to":"2","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"03d","fromt":"str","to":"7","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"04d","fromt":"str","to":"7","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"09d","fromt":"str","to":"40","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"10d","fromt":"str","to":"18","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"11d","fromt":"str","to":"42","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"13d","fromt":"str","to":"22","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"50d","fromt":"str","to":"11","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"01n","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"02n","fromt":"str","to":"2","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"03n","fromt":"str","to":"7","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"04n","fromt":"str","to":"7","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"09n","fromt":"str","to":"40","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"10n","fromt":"str","to":"18","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"11n","fromt":"str","to":"42","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"13n","fromt":"str","to":"22","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"50n","fromt":"str","to":"11","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1600,"wires":[["75afc5fb7e4fcc35"]]}]

You would need to construct a lookup table(object)
In the example below i have created a lookup object with 2 values, you would need to add all the openweather codes and then add the value you wish it to change to. Then in the JSONata expression use the payload.icon to look up the NSpanel icon
e.g

[{"id":"89fbc28.b41b8c","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":800,\"weather\":\"Clear\",\"detail\":\"clear sky\",\"icon\":\"01d\",\"tempk\":283.9,\"tempc\":10.7,\"temp_maxc\":12.9,\"temp_minc\":9.4,\"humidity\":69,\"pressure\":1037,\"maxtemp\":286.08,\"mintemp\":282.58,\"windspeed\":4.02,\"winddirection\":69,\"location\":\"test\",\"sunrise\":1647559855,\"sunset\":1647777347,\"clouds\":0,\"description\":\"The weather in test at coordinates: 50.7687, 12.2845 is Clear (clear sky).\"}","payloadType":"json","x":80,"y":60,"wires":[["b735b83c99137d7b"]]},{"id":"b735b83c99137d7b","type":"change","z":"bf9e1e33.030598","name":"temperatur","rules":[{"t":"set","p":"icons","pt":"msg","to":"{\"01d\":\"1\",\"02d\":\"2\"}","tot":"json"},{"t":"set","p":"payload","pt":"msg","to":"{\t   \"HMI_weather\": $lookup($$.icons, $$.payload.icon),\t   \"HMI_outdoorTemp\": {\t       \"current\": $$.payload.tempc,\t       \"range\": $$.payload.temp_minc & \", \" & $$.payload.temp_maxc   \t   }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":60,"wires":[["d8b3e6a00ee508a7"]]},{"id":"d8b3e6a00ee508a7","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":80,"wires":[]}]

Great!!!!!

That looks to work, but the last on fine tuning:

I need Numbers without "." so instad of 10.1 i need 10.

Is there a way to change the numbers to number without .?

OK, looks it will work with the original input... no needed to change the numbers i think..

i will take a look and come back in some hour to proof.

Ok i get error, and teh corrent temp willl only show a Number without a dot. The max and min, will work.....

Please in future take some time and supply an input object and exactly how you wish the output to look, that will save some time and back and forth posts.

[{"id":"89fbc28.b41b8c","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":800,\"weather\":\"Clear\",\"detail\":\"clear sky\",\"icon\":\"01d\",\"tempk\":283.9,\"tempc\":10.7,\"temp_maxc\":12.9,\"temp_minc\":9.4,\"humidity\":69,\"pressure\":1037,\"maxtemp\":286.08,\"mintemp\":282.58,\"windspeed\":4.02,\"winddirection\":69,\"location\":\"test\",\"sunrise\":1647559855,\"sunset\":1647777347,\"clouds\":0,\"description\":\"The weather in test at coordinates: 50.7687, 12.2845 is Clear (clear sky).\"}","payloadType":"json","x":80,"y":60,"wires":[["b735b83c99137d7b"]]},{"id":"b735b83c99137d7b","type":"change","z":"bf9e1e33.030598","name":"temperatur","rules":[{"t":"set","p":"icons","pt":"msg","to":"{\"01d\":\"1\",\"02d\":\"2\"}","tot":"json"},{"t":"set","p":"payload","pt":"msg","to":"{\t   \"HMI_weather\": $lookup($$.icons, $$.payload.icon),\t   \"HMI_outdoorTemp\": {\t       \"current\": $round($$.payload.tempc),\t       \"range\": $round($$.payload.temp_minc) & \", \" & $round($$.payload.temp_maxc)   \t   }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":60,"wires":[["d8b3e6a00ee508a7"]]},{"id":"d8b3e6a00ee508a7","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":80,"wires":[]}]

Thanks,

you are right, but i do not noticed the error before, the display was fine, only the console send error:1 so i do not noticed.

But with your one i can change the input to the output i need!

MANY THANKS!!!!

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