MQTT values Node-Red to Domoticz values

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
edje1205
Posts: 34
Joined: Tuesday 20 December 2016 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Amsterdam Nieuwendam
Contact:

MQTT values Node-Red to Domoticz values

Post by edje1205 »

Hi all

I have values from MQTT to Node-Red with MQTTin.txt/MQTTout.txt see att 3

I could place temp/hum/bar/text from WD MQTTout.txt in sensors with scripts from internet See att 2 and att 1

found script for itemp/hum/(baro)
[
var TEMP = msg.payload.temp;
//var TEMP = "20";
var HUM= msg.payload.hum;
//var HUM = "45";
var HUM_STAT=0;
if (HUM < 30) {
HUM_STAT=2;
} else if ((HUM >= 30) & (HUM < 45)) {
HUM_STAT=0;
} else if ((HUM >= 45) & (HUM < 70)) {
HUM_STAT=1;
} else if (HUM >= 70) {
HUM_STAT=3;
}
msg.payload = {"command":"udevice","idx":416,"nvalue":0,"svalue":TEMP + ";" + HUM + ";" + HUM_STAT};
return msg;
]


Also I have values from Darksky / Buienradar /Open Weather Maps sensors see att 2 and 3
(But I prefere my own values from my weatherstation Davis VP2 and software WeatherDisplay more precisely, sensors with ".." WD on it)


For other values (see below) I did not find any scripts to get them in sensors (or I did not understand :lol:) however I studied/searched for months #-o


2020-10-21 13:34:14.758 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":518,"nvalue":0,"svalue:RAINRATE":0.2}
2020-10-21 13:34:14.869 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":516,"nvalue":0,"svalue:UV;TEMP;UVN128,UV138":0}

[solarradiation]
2020-10-21 13:34:14.986 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":394,"nvalue":0,"svalue:Solar Radiation":209}
2020-10-21 13:34:16.150 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":428,"nvalue":0,"svalue:Solar Radiation":209}





[winddir]
2020-10-21 13:34:15.814 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":527,"svalue":160}

[windspeed][winddir]
2020-10-21 13:34:15.914 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":515,"nvalue":0,"svalue":"WB;WD;WS;WG;22;24"}

[raintoday]
2020-10-21 13:34:16.033 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":519,"nvalue":0,"svalue:RAINCOUNTER;RAINRATE;":8.8}


[avgbearing]
2020-10-21 13:34:16.268 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":514,"nvalue":0,"svalue:winddir":160}
2020-10-21 13:34:16.385 MQTT: Topic: domoticz/in, Message: ZuidZuidOost


Anybody here who can help me out ? Very appriciated !!

Thank so far !

Ed
Attachments
mqtt console.jpg
mqtt console.jpg (104.15 KiB) Viewed 5275 times
mqtt values WD in domoticz sensors.jpg
mqtt values WD in domoticz sensors.jpg (176.34 KiB) Viewed 5275 times
mqtt out node-red.jpg
mqtt out node-red.jpg (110.43 KiB) Viewed 5275 times
edje1205
Posts: 34
Joined: Tuesday 20 December 2016 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Amsterdam Nieuwendam
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by edje1205 »

This is what I get in Domoticz Log
Made several sensors got Data but (both)sensors are not updating:


Rain
2020-12-03 13:27:24.864 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":519,"nvalue":0,"svalue:RAINCOUNTER;RAINRATE;":2.7}

2020-12-03 13:27:23.631 Status: Warning: Expecting svalue with at least 2 elements separated by semicolon, 0 elements received (""), notification not sent (Hardware: 4 - RFLink Gateway USB, ID: 82518, Unit: 1, Type: 55 - Rain, SubType: 3 - TFA)
2020-12-03 13:27:24.885 Status: Warning: Expecting svalue with at least 2 elements separated by semicolon, 0 elements received (""), notification not sent (Hardware: 4 - RFLink Gateway USB, ID: 82519, Unit: 1, Type: 55 - Rain, SubType: 3 - TFA)



UV
2020-12-03 13:27:23.731 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":516,"nvalue":0,"svalue:UV;TEMP;UVN128,UV138":0}

2020-12-03 13:27:23.741 Status: Warning: Expecting svalue with at least 2 elements separated by semicolon, 0 elements received (""), notification not sent (Hardware: 4 - RFLink Gateway USB, ID: 82516, Unit: 1, Type: 57 - UV, SubType: 1 - UVN128,UV138)


Solar
2020-12-03 13:27:23.842 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":394,"nvalue":0,"svalue:Solar Radiation":14}
Solar
2020-12-03 13:27:24.985 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":428,"nvalue":0,"svalue":14}


Wind(+direction)
2020-12-03 13:27:24.741 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":426,"nvalue":0,"svalue":"WS;WB;WD;WG;22;24"}
Wind(direction)
2020-12-03 13:27:25.086 MQTT: Topic: domoticz/in, Message: Zuid
2020-12-03 13:27:25.186 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":514,"nvalue":0,"svalue:winddir":168}

?? belongs to wich IDX
2020-12-03 13:27:24.641 Error: MQTT: Invalid data received!
2020-12-03 13:27:24.986 Error: MQTT: Invalid data received!
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by FireWizard »

Hi, @edje1205

If you want to update sensors in Domoticz with MQTT, I recommend to read:
https://piandmore.wordpress.com/2019/02 ... -domoticz/

This is a very nice overview and in my opinion easier to read then:
https://www.domoticz.com/wiki/MQTT and https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s

Remember that nvalue always require a numerical value and svalue always require a string value.
A string value is always within quotes (" ").
So, "this is a string" and this is not a string. Similar 123 is a number, but "123" is not a number, but a string.
A string you can concatenate. So "Hello" + " world" will become "Hello world".
Similar 1 + 2 equals 3, but "1" + "2" equals "12".

1.
The first sensor you want to update is the "Rain" sensor.

Rain

The rain sensor will show the amount of rain fallen in mm and a rate in mm/h. You can send
{"command":"udevice", "idx":1234, "svalue":"rt;fl"}
where rt is the rate in mm/h fl is amount of rain fallen. PLEASE NOTE that fl is cumulative, so if the value is 3 mm and you send 2 mm, it will be 5 mm.

It is unclear for me, how you receive the value, but lets assume rate msg.payload.rate = 0 and the amount of rain fallen msg.payload.fallen= 2
Let us also assume that this are numbers and not strings.

The command you have to send to Domoticz is:

Code: Select all

msg.payload = {"command":"udevice","idx":519,"nvalue":0,"svalue":msg.payload.rate.toString() + ";" + msg.payload.fallen.toString()};
return msg;
If it are already strings, then you should remove the .toString() function.

2.
Second sensor is the UV sensor.

UV

The UV sensor will show just that in the UV Index. You can add digits after the decimal if needed.
{"command":"udevice", "idx":1234, "svalue":"uv;0"}
where uv is the uv index.

I don't know where the UV value comes from but let's assume it is a number and is available in msg.payload.uv.

The command you have to send to Domoticz is:

Code: Select all

msg.payload = {"command":"udevice","idx":516,"nvalue":0,"svalue":msg.payload.uv.toString() + ";" + "0"};
return msg;
or at the end ";0" instead of ";" + "0".
If it are already strings, then you should remove the .toString() function.

3.
Third sensor is the Solar radiation sensor.

Solar radiation

The solar radiation sensor will show just that in W/m2. You can add digits after the decimal if needed.
{"command":"udevice", "idx":1234, "svalue":"3.45"}
I don't know where the Solar value comes from but let's assume it is a number and is available in msg.payload.solar and is a number.

The command you have to send to Domoticz is:

Code: Select all

msg.payload = {"command":"udevice","idx":394,"nvalue":0,"svalue":msg.payload.solar.toString()};
return msg;
If it are already strings, then you should remove the .toString() function.

4.
Fourth sensor is the Wind sensor.

Wind

The wind sensor will show wind direction, velocity and gust speed. You can add digits after the decimal if needed.
{"command":"udevice", "idx":1234, "svalue":"an;dr;sp;gu;tm;ch"}
where an and dr are used to show the angle and wind direction, where an is the angle (can be any number and my have digits after the decimal) and dr is the direction. You can use N, NE, E, SE, S, SW, W and NW. sp is the speed in 0.1 m/s and gu is the gust speed in 0.1 m/s.

You can program it yourself, as we have 6 parameters and I don't know, where they come from.
If you can provide that information I can support you, but the principal is the same.

For temperature and humidity, I suggest you have a look at: viewtopic.php?f=34&t=32414&p=261548#p261548

Remember, you can not invent your own sensor devices, such as: winddir, windspeed+winddir, avgbearing and the svalue has to comply with the format in https://piandmore.wordpress.com/2019/02 ... -domoticz/

If you need more I'm happy to support you,

Regards
edje1205
Posts: 34
Joined: Tuesday 20 December 2016 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Amsterdam Nieuwendam
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by edje1205 »

@FireWizard

Thank you so much for all your advices, you made my day ! Now I got Rain, solar and I suppose UV (0 today so wait till better times)
Allreadey had Temp Hum Pressure (Hp)

I wil ltry to explain some values from my weatherstation, weatherprogram and MQTT:

All values are from my own waterstation Davis Vantage Pro 2.0 and weather program WeatherDisplay. (from developer Brian Hamilton)
This last program generates MQTTin.txt to MQTTout.txt

Output to Domoticz is:

Code: Select all

{"ClientID":"Nieuwendam","date":"14:27","dateFormat":"d/m/y","temp":5.6,"tempTL":1.2,"tempTH":5.8,"intemp":17.7,"dew":2.7,"dewpointTL":0.1,"dewpointTH":3.6,"apptemp":2.9,"apptempTL":-0.4,"apptempTH":7.1,"wchill":2.4,"wchillTL":-1.3,"heatindex":5.6,"heatindexTH":5.8,"humidex":4.1,"wlatest":4.2,"[b]wspeed":2.5[/b],"wgust":5.1,"wgustTM":5.7,"bearing":166,"[b]avgbearing":170[/b],"press":996.6,"pressTL":989.7,"pressTH":996.6,"pressL":812,"pressH":1046.9,"rfall":0,"rrate":0,"rrateTM":0,"hum":82,"humTL":82,"humTH":93,"inhum":44,"SensorContactLost":"0","forecast":"Meest bewolkt en koeler. Binnen 12 uur neerslag mogelijk, mogelijk met zware buien. Winderig.","tempunit":"C","windunit":"m/s","pressunit":"hPa","rainunit":"mm","temptrend":"+0.0","TtempTL":"08:09","TtempTH":"12:48","TdewpointTL":"08:09","TdewpointTH":"12:31","TapptempTL":"08:28","TapptempTH":"12:29","TwchillTL":"12:47","TheatindexTH":"12:48","TrrateTM":"00:00","ThourlyrainTH":"04:59","LastRainTipISO":"4/12/2020 04:58","hourlyrainTH":0,"raintoday":0,"ThumTL":"13:01","ThumTH":"08:12","TpressTL":"00:00","TpressTH":"14:26","presstrendval":"+1.1","Tbeaufort":5,"TwgustTM":"12:03","windTM":3.7,"bearingTM":155,"timeUTC":"2020,12,05,13,27,22","BearingRangeFrom10":149,"BearingRangeTo10":200,"UV":{"command":"udevice","idx":509,"nvalue":0,"svalue":"0;0"},"UVTH":0,"SolarRad":69,"CurrentSolarMax":124,"SolarTM":251,"domwinddir":"South southeasterly","windrun":51.06,"version":"10.37S","build":"114","ver":"10"}
windspeed in m/s but no value with

Code: Select all

MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":426,"nvalue":0,"svalue":"an;dr;sp;gu;tm;ch"} 
I try to destilate values with Node-red that give me in Domoticz Log:

Code: Select all

MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":514,"nvalue":0,"svalue:winddir":"170"} 
170 is South wind with next formula:

Code: Select all

var richting = msg.payload.avgbearing;
var Text = "Onbekend";
msg.payload = {"command":"udevice","idx":514,"nvalue":0,"svalue:winddir" : msg.payload.avgbearing.toString()};
if (richting >= 0 && richting <= 10){
    Text = "Noord";
}
if (richting >= 11 && richting <= 30){
    Text = "NoordNoordOoost";
}
if (richting >= 31 && richting <= 54){
    Text = "NoordOost";
}
if (richting >= 55 && richting <= 79){
    Text = "OostNoordOost";
}
if (richting >= 80 && richting <= 101){
    Text = "Oost";
}
if (richting >= 102 && richting <= 120){
    Text = "OostZuidOost";
}
if (richting >= 121 && richting <= 141){
    Text = "ZuidOost";
}
if (richting >= 142 && richting <= 164){
    Text = "ZuidZuidOost";
}
if (richting >= 165 && richting <= 190){
    Text = "Zuid";
}
if (richting >= 191 && richting <= 211){
    Text = "ZuidZuidWest";
}
if (richting >= 212 && richting <= 235){
    Text = "ZuidWest";
}
if (richting >= 236 && richting <= 259){
    Text = "WestZuidWest";
}
if (richting >= 260 && richting <= 285){
    Text = "West";
}
if (richting >= 285 && richting <= 310){
    Text = "WestNoordWest";
}
if (richting >= 310 && richting <= 327){
    Text = "NoordWest";
}
if (richting >= 328 && richting <= 348){
    Text = "NoordNoordWest";
}
if (richting >= 348 && richting <= 360){
    Text = "Noord";
}
return {payload:Text,richting}
gives me
MQTT: Topic: domoticz/in, Message: Zuid

but I don't get it in my Domoticz Sensor


Hope I did not confuse you but that is what it is (I'm struggling since months with it)
If you need more I'm happy to support you
Yes I do !
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by FireWizard »

Hi, @edje1205

You wrote in your previous post the following:
All values are from my own waterstation Davis Vantage Pro 2.0 and weather program WeatherDisplay. (from developer Brian Hamilton)
This last program generates MQTTin.txt to MQTTout.txt

Output to Domoticz is:

Code: Select all

{"ClientID":"Nieuwendam","date":"14:27","dateFormat":"d/m/y","temp":5.6,"tempTL":1.2,"tempTH":5.8,"intemp":17.7,"dew":2.7,"dewpointTL":0.1,"dewpointTH":3.6,"apptemp":2.9,"apptempTL":-0.4,"apptempTH":7.1,"wchill":2.4,"wchillTL":-1.3,"heatindex":5.6,"heatindexTH":5.8,"humidex":4.1,"wlatest":4.2,"wspeed":2.5,"wgust":5.1,"wgustTM":5.7,"bearing":166,"avgbearing":170,"press":996.6,"pressTL":989.7,"pressTH":996.6,"pressL":812,"pressH":1046.9,"rfall":0,"rrate":0,"rrateTM":0,"hum":82,"humTL":82,"humTH":93,"inhum":44,"SensorContactLost":"0","forecast":"Meest bewolkt en koeler. Binnen 12 uur neerslag mogelijk, mogelijk met zware buien. Winderig.","tempunit":"C","windunit":"m/s","pressunit":"hPa","rainunit":"mm","temptrend":"+0.0","TtempTL":"08:09","TtempTH":"12:48","TdewpointTL":"08:09","TdewpointTH":"12:31","TapptempTL":"08:28","TapptempTH":"12:29","TwchillTL":"12:47","TheatindexTH":"12:48","TrrateTM":"00:00","ThourlyrainTH":"04:59","LastRainTipISO":"4/12/2020 04:58","hourlyrainTH":0,"raintoday":0,"ThumTL":"13:01","ThumTH":"08:12","TpressTL":"00:00","TpressTH":"14:26","presstrendval":"+1.1","Tbeaufort":5,"TwgustTM":"12:03","windTM":3.7,"bearingTM":155,"timeUTC":"2020,12,05,13,27,22","BearingRangeFrom10":149,"BearingRangeTo10":200,"UV":{"command":"udevice","idx":509,"nvalue":0,"svalue":"0;0"},"UVTH":0,"SolarRad":69,"CurrentSolarMax":124,"SolarTM":251,"domwinddir":"South southeasterly","windrun":51.06,"version":"10.37S","build":"114","ver":"10"}

windspeed in m/s but no value with
I think this cannot be the output to Domoticz. At least Domoticz will not understand it. It looks as it is the output from your weather station. However it contains some errors. No idea, how they were introduced, maybe copy/paste.
1. After UV: you will find the phrase
{"command":"udevice","idx":509,"nvalue":0,"svalue":"0;0"}
This does not come from your weather station as it is formatted as a command to Domoticz. Probably the example from my previous post.

2. You will also find some text formatting in this string, This is not correct and comes from the forum editor.
You will find:
wspeed":2.5
and
avgbearing":170
This represents bold characters.

I have removed these errors and created a test flow.

Can you check and compare the output of your weather station with this test flow,
Did I miss something or are there errors.
It is assumed that your MQTT server (Mosquitto) is on the same device as Node Red. I use 'localhost'. If not, you have to change that.

Hereby the flow:

Code: Select all

[{"id":"47d75961.f88b6","type":"tab","label":"Test Weather","disabled":false,"info":""},{"id":"d59b5874.b95428","type":"inject","z":"47d75961.f88b6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"MQTTout","payload":"{\"ClientID\":\"Nieuwendam\",\"date\":\"14:27\",\"dateFormat\":\"d/m/y\",\"temp\":5.6,\"tempTL\":1.2,\"tempTH\":5.8,\"intemp\":17.7,\"dew\":2.7,\"dewpointTL\":0.1,\"dewpointTH\":3.6,\"apptemp\":2.9,\"apptempTL\":-0.4,\"apptempTH\":7.1,\"wchill\":2.4,\"wchillTL\":-1.3,\"heatindex\":5.6,\"heatindexTH\":5.8,\"humidex\":4.1,\"wlatest\":4.2,\"wspeed\":2.5,\"wgust\":5.1,\"wgustTM\":5.7,\"bearing\":166,\"avgbearing\":170,\"press\":996.6,\"pressTL\":989.7,\"pressTH\":996.6,\"pressL\":812,\"pressH\":1046.9,\"rfall\":0,\"rrate\":0,\"rrateTM\":0,\"hum\":82,\"humTL\":82,\"humTH\":93,\"inhum\":44,\"SensorContactLost\":\"0\",\"forecast\":\"Meest bewolkt en koeler. Binnen 12 uur neerslag mogelijk, mogelijk met zware buien. Winderig.\",\"tempunit\":\"C\",\"windunit\":\"m/s\",\"pressunit\":\"hPa\",\"rainunit\":\"mm\",\"temptrend\":\"+0.0\",\"TtempTL\":\"08:09\",\"TtempTH\":\"12:48\",\"TdewpointTL\":\"08:09\",\"TdewpointTH\":\"12:31\",\"TapptempTL\":\"08:28\",\"TapptempTH\":\"12:29\",\"TwchillTL\":\"12:47\",\"TheatindexTH\":\"12:48\",\"TrrateTM\":\"00:00\",\"ThourlyrainTH\":\"04:59\",\"LastRainTipISO\":\"4/12/2020 04:58\",\"hourlyrainTH\":0,\"raintoday\":0,\"ThumTL\":\"13:01\",\"ThumTH\":\"08:12\",\"TpressTL\":\"00:00\",\"TpressTH\":\"14:26\",\"presstrendval\":\"+1.1\",\"Tbeaufort\":5,\"TwgustTM\":\"12:03\",\"windTM\":3.7,\"bearingTM\":155,\"timeUTC\":\"2020,12,05,13,27,22\",\"BearingRangeFrom10\":149,\"BearingRangeTo10\":200,\"UV\":0,\"UVTH\":0,\"SolarRad\":69,\"CurrentSolarMax\":124,\"SolarTM\":251,\"domwinddir\":\"South southeasterly\",\"windrun\":51.06,\"version\":\"10.37S\",\"build\":\"114\",\"ver\":\"10\"}","payloadType":"json","x":190,"y":160,"wires":[["4da8961e.a623e"]]},{"id":"a18ffc2.ff459","type":"debug","z":"47d75961.f88b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":370,"y":260,"wires":[]},{"id":"4da8961e.a623e","type":"mqtt out","z":"47d75961.f88b6","name":"MQTT Out","topic":"MQTTout","qos":"0","retain":"false","broker":"f9f13036.e28b58","x":370,"y":160,"wires":[]},{"id":"6d2265db.acae74","type":"mqtt in","z":"47d75961.f88b6","name":"","topic":"MQTTout","qos":"0","datatype":"json","broker":"f9f13036.e28b58","x":180,"y":260,"wires":[["a18ffc2.ff459"]]},{"id":"f9f13036.e28b58","type":"mqtt-broker","name":"localhost","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Press the "Inject" button at the left in order to test.

A second thing I like to know, is the devices you want to use.
As you have seen some sensors can be combined
Do you want to combine or do you want separate sensors? Or both? Let me know.

Regards
edje1205
Posts: 34
Joined: Tuesday 20 December 2016 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Amsterdam Nieuwendam
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by edje1205 »

Hi @FireWizard

Thanks again for all the work ! Yes indeed I can imagine you're a bit confused. Fault by me !

This is the right output from my PWS weatherstation MQTTout.txt

Code: Select all

MQTTout:{"ClientID":"Nieuwendam","date":"15:29","dateFormat":"d/m/y","temp":4.2,"tempTL":1.1,"tempTH":4.2,"intemp":17.6,"dew":3.3,"dewpointTL":0.5,"dewpointTH":3.4,"apptemp":3.2,"apptempTL":-1.4,"apptempTH":4.8,"wchill":4.2,"wchillTL":-2.4,"heatindex":4.2,"heatindexTH":4.2,"humidex":2.9,"wlatest":0.0,"wspeed":0.0,"wgust":0.5,"wgustTM":5.1,"bearing":24,"avgbearing":24,"press":1003.6,"pressTL":1000.2 ,"pressTH":1003.6 ,"pressL":812.0,"pressH":1046.9,"rfall":  0.0,"rrate":0.00,"rrateTM":0.0,"hum":94,"humTL":94,"humTH":97,"inhum":48,"SensorContactLost":"0","forecast":"Meest bewolkt en koeler. Binnen 12 uur neerslag mogelijk, mogelijk met zware buien. Winderig.","tempunit":"C","windunit":"m/s","pressunit":"hPa","rainunit":"mm","temptrend":"+0.0","TtempTL":"08:28","TtempTH":"14:32","TdewpointTL":"08:28","TdewpointTH":"11:45","TapptempTL":"00:41","TapptempTH":"14:37","TwchillTL":"14:32","TheatindexTH":"14:32","TrrateTM":"00:00","ThourlyrainTH":"","LastRainTipISO":"7/12/2020 15:14","hourlyrainTH":0.0,"raintoday":  0.0,"ThumTL":"13:13","ThumTH":"09:12","TpressTL":"00:00","TpressTH":"15:24","presstrendval":"+0.4","Tbeaufort":4,"TwgustTM":"00:41","windTM":3.6,"bearingTM":186,"timeUTC":"2020,12,08,14,29,52","BearingRangeFrom10":24,"BearingRangeTo10":24,"UV":0.0,"UVTH":0.0,"SolarRad":16,"CurrentSolarMax":43,"SolarTM":111,"domwinddir":"Southeasterly","windrun":35.40,"version":"10.37S","build":"114","ver":"10"}
wspeed and avgbearing I mentioned in bold as highlight to show. It's not as in MQTTout.txt

In the meanwhile I now have 'wspeed' in a sensor as windspeed from my weatherstation in m/s. I can work with that.

Last struggle is wind direction were I found on internet 2 scripts

f1) an extract function in nodered as:

Code: Select all

var avgbearing = msg.payload.avgbearing
msg.payload = {"command":"udevice","idx":605,"svalue":  msg.payload.avgbearing.toString()};
return msg;
that give me a value of winddirection in numbers but I want text !:

Code: Select all

2020-12-08 15:44:57.230 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":605,"svalue":"24"}


were 24 is the wind direction from that moment, but I need the words (east west etc)



To get that I found next decode function:

Code: Select all

var richting = msg.payload.avgbearing;
var text = "Onbekend";
if (richting >= 0 && richting <= 10){
   text = "Noord";
}
if (richting >= 11 && richting <= 30){
   text = "NoordNoordOost";
}
if (richting >= 31 && richting <= 54){
   text = "NoordOost";
}
if (richting >= 55 && richting <= 79){
   text = "OostNoordOost";
}
if (richting >= 80 && richting <= 101){
   text = "Oost";
}
if (richting >= 102 && richting <= 120){
   text = "OostZuidOost";
}
if (richting >= 121 && richting <= 141){
   text = "ZuidOost";
}
if (richting >= 142 && richting <= 164){
   text = "ZuidZuidOost";
}
if (richting >= 165 && richting <= 190){
   text = "Zuid";
}
if (richting >= 191 && richting <= 211){
   text = "ZuidZuidWest";
}
if (richting >= 212 && richting <= 235){
   text = "ZuidWest";
}
if (richting >= 236 && richting <= 259){
   text = "WestZuidWest";
}
if (richting >= 260 && richting <= 285){
   text = "West";
}
if (richting >= 285 && richting <= 310){
   text = "WestNoordWest";
}
if (richting >= 310 && richting <= 327){
   text = "NoordWest";
}
if (richting >= 328 && richting <= 348){
   text = "NoordNoordWest";
}
if (richting >= 348 && richting <= 360){
   text = "Noord";
}
msg.payload = {"command":"udevice","idx":605,"stype" :"Text","svalue":msg.payload.avgbearing.toString()};
return {payload:text,richting};

output log of Domoticz then is

Code: Select all

2020-12-08 15:48:30.368 MQTT: Topic: domoticz/in, Message: NoordNoordOost
idx ??

Hurray this is what I need as text in my sensor, but there is no idx in it so Domoticz doesn't know were to send to
I made a text sensor IDX:605 but nothing shows up only "24"

Any suggestions ?
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by FireWizard »

Hi, @edje1205,

As I noticed that more users have difficulties to send data, received by e.g. MQTT or a HTTP request from Node Red to Domoticz, I have decided to make a kind of model. As not all weather stations present the same format and not all type of sensors are present the input may vary.

Domoticz supports the following weather sensors:

1. Temperature (will be presented under the Temperature tab).
2. Humidity (will be presented under the Temperature tab).
3. Barometer (will be presented under the Weather tab).
4. Combined sensors Temperature and Humidity (will be presented under the Temperature tab).
5. Combined sensors Temperature and Humidity and Barometer (will be presented under the Temperature tab AND under the Weather tab).
6. Combined sensors Temperature and Barometer (will be presented under the Temperature tab AND under the Weather tab).
7. Rain (will be presented under the Weather tab).
8. Wind (will be presented under the Weather tab).
9. Combined sensors Wind and Temperature and Chill (will be presented under the Temperature tab AND under the Weather tab).
10. UV (will be presented under the Weather tab).
11. Solar radiation (will be presented under the Weather tab).

As extra I have also included:
12. Text sensor (will be presented under the Utility tab).
13. Custom sensor (will be presented under the Utility tab).

Temperature tab

Screenshot_weather_temp.png
Screenshot_weather_temp.png (243.49 KiB) Viewed 5134 times

Weather

Screenshot_weather_weather.png
Screenshot_weather_weather.png (367.86 KiB) Viewed 5134 times

Utility

Screenshot_weather_utility.png
Screenshot_weather_utility.png (115.41 KiB) Viewed 5134 times

As an example we will use the following data, received from weatherstation Davis Vantage Pro 2.0 and weather program WeatherDisplay. (from developer Brian Hamilton)

Code: Select all

MQTTout : msg.payload : Object
object
ClientID: "Nieuwendam"
date: "15:29"
dateFormat: "d/m/y"
temp: 4.2
tempTL: 1.1
tempTH: 4.2
intemp: 17.6
dew: 3.3
dewpointTL: 0.5
dewpointTH: 3.4
apptemp: 3.2
apptempTL: -1.4
apptempTH: 4.8
wchill: 4.2
wchillTL: -2.4
heatindex: 4.2
heatindexTH: 4.2
humidex: 2.9
wlatest: 0
wspeed: 0
wgust: 0.5
wgustTM: 5.1
bearing: 24
avgbearing: 24
press: 1003.6
pressTL: 1000.2
pressTH: 1003.6
pressL: 812
pressH: 1046.9
rfall: 0
rrate: 0
rrateTM: 0
hum: 94
humTL: 94
humTH: 97
inhum: 48
SensorContactLost: "0"
forecast: "Meest bewolkt en koeler. Binnen 12 uur neerslag mogelijk, mogelijk met zware buien. Winderig."
tempunit: "C"
windunit: "m/s"
pressunit: "hPa"
rainunit: "mm"
temptrend: "+0.0"
TtempTL: "08:28"
TtempTH: "14:32"
TdewpointTL: "08:28"
TdewpointTH: "11:45"
TapptempTL: "00:41"
TapptempTH: "14:37"
TwchillTL: "14:32"
TheatindexTH: "14:32"
TrrateTM: "00:00"
ThourlyrainTH: ""
LastRainTipISO: "7/12/2020 15:14"
hourlyrainTH: 0
raintoday: 0
ThumTL: "13:13"
ThumTH: "09:12"
TpressTL: "00:00"
TpressTH: "15:24"
presstrendval: "+0.4"
Tbeaufort: 4
TwgustTM: "00:41"
windTM: 3.6
bearingTM: 186
timeUTC: "2020,12,08,14,29,52"
BearingRangeFrom10: 24
BearingRangeTo10: 24
UV: 0
UVTH: 0
SolarRad: 16
CurrentSolarMax: 43
SolarTM: 111
domwinddir: "Southeasterly"
windrun: 35.4
version: "10.37S"
build: "114"
ver: "10"
The flow consists of a simple MQTT input node. In this example the topic MQTTout is used.
The total payload is send to a "Function" node and from there to a MQTT output node.
This node has the topic domoticz/in.

The contents of the "Function" node is as follows:

Code: Select all

// This function sorts the comfort level for Domoticz based on the humidity.

function comfortlevel(hum) {
    
switch (true) {
    case hum > 70: { hum_stat = 3 } break;
    case hum < 30: { hum_stat = 2 } break;
    case hum >= 30 && hum <= 45: { hum_stat = 0 } break;
    case hum > 45 && hum <= 70: { hum_stat = 1 } break;
    default: { hum_stat = 0 } break;
}
return hum_stat;
}

// This function sorts the prediction (barometer forecast) for Domoticz based on the barometer pressure.

function bar_forecast(pres) {

switch (true) {
    case pres > 1030: { bar_for = 1 } break;
    case pres > 1010 && pres <= 1030: { bar_for = 2 } break;
    case pres > 990 && pres <= 1010: { bar_for = 3 } break;
    case pres > 970 && pres <= 990: { bar_for = 4 } break;
    default: { bar_for = 0 } break;
}
return bar_for;
}

// This function sorts the wind direction in abbreviated text for Domoticz based on the average bearing.

function winddir(avgb) {

switch (true) {
    case avgb >= 0 && avgb <= 11.25: { dir = "N" } break;
    case avgb >= 11.26 && avgb <= 33.75: { dir = "NNE" } break;
    case avgb >= 33.76 && avgb <= 56.25: { dir = "NE" } break;
    case avgb >= 56.26 && avgb <= 78.75: { dir = "ENE" } break;
    case avgb >= 78.76 && avgb <= 101.25: { dir = "E" } break;
    case avgb >= 101.26 && avgb <= 123.75: { dir = "ESE" } break;
    case avgb >= 123.76 && avgb <= 146.25: { dir = "SE" } break;
    case avgb >= 146.26 && avgb <= 168.75: { dir = "SSE" } break;
    case avgb >= 168.76 && avgb <= 191.25: { dir = "S" } break;
    case avgb >= 191.26 && avgb <= 213.75: { dir = "SSW" } break;
    case avgb >= 213.76 && avgb <= 236.25: { dir = "SW" } break;
    case avgb >= 236.26 && avgb <= 258.75: { dir = "WSW" } break;
    case avgb >= 258.76 && avgb <= 281.25: { dir = "W" } break;
    case avgb >= 281.26 && avgb <= 303.75: { dir = "WNW" } break;
    case avgb >= 303.76 && avgb <= 326.25: { dir = "NW" } break;
    case avgb >= 326.26 && avgb <= 348.75: { dir = "NNW" } break;
    case avgb >= 348.76 && avgb <= 359.99: { dir = "N" } break;
    default: { dir = "?" } break;
}
return dir;
}

var ba = msg.payload.press.toString(); //barometer pressure
var pr = bar_forecast(ba).toString(); // prediction (barometer forecast)
var tm = msg.payload.temp.toString(); // temperature
var hu = msg.payload.hum.toString(); // humidity
var lv = comfortlevel(hu).toString(); // comfort level
var rt = msg.payload.rrate.toString(); // rain rate
var fl = msg.payload.rfall.toString(); // rain fall
var sr = msg.payload.SolarRad.toString(); // solar radiation
var uv = msg.payload.UV.toString(); // UV radiation
var an = msg.payload.bearing.toString(); // wind bearing
var sp = (msg.payload.wspeed * 10).toString(); // wind speed in 0.1 m/s
var gu = (msg.payload.wgust * 10).toString(); // wind gust in 0.1 m/s
var ch = msg.payload.wchill.toString(); // chill temperature
var avgbr = msg.payload.avgbearing; // average bearing
var dr = winddir(avgbr); // wind direction in abbreviated text
var txt = msg.payload.forecast; // weather forecast
var dp = msg.payload.dew.toString(); // dew point

var msg1 = {};
var msg2 = {};
var msg3 = {};
var msg4 = {};
var msg5 = {};
var msg6 = {};
var msg7 = {};
var msg8 = {};
var msg9 = {};
var msg10 = {};
var msg11 = {};
var msg12 = {};
var msg13 = {};

msg1.payload = {"command":"udevice", "idx":30, "svalue":tm};
msg2.payload = {"command":"udevice", "idx":31, "nvalue":parseInt(hu), "svalue":lv};
msg3.payload = {"command":"udevice", "idx":32, "svalue":ba + ";" + pr};
msg4.payload = {"command":"udevice", "idx":33, "svalue":tm + ";" + hu + ";" + lv};
msg5.payload = {"command":"udevice", "idx":34, "svalue":tm + ";" + hu + ";" + lv + ";" + ba + ";" + pr};
msg6.payload = {"command":"udevice", "idx":35, "svalue":tm + ";" + ba + ";" + pr};
msg7.payload = {"command":"udevice", "idx":36, "svalue":rt + ";" + fl};
msg8.payload = {"command":"udevice", "idx":37, "svalue":an + ";" + dr + ";" + sp + ";" + gu + ";" + tm + ";" + ch};
msg9.payload = {"command":"udevice", "idx":38, "svalue":an + ";" + dr + ";" + sp + ";" + gu + ";" + tm + ";" + ch};
msg10.payload = {"command":"udevice", "idx":39, "svalue":uv + ";" + "0"};
msg11.payload = {"command":"udevice", "idx":40, "svalue":sr};
msg12.payload = {"command":"udevice", "idx":41, "svalue":txt};
msg13.payload = {"command":"udevice", "idx":42, "svalue":dp};

return [[msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9,msg10,msg11,msg12,msg13]];
The code consist of different parts.

1. As we need some parameters, which are not available in the received payload from the weather station we have to calculate these ourselves.
Therefore we will find 3 functions called comfortlevel, bar_forecast and winddir.
This functions are based on received parameters, like humidity for the comfort-level and bar (pressure) for the prediction (bar forecast).
The texts for the wind directions are based on the average bearing. If this is not available to current bearing must be used.
These texts can be changed to your local language. Do not use full text, but use abbreviations. (So NNE instead of Northnortheast)
These texts are to long and the sensor text does not fit nicely.
This part you will find from line 1 to 54.

2. As we want to send data to the different sensors, created in Domoticz we need some variables.
The majority of the variables are named after the variables used in: https://piandmore.wordpress.com/2019/02 ... -domoticz/
These variables are introduced in order to avoid long, and there difficult to read, lines in the final command.
If variables are not available or not used, you can comment these out.09 Dec 2020, 16:57
This part you will find from line 56 to 72.

3. As we want to send more than 1 message from this "Function" node, we have declared 13 msg objects, called msg1 to msg13.
If you do not use some sensors, as they are not available or not preferred, you can comment these out.
This part you will find from line 74 to 86.

4. The different message objects are created, according to the syntax found at: https://www.domoticz.com/wiki/Domoticz_ ... .2Fsensors
These syntax can not be changed, nor you can create your own sensors.
If you do not use some sensors, as they are not available or not preferred, you can comment these out.
This part you will find from line 88 to 100.

5. The output payload you will find at line 102.
If you do not use some sensors, as they are not available or not preferred, you should remove the corresponding msg* between the double square brackets [[ ]].

Do not forget to replace the Domoticz IDX numbers with your IDX numbers.
You will find these in lines 88-100 (indexes 30-42)

The complete Node Red flow, including 2 "Debug nodes"you will find below:

Code: Select all

[{"id":"a18ffc2.ff459","type":"debug","z":"47d75961.f88b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":220,"wires":[]},{"id":"6d2265db.acae74","type":"mqtt in","z":"47d75961.f88b6","name":"MQTTout In","topic":"MQTTout","qos":"0","datatype":"json","broker":"f9f13036.e28b58","x":170,"y":260,"wires":[["f30d5e0e.6c1a58","e7b054b8.b89c2"]]},{"id":"f30d5e0e.6c1a58","type":"function","z":"47d75961.f88b6","name":"","func":"// This function sorts the comfort level for Domoticz based on the humidity.\n\nfunction comfortlevel(hum) {\n    \nswitch (true) {\n    case hum > 70: { hum_stat = 3 } break;\n    case hum < 30: { hum_stat = 2 } break;\n    case hum >= 30 && hum <= 45: { hum_stat = 0 } break;\n    case hum > 45 && avgb <= 70: { hum_stat = 1 } break;\n    default: { hum_stat = 0 } break;\n}\nreturn hum_stat;\n}\n\n// This function sorts the prediction (barometer forecast) for Domoticz based on the barometer pressure.\n\nfunction bar_forecast(pres) {\n\nswitch (true) {\n    case pres > 1030: { bar_for = 1 } break;\n    case pres > 1010 && pres <= 1030: { bar_for = 2 } break;\n    case pres > 990 && pres <= 1010: { bar_for = 3 } break;\n    case pres > 970 && avgb <= 990: { bar_for = 4 } break;\n    default: { bar_for = 0 } break;\n}\nreturn bar_for;\n}\n\n// This function sorts the wind direction in abbreviated text for Domoticz based on the average bearing.\n\nfunction winddir(avgb) {\n\nswitch (true) {\n    case avgb >= 0 && avgb <= 11.25: { dir = \"N\" } break;\n    case avgb >= 11.26 && avgb <= 33.75: { dir = \"NNE\" } break;\n    case avgb >= 33.76 && avgb <= 56.25: { dir = \"NE\" } break;\n    case avgb >= 56.26 && avgb <= 78.75: { dir = \"ENE\" } break;\n    case avgb >= 78.76 && avgb <= 101.25: { dir = \"E\" } break;\n    case avgb >= 101.26 && avgb <= 123.75: { dir = \"ESE\" } break;\n    case avgb >= 123.76 && avgb <= 146.25: { dir = \"SE\" } break;\n    case avgb >= 146.26 && avgb <= 168.75: { dir = \"SSE\" } break;\n    case avgb >= 168.76 && avgb <= 191.25: { dir = \"S\" } break;\n    case avgb >= 191.26 && avgb <= 213.75: { dir = \"SSW\" } break;\n    case avgb >= 213.76 && avgb <= 236.25: { dir = \"SW\" } break;\n    case avgb >= 236.26 && avgb <= 258.75: { dir = \"WSW\" } break;\n    case avgb >= 258.76 && avgb <= 281.25: { dir = \"W\" } break;\n    case avgb >= 281.26 && avgb <= 303.75: { dir = \"WNW\" } break;\n    case avgb >= 303.76 && avgb <= 326.25: { dir = \"NW\" } break;\n    case avgb >= 326.26 && avgb <= 348.75: { dir = \"NNW\" } break;\n    case avgb >= 348.76 && avgb <= 359.99: { dir = \"N\" } break;\n    default: { dir = \"?\" } break;\n}\nreturn dir;\n}\n\nvar ba = msg.payload.press.toString(); //barometer pressure\nvar pr = bar_forecast(ba).toString(); // prediction (barometer forecast)\nvar tm = msg.payload.temp.toString(); // temperature\nvar hu = msg.payload.hum.toString(); // humidity\nvar lv = comfortlevel(hu).toString(); // comfort level\nvar rt = msg.payload.rrate.toString(); // rain rate\nvar fl = msg.payload.rfall.toString(); // rain fall\nvar sr = msg.payload.SolarRad.toString(); // solar radiation\nvar uv = msg.payload.UV.toString(); // UV radiation\nvar an = msg.payload.bearing.toString(); // wind bearing\nvar sp = (msg.payload.wspeed * 10).toString(); // wind speed in 0.1 m/s\nvar gu = (msg.payload.wgust * 10).toString(); // wind gust in 0.1 m/s\nvar ch = msg.payload.wchill.toString(); // chill temperature\nvar avgbr = msg.payload.avgbearing; // average bearing\nvar dr = winddir(avgbr); // wind direction in abbreviated text\nvar txt = msg.payload.forecast; // weather forecast\nvar dp = msg.payload.dew.toString(); // dew point\n\nvar msg1 = {};\nvar msg2 = {};\nvar msg3 = {};\nvar msg4 = {};\nvar msg5 = {};\nvar msg6 = {};\nvar msg7 = {};\nvar msg8 = {};\nvar msg9 = {};\nvar msg10 = {};\nvar msg11 = {};\nvar msg12 = {};\nvar msg13 = {};\n\nmsg1.payload = {\"command\":\"udevice\", \"idx\":30, \"svalue\":tm};\nmsg2.payload = {\"command\":\"udevice\", \"idx\":31, \"nvalue\":parseInt(hu), \"svalue\":lv};\nmsg3.payload = {\"command\":\"udevice\", \"idx\":32, \"svalue\":ba + \";\" + pr};\nmsg4.payload = {\"command\":\"udevice\", \"idx\":33, \"svalue\":tm + \";\" + hu + \";\" + lv};\nmsg5.payload = {\"command\":\"udevice\", \"idx\":34, \"svalue\":tm + \";\" + hu + \";\" + lv + \";\" + ba + \";\" + pr};\nmsg6.payload = {\"command\":\"udevice\", \"idx\":35, \"svalue\":tm + \";\" + ba + \";\" + pr};\nmsg7.payload = {\"command\":\"udevice\", \"idx\":36, \"svalue\":rt + \";\" + fl};\nmsg8.payload = {\"command\":\"udevice\", \"idx\":37, \"svalue\":an + \";\" + dr + \";\" + sp + \";\" + gu + \";\" + tm + \";\" + ch};\nmsg9.payload = {\"command\":\"udevice\", \"idx\":38, \"svalue\":an + \";\" + dr + \";\" + sp + \";\" + gu + \";\" + tm + \";\" + ch};\nmsg10.payload = {\"command\":\"udevice\", \"idx\":39, \"svalue\":uv + \";\" + \"0\"};\nmsg11.payload = {\"command\":\"udevice\", \"idx\":40, \"svalue\":sr};\nmsg12.payload = {\"command\":\"udevice\", \"idx\":41, \"svalue\":txt};\nmsg13.payload = {\"command\":\"udevice\", \"idx\":42, \"svalue\":dp};\n\nreturn [[msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9,msg10,msg11,msg12,msg13]];\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":260,"wires":[["a18ffc2.ff459","c2547ec1.bd1aa"]]},{"id":"c2547ec1.bd1aa","type":"mqtt out","z":"47d75961.f88b6","name":"Domoticz In","topic":"domoticz/in","qos":"0","retain":"false","broker":"f9f13036.e28b58","x":550,"y":260,"wires":[]},{"id":"e7b054b8.b89c2","type":"debug","z":"47d75961.f88b6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":370,"y":320,"wires":[]},{"id":"f9f13036.e28b58","type":"mqtt-broker","name":"localhost","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Regards
Last edited by FireWizard on Thursday 19 October 2023 21:38, edited 5 times in total.
edje1205
Posts: 34
Joined: Tuesday 20 December 2016 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Amsterdam Nieuwendam
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by edje1205 »

@FireWizard !!

Sorry for a late reply but: you made my day !, week!, months! !!! So long strugling and this was the solution at all.
Had to change only idx because of existing ones but after that 'appeltje, eitje' as we say.

Amazing !

Some questions:

Code: Select all

msg8.payload = {"command":"udevice", "idx":612, "svalue":an + ";" + dr + ";" + sp + ";" + gu + ";" + tm + ";" + ch};
msg9.payload = {"command":"udevice", "idx":613, "svalue":an + ";" + dr + ";" + sp + ";" + gu + ";" + tm + ";" + ch};
what's the difference between those ?
can I use msg9.payload for only gust (+gu) I tried with

Code: Select all

msg9.payload = {"command":"udevice", "idx":613, "svalue":dr + ";" + sp + ";" + gu};
but gives error / no value
or how to destilate only 'gust' for a sensor ?

and (but very small issue)

Code: Select all

var dp = msg.payload.dew.toString(); // dew point
gives value in a 'temp' and 'custom' sensor and zero (0) in the original dew sensor from domoticz:

Code: Select all

14-12-2020 12:04:25node: df461126.8efed
msg.payload : Object
{ command: "udevice", idx: 639, svalue: "10.1" }
(see att.)


Thanks so much again, no more headaches/sleepless nights ;-)
Attachments
dew zero.jpg
dew zero.jpg (10.52 KiB) Viewed 5100 times
dew value temp.jpg
dew value temp.jpg (9.23 KiB) Viewed 5100 times
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by FireWizard »

HI, @edje1205

It's nice that it is working, as you expected.

To answer your questions.
msg8.payload = {"command":"udevice", "idx":612, "svalue":an + ";" + dr + ";" + sp + ";" + gu + ";" + tm + ";" + ch};
msg9.payload = {"command":"udevice", "idx":613, "svalue":an + ";" + dr + ";" + sp + ";" + gu + ";" + tm + ";" + ch};

what's the difference between those ?
As you already noticed, the commands are exactly identical. However the difference is the virtual sensor, to which this data is sent to.

msg8 is sent to a sensor of the type "Wind", while
msg9 is sent to a sensor of type "Wind+Temperature+Chill"
You will see this at: https://piandmore.wordpress.com/2019/02 ... -domoticz/
The wind+temperature+chill sensor uses the same command as the wind sensor except in this case the tm (temperature, you can not use digits after the decimal) and ch (chill temperature, you can not use digits after the decimal) are shown.
Contrary with what has been written above, you can use digits after the decimal for both temperature and chill.

See below:

Screenshot_Wind_sensor.png
Screenshot_Wind_sensor.png (79.06 KiB) Viewed 5077 times
I created all possible (weather) sensors and populated them with the correct command.
can I use msg9.payload for only gust (+gu) I tried with
No, you cannot. You can only use the sensors, which are in the list in Domoticz.

See the wiki and that other link.

So, if you want to create a sensor, that is not known in Domoticz, you have to choose a "Custom" sensor.
So e.g "Gust" you create a "Custom" Sensor, with the name e.g. "Gust" and for x-axis you fill in m/s.
The disadvantage, in this case, is that the sensor will appear under the "Utility" tab.

So, a sensor, that you want to populate with:
msg9.payload = {"command":"udevice", "idx":613, "svalue":dr + ";" + sp + ";" + gu};
does not exist.
var dp = msg.payload.dew.toString(); // dew point

gives value in a 'temp' and 'custom' sensor and zero (0) in the original dew sensor from domoticz:
{ command: "udevice", idx: 639, svalue: "10.1" }
The first sensor, you show is a sensor of type "Leaf wetness
Leaf wetness

The leaf wetness sensor will show the leaf wetness. You can only send whole numbers.

{"command":"udevice", "idx":1234, "nvalue":34}
If you look to the command the numerical value should be in nvalue and not svalue.

So your command has to be: { command: "udevice", idx: 639, nvalue: parseInt(10.1) }

Be aware that the number is a whole number.

I hope this answers your questions.

Regards
edje1205
Posts: 34
Joined: Tuesday 20 December 2016 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Amsterdam Nieuwendam
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by edje1205 »

Hi @Firewizard



Now I know the 'trick' and understand a little more of node-red I have them all on my wanted Frontpage (see att) including co2 sensor ppm
real WOW !

Last question (I suppose ;-))

with this

Code: Select all

msg15.payload = { command: "udevice", idx: 639, nvalue: parseInt(10.1) };
dew sensor always keeps on '10' while a custom sernsor has the value (see att)
if no value in

Code: Select all

parseInt(10.1)
sensor keeps empty

how to get the value in official 'dew'sensor from domoticz ?

Thanks again for help !
Have nice days !
Attachments
dew dauwpunt.jpg
dew dauwpunt.jpg (19.38 KiB) Viewed 5020 times
frontpage.jpg
frontpage.jpg (80.17 KiB) Viewed 5020 times
User avatar
FireWizard
Posts: 1863
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: MQTT values Node-Red to Domoticz values

Post by FireWizard »

Hi, @edje1205
with this

Code:

Code: Select all

msg15.payload = { command: "udevice", idx: 639, nvalue: parseInt(10.1) };
dew sensor always keeps on '10' while a custom sernsor has the value (see att)
if no value in
I assume, that the sensor with IDX 639 is the "Leaf Wetness" sensor (called "Dew")
This sensor is populated by msg15.command with a fixed value of 10 (parseInt(10.1)

The Custom Sensor, which I created as an example of msg13,payload, looks like:
msg13.payload = {"command":"udevice", "idx":42, "svalue":dp};
Feel free to replace dp with msg.payload.dew.toString().

Be aware, that in case of the "Leaf wetness" sensor you have to send the numerical value as nvalue, while in case of a custom sensor, you have to send the value as a string to svalue.
The custom sensor in Domoticz accepts decimals, while the leaf wetness sensor does not accept decimals (therefore we us parseInt)

So if you want to have the dew point in the leaf wetness sensor, you should send:

Code: Select all

msg15.payload = { command: "udevice", idx: 639, nvalue: parseInt(dp) };
or

Code: Select all

msg15.payload = { command: "udevice", idx: 639, nvalue: parseInt (msg.payload.dew) }; 
Something else.

I'm not a biological specialist, a specialist in plant diseases or a meteorological specialist, but I think that the dew point is not the same as leaf wetness . You call it the official dew sensor of Domoticz, but I do not believe that was the intention.

From Wikipedia:
The dew point is the temperature to which air must be cooled to become saturated with water vapor. When cooled further, the airborne water vapor will condense to form liquid water (dew). When air cools to its dew point through contact with a surface that is colder than the air, water will condense on the surface.
So this is a "Temperature".
Leaf wetness is a meteorological parameter that describes the amount of dew and precipitation left on surfaces. It is used for monitoring leaf moisture for agricultural purposes, such as fungus and disease control, for control of irrigation systems, and for detection of fog and dew conditions, and early detection of rainfall.
Leaf wetness duration is mostly measured 2m above the ground.
The Unit: ‘minutes per hour’.

It is up to you, of course, if you want to misuse the "leaf wetness" sensor for the dew point.

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest