problem with weerlive api to domoticz using node-red
Posted: Friday 13 November 2020 15:55
Hi,
I'm trying to learn some node-red and domoticz, so i chose a practice project. Getting the forecast from the weerlive.nl api and pushing it into a domoticz virtual text sensor.
but i can't get it to work. let me explain what i have so far:
I have a device (dummy sensor of type weather forecast / text) in domoticz
i have mqtt running and working to deliver data to domoticz (this already works with another flow)
i have an api key for weerlive.nl as i need it for my home town. but for this post, we could use the demo api key that only works for Amsterdam. which makes the url be like: http://weerlive.nl/api/json-data-10min. ... =Amsterdam and that outputs something like:
{ "liveweer": [{"plaats": "Amsterdam", "temp": "12.4", "gtemp": "8.4", "samenv": "Geheel bewolkt", "lv": "90", "windr": "ZZW", "windms": "6", "winds": "4", "windk": "11.7", "windkmh": "21.6", "luchtd": "1012.2", "ldmmhg": "759", "dauwp": "10", "zicht": "20", "verw": "Bewolkt en af en toe (mot)regen, morgenmiddag vooral in het zuiden zon", "sup": "07:58", "sunder": "16:52", "image": "bewolkt", "d0weer": "bewolkt", "d0tmax": "12", "d0tmin": "5", "d0windk": "3", "d0windknp": "8", "d0windms": "4", "d0windkmh": "15", "d0windr": "Z", "d0neerslag": "4", "d0zon": "7", "d1weer": "bewolkt", "d1tmax": "14", "d1tmin": "8", "d1windk": "3", "d1windknp": "8", "d1windms": "4", "d1windkmh": "15", "d1windr": "Z", "d1neerslag": "30", "d1zon": "30", "d2weer": "regen", "d2tmax": "15", "d2tmin": "12", "d2windk": "3", "d2windknp": "10", "d2windms": "5", "d2windkmh": "19", "d2windr": "Z", "d2neerslag": "90", "d2zon": "10", "alarm": "0"}]}
debug node shows me the output of a http request node nicely. the forecast value is called "verw" which is the first 4 characters of the Dutch word verwachting, which means 'expectation' or in terms of weather, forecast. This entry holds a sentence describing the forecast, like: "Bewolkt en af en toe (mot)regen, morgenmiddag vooral in het zuiden zon" (which it sais right now.)
this i run through a split node into a function nodig where i want to make this output domoticz-readable, and there it breaks. i get nothing:
13/11/2020, 15:45:54node: 9d51eb61.26c4f8
msg.payload : string[0]
""
yeah, nothing. i expected more. really. just a little more if at all possible...
here's the function i put in the function node:
var msg1 = {};
msg.topic = msg.payload.name;
switch (msg.topic) {
case "verw":
msg.payload = {"command":"udevice","idx":111,"nvalue":0,"svalue":(msg.payload.verw)};
break;
}
return msg;
probably way overcomplicated and apparently wrong. I put it in switch/case to allow me to add other things to sensors later. i guess the problem is in the payload somehow.
but what is wrong, i just can't figure it out, probably because i understand very little about this whole system still. But i'm willing to learn, because i have a long list of things i want to try out. oh, and i'm not a programmer or software developer, so these things don't come naturally.
Of course i need to add the domoticz mqtt node at the end, but I'll just copy that from the other flow, so i dont expect any problems there...
so i hope someone can just point out my failings and set me straight on the node-red path of glory. Thanks for any help!
Cheers
Willem
I'm trying to learn some node-red and domoticz, so i chose a practice project. Getting the forecast from the weerlive.nl api and pushing it into a domoticz virtual text sensor.
but i can't get it to work. let me explain what i have so far:
I have a device (dummy sensor of type weather forecast / text) in domoticz
i have mqtt running and working to deliver data to domoticz (this already works with another flow)
i have an api key for weerlive.nl as i need it for my home town. but for this post, we could use the demo api key that only works for Amsterdam. which makes the url be like: http://weerlive.nl/api/json-data-10min. ... =Amsterdam and that outputs something like:
{ "liveweer": [{"plaats": "Amsterdam", "temp": "12.4", "gtemp": "8.4", "samenv": "Geheel bewolkt", "lv": "90", "windr": "ZZW", "windms": "6", "winds": "4", "windk": "11.7", "windkmh": "21.6", "luchtd": "1012.2", "ldmmhg": "759", "dauwp": "10", "zicht": "20", "verw": "Bewolkt en af en toe (mot)regen, morgenmiddag vooral in het zuiden zon", "sup": "07:58", "sunder": "16:52", "image": "bewolkt", "d0weer": "bewolkt", "d0tmax": "12", "d0tmin": "5", "d0windk": "3", "d0windknp": "8", "d0windms": "4", "d0windkmh": "15", "d0windr": "Z", "d0neerslag": "4", "d0zon": "7", "d1weer": "bewolkt", "d1tmax": "14", "d1tmin": "8", "d1windk": "3", "d1windknp": "8", "d1windms": "4", "d1windkmh": "15", "d1windr": "Z", "d1neerslag": "30", "d1zon": "30", "d2weer": "regen", "d2tmax": "15", "d2tmin": "12", "d2windk": "3", "d2windknp": "10", "d2windms": "5", "d2windkmh": "19", "d2windr": "Z", "d2neerslag": "90", "d2zon": "10", "alarm": "0"}]}
debug node shows me the output of a http request node nicely. the forecast value is called "verw" which is the first 4 characters of the Dutch word verwachting, which means 'expectation' or in terms of weather, forecast. This entry holds a sentence describing the forecast, like: "Bewolkt en af en toe (mot)regen, morgenmiddag vooral in het zuiden zon" (which it sais right now.)
this i run through a split node into a function nodig where i want to make this output domoticz-readable, and there it breaks. i get nothing:
13/11/2020, 15:45:54node: 9d51eb61.26c4f8
msg.payload : string[0]
""
yeah, nothing. i expected more. really. just a little more if at all possible...
here's the function i put in the function node:
var msg1 = {};
msg.topic = msg.payload.name;
switch (msg.topic) {
case "verw":
msg.payload = {"command":"udevice","idx":111,"nvalue":0,"svalue":(msg.payload.verw)};
break;
}
return msg;
probably way overcomplicated and apparently wrong. I put it in switch/case to allow me to add other things to sensors later. i guess the problem is in the payload somehow.
but what is wrong, i just can't figure it out, probably because i understand very little about this whole system still. But i'm willing to learn, because i have a long list of things i want to try out. oh, and i'm not a programmer or software developer, so these things don't come naturally.
Of course i need to add the domoticz mqtt node at the end, but I'll just copy that from the other flow, so i dont expect any problems there...
so i hope someone can just point out my failings and set me straight on the node-red path of glory. Thanks for any help!
Cheers
Willem