LUA-script for updating sensors by MQTT
Moderator: leecollings
-
- Posts: 14
- Joined: Friday 31 May 2019 11:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.11352
- Contact:
LUA-script for updating sensors by MQTT
I use both Home Assistant and Domoticz. Not all Xiaomi plant sensors can be reached from Domoticz. So I want to use the HA, which is in a different place to make the last 2 sensors also available in Domoticz. For this I use Node Red and MQTT. I get the data in the Pi on which Domoticz is running. I only know too little about the technology to update the devices in Domoticz with the value of the sensors. Does anyone have an idea? Can you do that with a "simple" Lua-script. I have a separate message 'Dracena' and 'Palm' for both sensors.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: LUA-script for updating sensors by MQTT
Domoticz can be set to listen to MQTT topic "domoticz/in" already so it could be that you don't need another script.
What type / subtype are the domoticz devices ? Which information do you already send to the PI and how ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 14
- Joined: Friday 31 May 2019 11:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.11352
- Contact:
Re: LUA-script for updating sensors by MQTT
At this time, only the value of the sensor indicating the percentage of humidity. For this purpose I created a device (from hardware dummy) of type general, percentage (humidity).
Once this works, I want to use more, because I've discovered that with the addition 'Nora' to Node-red, I can also use Google Assistant without having to switch to Controlz.
For everyone who is also interested, here's the link:
https://flows.nodered.org/node/node-red-contrib-nora .
Please share interesting experiences here on the forum.
Once this works, I want to use more, because I've discovered that with the addition 'Nora' to Node-red, I can also use Google Assistant without having to switch to Controlz.
For everyone who is also interested, here's the link:
https://flows.nodered.org/node/node-red-contrib-nora .
Please share interesting experiences here on the forum.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: LUA-script for updating sensors by MQTT
Please find the wiki on how to add MQTT to domoticz
For virtual device humidity the command to send to domoticz is:
Code: Select all
mosquitto_pub -m '{"idx":45,"nvalue":53,"svalue":"3","Battery":66}' -t domoticz/in
Code: Select all
mosquitto_pub -m '{"idx":46,"nvalue":0,"svalue":"53"}' -t domoticz/in
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 14
- Joined: Friday 31 May 2019 11:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.11352
- Contact:
Re: LUA-script for updating sensors by MQTT
Maybe this helps someone to give me clues. I've downloaded the source from Node-Red. Please notice that there is still an ERROR in this code. I want the actual message (namely the correct humility) to be in the message sent to Domoticz to adjust the value. I already discovered that Node-Red is very powerful once you know how to deal with it.
To use the above. Copy it and use the import-function of Node-Red. It will deliver my flow in a useful and readable form.
Code: Select all
[{"id":"67fa066b.31251","type":"mqtt out","z":"75ef81a3.3f27a","name":"","topic":"domoticz/in","qos":"2","retain":"true","broker":"51489f0e.3dc0e","x":590,"y":100,"wires":[]},{"id":"51489f0e.3dc0e","type":"mqtt-broker","z":"","name":"","broker":"192.168.0.130","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: LUA-script for updating sensors by MQTT
Hi,
I do not want to interfere, with the good support waaren is trying to give you, but we need more info.
The code you posted is not a flow, but actually only a MQTT output node, configured for domoticz/in, including its (hidden) configuration node.
In order to make it work, you have to create a input to that MQTT output node, containing exactly the data for humidity and percentage with the syntax, as shown in waarens post. Probably, you will need some kind of conversion.
Therefore can you tell us, how your devices provide the data and how that data looks like.
I suggest that you install the following node in node-red: https://flows.nodered.org/node/node-red ... xiaomi-ble.
This node can hopefully import the desired data into node-red.
Connect a debug node to that xiaomi node and check the result in the debug pane.
[Edit] Look also here: https://flows.nodered.org/flow/b1af1d00 ... f025d33feb
Is it published at /home/miflora?
Regards
I do not want to interfere, with the good support waaren is trying to give you, but we need more info.
The code you posted is not a flow, but actually only a MQTT output node, configured for domoticz/in, including its (hidden) configuration node.
In order to make it work, you have to create a input to that MQTT output node, containing exactly the data for humidity and percentage with the syntax, as shown in waarens post. Probably, you will need some kind of conversion.
Therefore can you tell us, how your devices provide the data and how that data looks like.
I suggest that you install the following node in node-red: https://flows.nodered.org/node/node-red ... xiaomi-ble.
This node can hopefully import the desired data into node-red.
Connect a debug node to that xiaomi node and check the result in the debug pane.
[Edit] Look also here: https://flows.nodered.org/flow/b1af1d00 ... f025d33feb
Is it published at /home/miflora?
Regards
-
- Posts: 14
- Joined: Friday 31 May 2019 11:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.11352
- Contact:
Re: LUA-script for updating sensors by MQTT
You're not getting the point. I almost got it working. When I use my own data domoticz gets updated. But until now I'm not able to get in the data from HA. Only because I don't know how to filter the value from the message from HA. I fill it know with idx, nvalue, and svalue. I can even update switches.
-
- Posts: 14
- Joined: Friday 31 May 2019 11:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.11352
- Contact:
Re: LUA-script for updating sensors by MQTT
I already solved it. I don't need LUA. It works perfectly within Node-Red. I only oversaw my mistake. This solves the problem in the function-node:
I had to save the data of msg.payload first in a local variable. After msg.payload the data is no longer available. I do can recommend Node-Red It opens a world to new opportunities
Code: Select all
var moist = msg.payload
msg.payload = {};
msg.payload.idx = 1036;
msg.payload.nvalue = 0;
msg.payload.svalue = moist;
return msg;
Who is online
Users browsing this forum: No registered users and 0 guests