sensor data from RFLink over MQTT to domoticz

Everything about esp8266 and more.

Moderator: leecollings

Post Reply
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

sensor data from RFLink over MQTT to domoticz

Post by hasselhoffer »

I have a setup with a RFLink gateway connected to an esp8266 that sends sensor values over mqtt to my mqtt broker.
The problem is that the mqtt messages sent by the esp8266 is not in correct format for Domoticz.
I have installed node red to have the posibility to change the format of the messages sent by the esp8266.
The problem is that I have no prior programming experience. I'm able to change the topic to domotics/in. When it comes to change the payload of the messages I get stuck.
I'm grateful for help.


original message
{"topic":"rflink/Oregon_TempHygro-128B8","payload":{"TEMP":15.4,"HUM":54,"HSTATUS":0,"BAT":"OK"},"qos":0,"retain":false,"_msgid":"07ef509422ae8d64"}

altered message
{"topic":"domoticz/in","payload":{"TEMP":15.4,"HUM":54,"HSTATUS":0,"BAT":"OK"},"qos":0,"retain":false,"_msgid":"07ef509422ae8d64"}

From what I have read the format is supposed to be like this:
{"command":"udevice", "idx":1234, "svalue":"tm;hu;lv;ba;pr"}
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: sensor data from RFLink over MQTT to domoticz

Post by waltervl »

Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: sensor data from RFLink over MQTT to domoticz

Post by FireWizard »

Hello @hasselhoffer

As I do not own such a device ESP6266 with a RFLink Gateway, I have created a simulation with an "Inject" node.

Just for this kind of questions I did create a kind of model, that I recommend to read.
See: viewtopic.php?f=28&t=34300&p=263147&hil ... re#p263147

In this case you receive as data (payload):
{"topic":"rflink/Oregon_TempHygro-128B8","payload":{"TEMP":15.4,"HUM":54,"HSTATUS":0,"BAT":"OK"},"qos":0,"retain":false,"_msgid":"07ef509422ae8d64"}
Let us evaluate

There are a Temperature and a Humidity value present. Beside that we have also a Humidity status, which I assume, correspondents with https://www.domoticz.com/wiki/Domoticz_ ... 2Fhumidity

Also we have some info about the Battery (currently OK)

This data may be sent to Domoticz as a value. See:
https://www.domoticz.com/wiki/Domoticz_ ... y_level.29
It is unknown, what the status means at the moment and what will be sent in case the capacity is reduced to, let's say, 50%.
So for the moment I ignore that value. All other data, including the topic, in the received payload may be ignored as well.

Screenshot_RFlink_MQTT.png
Screenshot_RFlink_MQTT.png (24.35 KiB) Viewed 1919 times

As we have only available the temperature, humidity and humidity status and not pressure and prediction, we should use: {"command":"udevice", "idx":1234, "svalue":"tm;hu;lv"} and not {"command":"udevice", "idx":1234, "svalue":"tm;hu;lv;ba;pr"}

For the conversion to Domoticz format, we use a "Function" node, with the following content:

Code: Select all

msg.payload = {"command":"udevice","idx":1234,"nvalue":0,"svalue":msg.payload.TEMP + ";" + msg.payload.HUM + ";" + msg.payload.HSTATUS}
return msg;
The flow will look as follows:

Screenshot_RFlink_MQTT2.png
Screenshot_RFlink_MQTT2.png (43.05 KiB) Viewed 1919 times

You can replace the second "Debug" node with a "MQTT Output" node. Configure that node with a topic domoticz/in, so that Domoticz will subscribe to it. Configure also the correct virtual sensor (Temperature + Humidity) and insert the corresponding IDX in the "Function" node.

The complete flow you will find below:

Code: Select all

[{"id":"100f0d01a219a15b","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"a75b5d19e50c5a5b","type":"inject","z":"100f0d01a219a15b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rflink/Oregon_TempHygro-128B8","payload":"{\"TEMP\":15.4,\"HUM\":54,\"HSTATUS\":0,\"BAT\":\"OK\"}","payloadType":"json","x":850,"y":100,"wires":[["34f5581651d07a45","93273e4a0ac3c47a"]]},{"id":"34f5581651d07a45","type":"debug","z":"100f0d01a219a15b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":60,"wires":[]},{"id":"93273e4a0ac3c47a","type":"function","z":"100f0d01a219a15b","name":"","func":"msg.payload = {\"command\":\"udevice\",\"idx\":1234,\"nvalue\":0,\"svalue\":msg.payload.TEMP + \";\" + msg.payload.HUM + \";\" + msg.payload.HSTATUS}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":100,"wires":[["8251db9ca3888d22"]]},{"id":"8251db9ca3888d22","type":"debug","z":"100f0d01a219a15b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":100,"wires":[]}]
Regards
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: sensor data from RFLink over MQTT to domoticz

Post by hasselhoffer »

Hi @FireWizard
I'm very grateful for all the help I get!
I have now tested the flow you created for me.
when I use the inject node you created my virtual sensor is updated in domoticz.
domoticz sensor 1.PNG
domoticz sensor 1.PNG (4.8 KiB) Viewed 1899 times
When i hook up the flow with mqtt data in I seem to get som kind of error after data has passed through the function node.
sfter function node.PNG
sfter function node.PNG (13.01 KiB) Viewed 1899 times
when I compare inject node with mqtt in they seem to differ a bit
compare mqtt in with inject node 3.PNG
compare mqtt in with inject node 3.PNG (16.52 KiB) Viewed 1899 times
To be able to understand what you actually do in the function node,is learning javascript the way to go?

regards
Markus
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: sensor data from RFLink over MQTT to domoticz

Post by FireWizard »

Hello @hasselhoffer,

I'm really sorry, that I did not mention the configuration of the MQTT Input node.

Can you change the Output in the Configuration of the MQTT input node to "a parsed JSON object", instead of "auto-detect (string or buffer)" as follows:

Screenshot_MQTT Input.png
Screenshot_MQTT Input.png (22.99 KiB) Viewed 1890 times
You asked also:
To be able to understand what you actually do in the function node,is learning javascript the way to go?
Of course knowing javascript is always an advantage, but as I should give a recommendation, I suggest you watch the movies, created by the developers of Node RED. This will costs you about 1 hour of your time, but you will learn so much.

See: https://www.youtube.com/channel/UCQaB8N ... A/featured

There are many more videos available, explaining a lot. (See the video tab in the link)

What I did in the "Function" node was not very fancy. I simple inserted the path of the different values TEMP, HUM and HStatus in the required payload for Domoticz ({"command":"udevice", "idx":1234, "svalue":"tm;hu;lv"}) You can find that path, without msg, when you hoover with your mouse over the element.

See: https://nodered.org/docs/user-guide/messages

Regards
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: sensor data from RFLink over MQTT to domoticz

Post by hasselhoffer »

Hi @FireWizard
Many thanks.
It works like a charm now, and I'm checking out both the user guide and the videos.
I think it is well spent time.

Regards
Markus
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest