MQTT to Domoticz
Moderators: leecollings, remb0
-
- Posts: 23
- Joined: Monday 19 December 2016 8:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Germany - Münsterland
- Contact:
MQTT to Domoticz
Hi Folks,
with less programming skills I'm totally lost with the explanations I found yet.
Can someone explain maybe step by step how I can get a MQTT-topic into Domoticz?
I have a watermeter publishing the total counterreading via MQTT, all is working fine. I can see the amount via Node red in the msg.payload/debug window inside Node red.
Now the last step, getting it into Domoticz, is my mountain that I can't climb.
Regards
Meikel
with less programming skills I'm totally lost with the explanations I found yet.
Can someone explain maybe step by step how I can get a MQTT-topic into Domoticz?
I have a watermeter publishing the total counterreading via MQTT, all is working fine. I can see the amount via Node red in the msg.payload/debug window inside Node red.
Now the last step, getting it into Domoticz, is my mountain that I can't climb.
Regards
Meikel
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: MQTT to Domoticz
Hi, @Busmeikel
Can you publish your flow or a screenshot of what you see in your "Debug" window?
Regards
Can you publish your flow or a screenshot of what you see in your "Debug" window?
Regards
-
- Posts: 23
- Joined: Monday 19 December 2016 8:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Germany - Münsterland
- Contact:
Re: MQTT to Domoticz
Hi FireWizard,
my "Debug" looks like that
It is the value in m³, published every 5 minutes. It would be fine to have that counter in Domoticz and also a function maybe "Liter per day" or something like that.
Thanks for your reply.
Meikel
my "Debug" looks like that
It is the value in m³, published every 5 minutes. It would be fine to have that counter in Domoticz and also a function maybe "Liter per day" or something like that.
Thanks for your reply.
Meikel
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: MQTT to Domoticz
Hello @Busmeikel
I assume that you have already Domoticz configured, so that Domoticz and the MQTT broker communicates.
If not, see: https://www.domoticz.com/wiki/MQTT
1. Create a new device in Domoticz ==> Hardware.
Type: Dummy (Does nothing, use for virtuals switches only)
2. Press "Create Virtual Sensors".
Select Sensor Type: "Counter" and give it a name (In this example I use "Water Usage")
3. Go to the device under the "Utility" tab.
Edit the device as follows:
Make a note of the Idx:. In this case it is 12.
For this type of device the following command is required:
(source: https://piandmore.wordpress.com/2019/02 ... -domoticz/)
The flow looks as follows:
The Function node "translates" the received input to the required Domoticz input.
The contents is as follows:
Brief explanation:
As you have seen above the Water sensor receives its value in the svalue variable.
But we have to calculate with the value.
1. The first function (parseFloat) converts the string ("131,638") to a Number.
2. This number is multiplied with 100
3. The result is formatted to 1 digit after the comma (toFixed(1))
4. This value is sent to Domoticz
See the "debug" part in the picture.
If everything is correct, you will see:
You asked:
If you have available a flow meting, you can also use the other sensor (Currently Red, as it receives no data)
Regards
I assume that you have already Domoticz configured, so that Domoticz and the MQTT broker communicates.
If not, see: https://www.domoticz.com/wiki/MQTT
1. Create a new device in Domoticz ==> Hardware.
Type: Dummy (Does nothing, use for virtuals switches only)
2. Press "Create Virtual Sensors".
Select Sensor Type: "Counter" and give it a name (In this example I use "Water Usage")
3. Go to the device under the "Utility" tab.
Edit the device as follows:
Make a note of the Idx:. In this case it is 12.
For this type of device the following command is required:
(source: https://piandmore.wordpress.com/2019/02 ... -domoticz/)
For water, the value, we have to upload is in 10L and so we have to multiply the received value with 100.Counter
The counter sensor will show usage. You can add digits after the decimal if needed. The main display will show it rounded of to 2 digits while beneath it, it will show the whole number you upload. For some reason the log shows the value for every hour and that value is the value at the start of the hour.
{"command":"udevice", "idx":1234, "svalue":"3.45"}
The tricky part is that the type of counter determines what number you should upload:
Energy, upload per Wh, displayed in kWh
Gas, upload per 0.01 m3, displayed in m3
Water, upload per 10 l, display in l (and in m3 below the main display)
Counter, upload per 1 something, also displayed in the same format
Energy generated, upload per Wh, displayed in kWh
The flow looks as follows:
The Function node "translates" the received input to the required Domoticz input.
The contents is as follows:
Code: Select all
msg.payload = {"command":"udevice", "idx":12, "svalue":(parseFloat(msg.payload) * 100).toFixed(1)}
return msg;
As you have seen above the Water sensor receives its value in the svalue variable.
But we have to calculate with the value.
1. The first function (parseFloat) converts the string ("131,638") to a Number.
2. This number is multiplied with 100
3. The result is formatted to 1 digit after the comma (toFixed(1))
4. This value is sent to Domoticz
See the "debug" part in the picture.
If everything is correct, you will see:
You asked:
The Liter per day, you will find in the Log files of the Sensor.It is the value in m³, published every 5 minutes. It would be fine to have that counter in Domoticz and also a function maybe "Liter per day" or something like that.
If you have available a flow meting, you can also use the other sensor (Currently Red, as it receives no data)
Regards
Last edited by FireWizard on Thursday 22 April 2021 19:49, edited 1 time in total.
-
- Posts: 23
- Joined: Monday 19 December 2016 8:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Germany - Münsterland
- Contact:
Re: MQTT to Domoticz
Okay,
everything done and Domoticz is now unreachable, ERR_CONNECTION_REFUSED. What happened?
Before I use my safety copy and everything is at point zero. What can I do to bring Domoticz back to life? Reboot and cold start with no effect.
everything done and Domoticz is now unreachable, ERR_CONNECTION_REFUSED. What happened?
Before I use my safety copy and everything is at point zero. What can I do to bring Domoticz back to life? Reboot and cold start with no effect.
-
- Posts: 23
- Joined: Monday 19 December 2016 8:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Germany - Münsterland
- Contact:
Re: MQTT to Domoticz
...RasPi is still alive, cleared Browsercache...
No idea...
No idea...
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: MQTT to Domoticz
@Busmeikel
Honestly I have no idea what has happened.
You followed exactly the steps? Used the same device?
And after you created the device, Domoticz has been working?
I can only think that because of an unexpected value the database has got corrupted?
Can you try to restore a previous database?
Honestly I have no idea what has happened.
You followed exactly the steps? Used the same device?
And after you created the device, Domoticz has been working?
I can only think that because of an unexpected value the database has got corrupted?
Can you try to restore a previous database?
-
- Posts: 23
- Joined: Monday 19 December 2016 8:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Germany - Münsterland
- Contact:
Re: MQTT to Domoticz
Hi,
after reactivating Domoticz with my safety copy and updating to 2021.1 system works now. But...
It is not clear for me how to configure the "MQTT To Domoticz"-Node, when I put in the same topic of "MQTT Out"
it lasts in a closed loop and I have to delete the node and restart Node red.
The multiplier from m³ to Liters is 1000
@FireWizard: Can you help with "MQTT To Domoticz"
Regards
Meikel
after reactivating Domoticz with my safety copy and updating to 2021.1 system works now. But...
It is not clear for me how to configure the "MQTT To Domoticz"-Node, when I put in the same topic of "MQTT Out"
it lasts in a closed loop and I have to delete the node and restart Node red.
The multiplier from m³ to Liters is 1000
@FireWizard: Can you help with "MQTT To Domoticz"
Regards
Meikel
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: MQTT to Domoticz
Hello @Busmeikel
because of MQTT input. So I was afraid of an erroneous input in the database.
First:
The requirements for water in the "Counter" are that we have to send the value in 10 L units.
See:
So let´s look to:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
I think it is easier to set the counter/divider in Domoticz: Setup ===> Settings ===> Meters/Counters ===> RFXMeter/Counter Dividers: ===> Water =1.
In this case we simple send the value of msg.payload to Domoticz.
This is, I think what you want:
Remember to change the idx number (currently 11) to the idx number of your "Water Usage" device!
You said:
The topic should be changed to the topic that Domoticz has subscribed to.
So that means that you have to publish to the same topic as you configured in Domoticz.
If you left the fields empty, you have to publish to domoticz/in.
So try it and let´s hope we have more success now.
Regards
Fortunately it works again. I broke almost my head, why this happened. It happened to me never before, that Domoticz crashed,after reactivating Domoticz with my safety copy and updating to 2021.1 system works now. But...
because of MQTT input. So I was afraid of an erroneous input in the database.
Sure I can.@FireWizard: Can you help with "MQTT To Domoticz"
First:
I fully agree, your correct, but that is not the multiplier we need in the "Function" node.The multiplier from m³ to Liters is 1000
The requirements for water in the "Counter" are that we have to send the value in 10 L units.
See:
But studying this issue, the data at piandmore may be outdated.Water, upload per 10 l, display in l (and in m3 below the main display)
So let´s look to:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
I think it is easier to set the counter/divider in Domoticz: Setup ===> Settings ===> Meters/Counters ===> RFXMeter/Counter Dividers: ===> Water =1.
In this case we simple send the value of msg.payload to Domoticz.
This is, I think what you want:
The contents of the "Function" node:When there is a counter created, there is a possibility to change the units by clicking on "Change" at the utility tab.
Energy (kWh)
Gas (m3)
Water (m3)
Counter (no unit)
The counter will be treated with the divider which is defined in the parameters in the application settings. For example if the counter is set to "Water" and the value is passed as liters, the divider must set to 1000 (as the unit is m3). The device displays 2 values:
The status is the overall total volume (or counter).
The volume (or counter) of the day (in the top right corner).
The today's volume (or counter) is calculated from the total volume (or counter).
Code: Select all
msg.payload = {"command":"udevice", "idx":11, "svalue":msg.payload}
return msg;
Yes, I can imagine that it is a loop, because you publish the same value to the same topic as you did subscribe to.@FireWizard: Can you help with "MQTT To Domoticz"
You said:
Your topic is "wasserzaehler/zaehlerstand ". If you publish the final value to that same topic, it will go into a loop.It is not clear for me how to configure the "MQTT To Domoticz"-Node, when I put in the same topic of "MQTT Out"
it lasts in a closed loop and I have to delete the node and restart Node red.
The topic should be changed to the topic that Domoticz has subscribed to.
So that means that you have to publish to the same topic as you configured in Domoticz.
If you left the fields empty, you have to publish to domoticz/in.
So try it and let´s hope we have more success now.
Regards
-
- Posts: 23
- Joined: Monday 19 December 2016 8:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Germany - Münsterland
- Contact:
Re: MQTT to Domoticz
Hi FireWizard,
live could be so easy when you know how something works.
Now it is working well and I can go further with the next steps.
Thank you very much
Meikel
live could be so easy when you know how something works.
Now it is working well and I can go further with the next steps.
Thank you very much
Meikel
-
- Posts: 10
- Joined: Thursday 04 June 2020 15:10
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.2
- Location: Subtropical Scandinavia (Fryslan)
- Contact:
Re: MQTT to Domoticz
Grrr it's getting frustrated
From NodeRed I want to send the daycount and the total count.
Somehow I only get or the daycount OR the total count.
Can someome help me with a correct msg.payload.svalue ??
My current msg.payload is: (value1 = daycount, value2 =total count
From NodeRed I want to send the daycount and the total count.
Somehow I only get or the daycount OR the total count.
Can someome help me with a correct msg.payload.svalue ??
My current msg.payload is: (value1 = daycount, value2 =total count
Code: Select all
value = parseInt(msg.payload.COUNTER.C1);
value2 = parseInt(global.get("WaterTotalCounter")/1000);
msg.payload={};
msg.payload.idx=134
msg.payload.svalue= (value).toString() + ";" + (value2).ToString();
return [msg];
- waltervl
- Posts: 5149
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: MQTT to Domoticz
If you use the standard counter device https://www.domoticz.com/wiki/Domoticz_ ... 7s#Counter then you can only sent a total counter value. Domoticz will calculate the daily value for you as you will send this multiple time per day.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 10
- Joined: Thursday 04 June 2020 15:10
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.2
- Location: Subtropical Scandinavia (Fryslan)
- Contact:
Re: MQTT to Domoticz
Okay. Thanks for the quick response.
But then again. On my previous sensor I had the offset filled in with the current state of the water meter. But every new day, the day counter was reset and my total count was the offset data. So not an actual total.
The only workaround is then to add another virtual sensor to push my totalcount. Or can I somehow misuse a managed counter?
But then again. On my previous sensor I had the offset filled in with the current state of the water meter. But every new day, the day counter was reset and my total count was the offset data. So not an actual total.
The only workaround is then to add another virtual sensor to push my totalcount. Or can I somehow misuse a managed counter?
- waltervl
- Posts: 5149
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: MQTT to Domoticz
It all depends how your previous sensor was defined and how it was filled with the script/plugin you used. We cannot see that. Perhaps the script did the resetting.
The counter sensor works like you read every time your water meter and send the counter value on the water meter to Domoticz. If you do that every 5 min or every hour the counter will modify and Domoticz will calculate the used delta of today. And will store that into the database. At 0.00 hrs it will reset the daily usage to 0.
If your hardware sensor only counts and sends the number of rotations every delta of 5 min or hour you will have to use the incremental counter. That one I think needs a script to reset every day and update the offset. But I am no expert on this. What manual are you using to implement the water meter with MQTT?
Edit: It seems that the incremental counter works the same as a normal counter but instead of the total counter you send the delta. Domoticz will calculate the rest. So no manual/script reset necessary. You only need to set the offset once if you start measuring.
The counter sensor works like you read every time your water meter and send the counter value on the water meter to Domoticz. If you do that every 5 min or every hour the counter will modify and Domoticz will calculate the used delta of today. And will store that into the database. At 0.00 hrs it will reset the daily usage to 0.
If your hardware sensor only counts and sends the number of rotations every delta of 5 min or hour you will have to use the incremental counter. That one I think needs a script to reset every day and update the offset. But I am no expert on this. What manual are you using to implement the water meter with MQTT?
Edit: It seems that the incremental counter works the same as a normal counter but instead of the total counter you send the delta. Domoticz will calculate the rest. So no manual/script reset necessary. You only need to set the offset once if you start measuring.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: MQTT to Domoticz
Hello @BlueMotion,
Just two questions:
1. Do you want to use the same widget (sensor), that is shown in my post of 22 Apr 2021, 16:59?
2. Where do you get the values:
Your current "function" does not look very good or is it only a part of a bigger function?
Regards
Just two questions:
1. Do you want to use the same widget (sensor), that is shown in my post of 22 Apr 2021, 16:59?
2. Where do you get the values:
from?value = parseInt(msg.payload.COUNTER.C1);
value2 = parseInt(global.get("WaterTotalCounter")/1000);
Your current "function" does not look very good or is it only a part of a bigger function?
Regards
-
- Posts: 10
- Joined: Thursday 04 June 2020 15:10
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.2
- Location: Subtropical Scandinavia (Fryslan)
- Contact:
Re: MQTT to Domoticz
1. Yes that was my plan. For now I created two sensors: One for DayCount and the other for TotalCount
2. Yes, just toke a small snapshot of the whole node-red flow. Just to explain that I have 2 values. A DayCount and a TotalCount
2. Yes, just toke a small snapshot of the whole node-red flow. Just to explain that I have 2 values. A DayCount and a TotalCount
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: MQTT to Domoticz
hello @BlueMotion
You wrote:
The output of this "Function" node has to be connected to the input of a MQTT Output node, with the topic domoticz/in.
I assume, you have a variable, called msg.payload.COUNTER.C1
I have no idea, whether this is a number or a string.
Let us assume, it is a number.
The IDX of the sensor is 134.
The contents of the "Function" node would become:
If the variable msg.payload.COUNTER.C1 is a string, we can omit the toString() function.
The contents will become:
The selected widget will only accept one svalue and that should be a string.
You wrote:
I assume, you have already created the sensor, so that does not need further explanation.1. Yes that was my plan. For now I created two sensors: One for DayCount and the other for TotalCount
For now, we will prepare a "Function" node to format the command for Domoticz.Yes, just toke a small snapshot of the whole node-red flow. Just to explain that I have 2 values. A DayCount and a TotalCount
The output of this "Function" node has to be connected to the input of a MQTT Output node, with the topic domoticz/in.
I assume, you have a variable, called msg.payload.COUNTER.C1
I have no idea, whether this is a number or a string.
Let us assume, it is a number.
The IDX of the sensor is 134.
The contents of the "Function" node would become:
Code: Select all
msg.payload = {"command":"udevice","idx":134,"nvalue":0,"svalue":msg.payload.COUNTER.C1.toString();
return msg;
The contents will become:
Code: Select all
msg.payload = {"command":"udevice","idx":134,"nvalue":0,"svalue":msg.payload.COUNTER.C1;
return msg;
Who is online
Users browsing this forum: Google [Bot] and 1 guest