Get sensor values with MQTT into Domoticz [Solved]
Moderator: leecollings
-
- Posts: 6
- Joined: Thursday 12 November 2020 12:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Slovenija
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello.
This is a screenshot of the Debug node output, in the case of the "Topic" field: home/weather/solarweatherstation/#
"Lepo vreme" means "Nice weather" in Slovenian language.
At first I would be happy if I could get in Domoticz data of tempc, humi and relhpa in Domoticz sensor »temp+hum+baro«
Where should environment level and prediction come from, I don't know. Maybe let’s leave them for a begining.
All sensors a published at the same moment.
Regards
Roman
This is a screenshot of the Debug node output, in the case of the "Topic" field: home/weather/solarweatherstation/#
"Lepo vreme" means "Nice weather" in Slovenian language.
At first I would be happy if I could get in Domoticz data of tempc, humi and relhpa in Domoticz sensor »temp+hum+baro«
Where should environment level and prediction come from, I don't know. Maybe let’s leave them for a begining.
All sensors a published at the same moment.
Regards
Roman
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello Roman (@Lipa),
You wrote:
All of them are arriving at 20:07:59, except the last, which arrives at 20:08:00.
Totally 12 messages. We should remember.
For the moment I have created a small flow, which handles
- temperature-
- humidity
- rel. pressure
- (environmental) level
This is a function, based on some calculation, which you can find : viewtopic.php?f=34&t=32414&p=245393&hil ... el#p245393
-prediction This is unknown for the moment, so I use "0".
It is based on:
The first node is the MQTT input node, which subscribe to your topic: home/weather/solarweatherstation/#
The second node is a "Join", which combines all incoming messages.
Currently 3 messages (temperature, humidity and pressure), but your weather station publish a sequence of 12 messages.
You should edit the "Join"node and replace "After a number of message parts" number 3 for 12.
In the 'Function" node you have to replace in line 17 the IDX for the IDX of your Domoticz device.
If everything has been done correctly, this is the result:
Regards
You wrote:
Strictly spoken, that is not true. You can see it easily in your debug sequence.All sensors are published at the same moment.
All of them are arriving at 20:07:59, except the last, which arrives at 20:08:00.
Totally 12 messages. We should remember.
For the moment I have created a small flow, which handles
- temperature-
- humidity
- rel. pressure
- (environmental) level
This is a function, based on some calculation, which you can find : viewtopic.php?f=34&t=32414&p=245393&hil ... el#p245393
-prediction This is unknown for the moment, so I use "0".
It is based on:
Temperature+Humidity+Barometer
The temperature+Humidity+Barometer sensor will show just that and an environment level and a prediction. You can send digits for the temperature but only the first is displayed (it is rounded off). The humidity only displays whole numbers (chops off any digits).
{"command":"udevice", "idx":1234, "svalue":"tm;hu;lv;ba;pr"}
where tm is the temperature, hu is the humidity and lv is the environment level, ba is the pressure and pr is the prediction.
lv can have the following values:
0, normal
1, comfortable
2, dry
3, wet
pr can have the following values:
0, no prediction
1, sunny
2, partly cloudy
3, cloudy
4, rain
5, unknown
(oddly enough 6 cloudy/rain does not work for this sensor)
The first node is the MQTT input node, which subscribe to your topic: home/weather/solarweatherstation/#
The second node is a "Join", which combines all incoming messages.
Currently 3 messages (temperature, humidity and pressure), but your weather station publish a sequence of 12 messages.
You should edit the "Join"node and replace "After a number of message parts" number 3 for 12.
In the 'Function" node you have to replace in line 17 the IDX for the IDX of your Domoticz device.
If everything has been done correctly, this is the result:
Regards
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello Roman (@Lipa)
I forgot the most important part, the flow itself.
Regards
I forgot the most important part, the flow itself.
Code: Select all
[{"id":"a4e7fffc.b8f908","type":"mqtt in","z":"4b2085e6.d2fdf4","name":"Weather Station In","topic":"home/weather/solarweatherstation/#","qos":"0","datatype":"json","broker":"8591549f.77809","x":250,"y":320,"wires":[["8034b495.e06e18"]]},{"id":"8034b495.e06e18","type":"join","z":"4b2085e6.d2fdf4","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":450,"y":320,"wires":[["12537246.eac82e"]]},{"id":"12537246.eac82e","type":"function","z":"4b2085e6.d2fdf4","name":"","func":"var tm = msg.payload[\"home/weather/solarweatherstation/tempc\"];\nvar hu = msg.payload[\"home/weather/solarweatherstation/humi\"];\nvar ba = msg.payload[\"home/weather/solarweatherstation/relhpa\"];\n\nfunction lv (hum) {\nif (hum < 30) {\n return 2;\n} else if ((hum >= 30) & (hum < 45)) {\n return 0;\n} else if ((hum >= 45) & (hum < 70)) {\n return 1;\n} else if (hum >= 70) {\n return 3; \n}\n}\n\nmsg.payload = {\"command\":\"udevice\", \"idx\":31, \"svalue\":tm.toString() + \";\" + hu.toString() + \";\" + lv(hu).toString() + \";\" + ba.toString() + \";\" + \"0\"}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":320,"wires":[["3e6c8450.78724c"]]},{"id":"3e6c8450.78724c","type":"mqtt out","z":"4b2085e6.d2fdf4","name":"Domoticz In","topic":"domoticz/in","qos":"2","retain":"false","broker":"f9f13036.e28b58","x":810,"y":320,"wires":[]},{"id":"8591549f.77809","type":"mqtt-broker","name":"Jonas_MQTT_Server","broker":"192.168.10.24","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"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
-
- Posts: 6
- Joined: Thursday 12 November 2020 12:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Slovenija
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello FireWizard
Thanks, it works great ...
Why does the Domoticz log message repeat 10 times?
Probably because:
Thanks, it works great ...
Code: Select all
2020-11-13 19:09:46.425 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:46.536 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:46.646 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:46.757 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:46.868 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:46.979 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:47.089 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:47.200 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:47.318 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
2020-11-13 19:09:47.430 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"svalue":"9.6;91;3;1028;0"}
Probably because:
RegardsStrictly spoken, that is not true. You can see it easily in your debug sequence.
All of them are arriving at 20:07:59, except the last, which arrives at 20:08:00.
Totally 12 messages. We should remember.
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi,
@Lipa
You wrote:
With the current content of the Function node the flow is triggered on all messages.
The first 3 incoming messages result in 1 outgoing message and then every incoming gives the same outgoing. So totally 10.
I think we can improve it by adding a node, so that it is only triggering, if temperature, humidity or pressure is received.
This node is not part of the default node set, so you have to load it from the Palette
To do so
1 .Go to the "hamburger" menu, just right of the Deploy button.
2. Click "Manage palette".
3. Goto to the tab "Install"
4. Search for node-red-contrib-filter
5. Install this node.
Please find below the new flow with "Filter" node included.
This "Filter" node let only the 3 messages, containing the currently used items, pass.
So if you want more items, you might have to change the content of the "Filter" node.
Also set the "Join" node to 3 again.
Regards
@Lipa
You wrote:
That is correct.Why does the Domoticz log message repeat 10 times?
Probably because:
Strictly spoken, that is not true. You can see it easily in your debug sequence.
All of them are arriving at 20:07:59, except the last, which arrives at 20:08:00.
Totally 12 messages. We should remember.
With the current content of the Function node the flow is triggered on all messages.
The first 3 incoming messages result in 1 outgoing message and then every incoming gives the same outgoing. So totally 10.
I think we can improve it by adding a node, so that it is only triggering, if temperature, humidity or pressure is received.
This node is not part of the default node set, so you have to load it from the Palette
To do so
1 .Go to the "hamburger" menu, just right of the Deploy button.
2. Click "Manage palette".
3. Goto to the tab "Install"
4. Search for node-red-contrib-filter
5. Install this node.
Please find below the new flow with "Filter" node included.
Code: Select all
[{"id":"a4e7fffc.b8f908","type":"mqtt in","z":"4b2085e6.d2fdf4","name":"Weather Station In","topic":"home/weather/solarweatherstation/#","qos":"0","datatype":"json","broker":"8591549f.77809","x":150,"y":320,"wires":[["2e7e4f04.135788"]]},{"id":"8034b495.e06e18","type":"join","z":"4b2085e6.d2fdf4","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":610,"y":320,"wires":[["12537246.eac82e"]]},{"id":"12537246.eac82e","type":"function","z":"4b2085e6.d2fdf4","name":"","func":"var tm = msg.payload[\"home/weather/solarweatherstation/tempc\"];\nvar hu = msg.payload[\"home/weather/solarweatherstation/humi\"];\nvar ba = msg.payload[\"home/weather/solarweatherstation/relhpa\"];\n\nfunction lv (hum) {\nif (hum < 30) {\n return 2;\n} else if ((hum >= 30) & (hum < 45)) {\n return 0;\n} else if ((hum >= 45) & (hum < 70)) {\n return 1;\n} else if (hum >= 70) {\n return 3; \n}\n}\n\nmsg.payload = {\"command\":\"udevice\", \"idx\":31, \"svalue\":tm.toString() + \";\" + hu.toString() + \";\" + lv(hu).toString() + \";\" + ba.toString() + \";\" + \"0\"}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":780,"y":320,"wires":[["3e6c8450.78724c"]]},{"id":"3e6c8450.78724c","type":"mqtt out","z":"4b2085e6.d2fdf4","name":"Domoticz In","topic":"domoticz/in","qos":"2","retain":"false","broker":"f9f13036.e28b58","x":970,"y":320,"wires":[]},{"id":"2e7e4f04.135788","type":"filter","z":"4b2085e6.d2fdf4","name":"Filter Temp/Hum/Bar","property":"topic","propertyType":"msg","asArray":false,"itemProperty":"","itemPropertyType":"item","rules":[{"t":"eq","v":"home/weather/solarweatherstation/tempc","vt":"str","output":1},{"t":"eq","v":"home/weather/solarweatherstation/humi","vt":"str","output":1},{"t":"eq","v":"home/weather/solarweatherstation/relhpa","vt":"str","output":1}],"checkall":"true","outputs":1,"x":400,"y":320,"wires":[["8034b495.e06e18"]]},{"id":"8591549f.77809","type":"mqtt-broker","name":"Jonas_MQTT_Server","broker":"192.168.10.24","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"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":""}]
So if you want more items, you might have to change the content of the "Filter" node.
Also set the "Join" node to 3 again.
Regards
Last edited by FireWizard on Saturday 14 November 2020 9:31, edited 1 time in total.
-
- Posts: 6
- Joined: Thursday 12 November 2020 12:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Slovenija
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi,
@FireWizard
Thank you so much, now I just see how powerful a tool Node Red is if you know him.
There are now three records in the log.
Thanks again for the help and I still ask you for further instructions if I need it.
@FireWizard
Thank you so much, now I just see how powerful a tool Node Red is if you know him.
There are now three records in the log.
Code: Select all
020-11-13 23:19:30.759 (Aeotec ZW090) General/kWh (AN 158 kWh Meter)
2020-11-13 23:19:52.742 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":120,"svalue":"8.8;91;3;1029;0"}
2020-11-13 23:19:52.857 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":120,"svalue":"8.8;91;3;1029;0"}
2020-11-13 23:19:52.968 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":120,"svalue":"8.8;91;3;1029;0"}
2020-11-13 23:19:53.079 MQTT: Topic: domoticz/in, Message: {"command":"udevice","idx":121,"nvalue":0,"svalue":"4.02"}
2020-11-13 23:20:04.075 (Aeotec ZW090) Usage (AN 158 W Meter)
-
- Posts: 17
- Joined: Thursday 14 December 2017 23:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi @FireWizard,
you are my last great hope
I sit now for days on it and just do not come further.
I always get only: svalue: undefined out. Somewhere I have an error, but I just can't find it. Maybe I am doing fundamentally wrong.
I have the hope that you with your knowledge simply say "Yes, there is the error, take this value and it works".
Here is my situation:
I collect data from my electricity meter via a Raspberry (vzlogger aka volkszähler) and output that there via MQTT. I have installed a MQTT broker and Node Red and everything works. For example, I can write to a text sensor via Node Red.
in the node mqtt in I see the data: in the json node also But no matter how I try, I don't get anything usable from the function node.
I don't really have a clue about JavaScript. i tried to understand your examples and adapt them to me, but it just doesn't work. with this code:
Can you tell me what i am doing wrong and how i can solve this?
The actual goal then is to get two values into my electric sensor.
The current consumption and the meter reading.
I really hope that you can help me, or someone else who has already implemented something like this.
many greetings
Marco
you are my last great hope
I sit now for days on it and just do not come further.
I always get only: svalue: undefined out. Somewhere I have an error, but I just can't find it. Maybe I am doing fundamentally wrong.
I have the hope that you with your knowledge simply say "Yes, there is the error, take this value and it works".
Here is my situation:
I collect data from my electricity meter via a Raspberry (vzlogger aka volkszähler) and output that there via MQTT. I have installed a MQTT broker and Node Red and everything works. For example, I can write to a text sensor via Node Red.
in the node mqtt in I see the data: in the json node also But no matter how I try, I don't get anything usable from the function node.
I don't really have a clue about JavaScript. i tried to understand your examples and adapt them to me, but it just doesn't work. with this code:
Code: Select all
var us = msg.payload["domoticz/in/chn1/raw"];
var cu = msg.payload["domoticz/in/chn3/raw"];
msg.payload = {"command":"udevice", "idx":473, "svalue":us}
return msg;
Can you tell me what i am doing wrong and how i can solve this?
The actual goal then is to get two values into my electric sensor.
The current consumption and the meter reading.
I really hope that you can help me, or someone else who has already implemented something like this.
many greetings
Marco
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
HI, @lazaruss72, Marco
It is not a huge problem.
1. If I look to the output of your MQTT out node, I see you are subscribed to domoticz/in/#.
That does not look correct. You use as input everything that is sent to Domoticz. In fact you are looking to a loop. And Domoticz can not handle this data.
You said:
See: https://flows.nodered.org/node/node-red ... lkszaehler
I see discussions about MQTT support for vzlogger. If you use that (I assume you do) do you have info about the published topics?
Your topic is domoticz/in/chn1/raw and also chn0, chn2 and chn3.
However, I found somewhere on Internet that vzlogger publishes the data under topic: vzlogger/data/chn0/raw.
Can you confirm this?
2. The Domoticz sensor, you want to control.
Is this of type Electric?
If you can give me that information, I have a flow ready.
Regards
It is not a huge problem.
1. If I look to the output of your MQTT out node, I see you are subscribed to domoticz/in/#.
That does not look correct. You use as input everything that is sent to Domoticz. In fact you are looking to a loop. And Domoticz can not handle this data.
You said:
There exist a Node Red node for Volkszähler. Do you use that one?vzlogger aka volkszähler
See: https://flows.nodered.org/node/node-red ... lkszaehler
I see discussions about MQTT support for vzlogger. If you use that (I assume you do) do you have info about the published topics?
Your topic is domoticz/in/chn1/raw and also chn0, chn2 and chn3.
However, I found somewhere on Internet that vzlogger publishes the data under topic: vzlogger/data/chn0/raw.
Can you confirm this?
2. The Domoticz sensor, you want to control.
Is this of type Electric?
If you can give me that information, I have a flow ready.
Regards
-
- Posts: 17
- Joined: Thursday 14 December 2017 23:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello FireWizard,
first of all thank you for your prompt reply.
to your questions:
the orginal topic in volkszähler is vzlogger/data, that's right. I had changed it to domoticz/in since I don't have any other mqtt stuff and thought it has no effect.
the node red nodes for volkszähler i didn't know and i don't have them in use. i have them installed now but i don't understand how to use them. don't really find information about them.
Yes, I can confirm that the vzlogger publishes by default under the topic vzlogger/data/chn0/raw.
And yes, this is exactly the sensor I want to feed with data.
I think that is the right one. I am very curious about your flow and hope that it is the solution... the topic has already given me some sleepless nights.
many greetings
lazarus
first of all thank you for your prompt reply.
to your questions:
the orginal topic in volkszähler is vzlogger/data, that's right. I had changed it to domoticz/in since I don't have any other mqtt stuff and thought it has no effect.
the node red nodes for volkszähler i didn't know and i don't have them in use. i have them installed now but i don't understand how to use them. don't really find information about them.
Yes, I can confirm that the vzlogger publishes by default under the topic vzlogger/data/chn0/raw.
And yes, this is exactly the sensor I want to feed with data.
I think that is the right one. I am very curious about your flow and hope that it is the solution... the topic has already given me some sleepless nights.
many greetings
lazarus
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello @lazaruss72, Hello Marco.
If I look to your screenshots, I see that the value is a string. (the color is red and it is between " "). I see also that you have multiple channels (chn0, chn1, chn2 and chn3). Perhaps more, that I cannot see. I noticed you want to use the data from chn1 and chn 2.
I suggest the following flow:
As we have (at least) 4 channels, from which we want to use only 2, I propose not to use wildcards, like + or #, but to create 2 MQTT Input nodes with the correct topic. This avoids that we have to remove the other, unused topics, which may interfere with the correct stream.
The data is a simple payload with the value in a string. If it is a number we have to modify the "function"node slightly.
These two topics are joined in a Join node, where the topic (vzlogger/data/chn1/raw and vzlogger/data/chn3/raw) is used as the "key".
The result, you will see in the screenshot below.
These values are used in the function node to prepare the correct data to Domoticz.
The correct syntax is: {"command":"udevice", "idx":1234, "svalue":"us;cu"}.
The command "command":"udevice" is the default command and therefore may be omitted, but for clarity. I left it in.
You have to insert your IDX number for the sensor you use (electric)
The svalue has always to be a string value. In this case two string variable (us and cu), separated by a semicolon (;).
This is prepared in the function node.
If the data consists of a number (blue color and no " ") you have to make it as a string with the function as follows:
The result is as follows:
and will give you this values in the sensor:
I entered just some figures, so keep in mind that cu is cumulative and the values are added.
The input should be in Wh, although the presentation wil be in kWh.
Please find attached the complete flow:
Do not forget to insert the correct IDX number
Awaiting your result.
Regards
If I look to your screenshots, I see that the value is a string. (the color is red and it is between " "). I see also that you have multiple channels (chn0, chn1, chn2 and chn3). Perhaps more, that I cannot see. I noticed you want to use the data from chn1 and chn 2.
I suggest the following flow:
As we have (at least) 4 channels, from which we want to use only 2, I propose not to use wildcards, like + or #, but to create 2 MQTT Input nodes with the correct topic. This avoids that we have to remove the other, unused topics, which may interfere with the correct stream.
The data is a simple payload with the value in a string. If it is a number we have to modify the "function"node slightly.
These two topics are joined in a Join node, where the topic (vzlogger/data/chn1/raw and vzlogger/data/chn3/raw) is used as the "key".
The result, you will see in the screenshot below.
These values are used in the function node to prepare the correct data to Domoticz.
The correct syntax is: {"command":"udevice", "idx":1234, "svalue":"us;cu"}.
The command "command":"udevice" is the default command and therefore may be omitted, but for clarity. I left it in.
You have to insert your IDX number for the sensor you use (electric)
The svalue has always to be a string value. In this case two string variable (us and cu), separated by a semicolon (;).
This is prepared in the function node.
Code: Select all
var us = msg.payload["vzlogger/data/chn1/raw."];
var cu = msg.payload["vzlogger/data/chn3/raw."];
msg.payload = {"command":"udevice", "idx":45, "svalue":us + ";" + cu};
return msg;
Code: Select all
var us = msg.payload["vzlogger/data/chn1/raw."].toString();
var cu = msg.payload["vzlogger/data/chn3/raw."].toString();
msg.payload = {"command":"udevice", "idx":45, "svalue":us + ";" + cu};
return msg;
and will give you this values in the sensor:
I entered just some figures, so keep in mind that cu is cumulative and the values are added.
The input should be in Wh, although the presentation wil be in kWh.
Please find attached the complete flow:
Code: Select all
[{"id":"258d3ca4.36a2ec","type":"mqtt in","z":"b49db3af.cc9f8","name":"","topic":"vzlogger/data/chn1/raw.","qos":"2","datatype":"json","broker":"f9f13036.e28b58","x":250,"y":260,"wires":[["5afd9f35.aa70f"]]},{"id":"97ca8bf2.e3361","type":"function","z":"b49db3af.cc9f8","name":"","func":"var us = msg.payload[\"vzlogger/data/chn1/raw.\"];\nvar cu = msg.payload[\"vzlogger/data/chn3/raw.\"];\n\nmsg.payload = {\"command\":\"udevice\", \"idx\":45, \"svalue\":us + \";\" + cu};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":320,"wires":[["f352fb59.cd04f","d0e46a68.0d0e08"]]},{"id":"f352fb59.cd04f","type":"debug","z":"b49db3af.cc9f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":422,"wires":[]},{"id":"d0e46a68.0d0e08","type":"mqtt out","z":"b49db3af.cc9f8","name":"","topic":"domoticz/in","qos":"0","retain":"false","broker":"f9f13036.e28b58","x":830,"y":320,"wires":[]},{"id":"5f929d20.09ce6c","type":"mqtt in","z":"b49db3af.cc9f8","name":"","topic":"vzlogger/data/chn3/raw.","qos":"2","datatype":"json","broker":"f9f13036.e28b58","x":250,"y":380,"wires":[["5afd9f35.aa70f"]]},{"id":"5afd9f35.aa70f","type":"join","z":"b49db3af.cc9f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":470,"y":320,"wires":[["4d33fb01.4811b4","97ca8bf2.e3361"]]},{"id":"4d33fb01.4811b4","type":"debug","z":"b49db3af.cc9f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":262,"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":""}]
Awaiting your result.
Regards
-
- Posts: 17
- Joined: Thursday 14 December 2017 23:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello FireWizard,
thank you for your answer and the detailed explanations.
The two inputs and the join is completely ingenious.
I have tested your flow and unfortunately have to say that at the end comes out again undefined
As you can see in the screenshot below after the join at debug node both values occur.
But at debug node after the function arrives undefined.
I don't understand why ... your function looks very logical. i also tried it with the second code. there is the exact same thing
best regards
lazarus
thank you for your answer and the detailed explanations.
The two inputs and the join is completely ingenious.
I have tested your flow and unfortunately have to say that at the end comes out again undefined
As you can see in the screenshot below after the join at debug node both values occur.
But at debug node after the function arrives undefined.
I don't understand why ... your function looks very logical. i also tried it with the second code. there is the exact same thing
best regards
lazarus
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi, @lazaruss72
I see it. There is a dot behind the topic. No idea, how that has been introduced. Obviously introduced by me, during copy/paste.
I have now the following flow:
And the contents of the 'Function" node is now as follows, as it turned out to be a number and not a string:
Do not forget to insert the correct IDX number
Awaiting your result.
Regards
I see it. There is a dot behind the topic. No idea, how that has been introduced. Obviously introduced by me, during copy/paste.
I have now the following flow:
And the contents of the 'Function" node is now as follows, as it turned out to be a number and not a string:
Code: Select all
var us = msg.payload["vzlogger/data/chn1/raw"].toString();
var cu = msg.payload["vzlogger/data/chn3/raw"].toString();
msg.payload = {"command":"udevice", "idx":45, "svalue":us + ";" + cu};
return msg;
Awaiting your result.
Regards
-
- Posts: 17
- Joined: Thursday 14 December 2017 23:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello @FireWizard,
You are absolutely amazing!
IT WORKS
I had seen the point at mqtt in node and corrected it, but it didn't occur to me to do the same in the function node. that's not where I noticed it.
I am so happy that it is finally working now!!! Many many thanks for that. Now I will put the second sensor into operation and hope that I can manage it.
Stay healthy and many greetings
lazarus
You are absolutely amazing!
IT WORKS
I had seen the point at mqtt in node and corrected it, but it didn't occur to me to do the same in the function node. that's not where I noticed it.
I am so happy that it is finally working now!!! Many many thanks for that. Now I will put the second sensor into operation and hope that I can manage it.
Stay healthy and many greetings
lazarus
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi, @lazaruss72
Nice that it is working as expected
Best regards
Nice that it is working as expected
If you need some support, do not hesitate to ask.Now I will put the second sensor into operation and hope that I can manage it.
Best regards
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello Dear expert,
So sorry to trouble you with another noob at this...
I am trying to get measured current data to Domoticz (using EmonTX Shield for Arduino).
I have MQTT and Node-red up and running (I can see the Json data on the MQTT broker).
It looks like this: {"Phase1":xxx,"Phase2":yyy,"Phase3":zzz}
I did at a time manage to get updated values to the three 1-phase labels in Domoticz, but always with the (quite useless) value zero. In this picture they aren't updates at all.
Below is the flow with code from this helpful thread.
Hoping to get some help.
Thanjs in advance.
Br Richard
So sorry to trouble you with another noob at this...
I am trying to get measured current data to Domoticz (using EmonTX Shield for Arduino).
I have MQTT and Node-red up and running (I can see the Json data on the MQTT broker).
It looks like this: {"Phase1":xxx,"Phase2":yyy,"Phase3":zzz}
I did at a time manage to get updated values to the three 1-phase labels in Domoticz, but always with the (quite useless) value zero. In this picture they aren't updates at all.
Below is the flow with code from this helpful thread.
Hoping to get some help.
Thanjs in advance.
Br Richard
- Attachments
-
- Domoticz.JPG (30.12 KiB) Viewed 2036 times
-
- MQTT_to_Domoticz.JPG (50.7 KiB) Viewed 2036 times
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello @rippe
Dis you ever try to comment out the line starting with msg4? By putting // in front of it. And also remove msg4 between [[ ]]?
It should work.
But the problem is msg4.
What you do is that you send with msg 4, 3 complete message objects. You can see that after IDX 327 in the picture you send in your post.
What you want is to send the 3 values (ampere) of both Phase 1, Phase 2 and Phase 3 (separated by a semicolon
These values you will find back in msg1.payload.svalue, etc.
I modified your flow as follows:
I changed the IDX (18-21) numbers in order to test on my system.
This results in:
And in Domoticz:
Best regards
As far as I can see, the values for Current L1, CurrentL2 and Current L3 should update. The commands to Domoticz are correct.I did at a time manage to get updated values to the three 1-phase labels in Domoticz, but always with the (quite useless) value zero. In this picture they aren't updates at all.
Dis you ever try to comment out the line starting with msg4? By putting // in front of it. And also remove msg4 between [[ ]]?
It should work.
But the problem is msg4.
What you do is that you send with msg 4, 3 complete message objects. You can see that after IDX 327 in the picture you send in your post.
What you want is to send the 3 values (ampere) of both Phase 1, Phase 2 and Phase 3 (separated by a semicolon
These values you will find back in msg1.payload.svalue, etc.
I modified your flow as follows:
Code: Select all
var msg1 ={};
var msg2 ={};
var msg3 ={};
var msg4 ={};
msg1.payload = {"command": "udevice","idx":18,"svalue": msg.payload.Phase1.toString()};
msg2.payload = {"command": "udevice","idx":19,"svalue": msg.payload.Phase2.toString()};
msg3.payload = {"command": "udevice","idx":20,"svalue": msg.payload.Phase3.toString()};
msg4.payload = {"command": "udevice","idx":21,"svalue": msg1.payload.svalue + ";" + msg2.payload.svalue + ";" + msg3.payload.svalue};
return [[msg1,msg2,msg3,msg4]]
This results in:
And in Domoticz:
Best regards
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi @FireWizard,
Jeeez... You are quick
Message 4 was much better.
However, Domoticz still will not update the values. Have a look at the picture. I believe it's somthing with the incoming string or something (see the parsing error).
Best regards,
Richard
Jeeez... You are quick
Message 4 was much better.
However, Domoticz still will not update the values. Have a look at the picture. I believe it's somthing with the incoming string or something (see the parsing error).
Best regards,
Richard
- Attachments
-
- ParseError.JPG (49.77 KiB) Viewed 2027 times
-
- MQTT_to_Domoticz_3.JPG (35.14 KiB) Viewed 2027 times
-
- MQTT_to_Domoticz_2.JPG (67.01 KiB) Viewed 2027 times
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi, @rippe
It looks much better, but I really do not understand why the sensors are not updated.
If I take my values (and my input is exactly the same as yours) and configure the MQTT input node, to receive a string, then it gives me a string of 55 characters. The error you get, "Failed to parse JSON string" indicates a string of 27 characters.
But the output of your MQTT input node is a parsed JSON Object.
I assume that this error message is coming from this flow and not from another flow at another tab.
If you hoover with your mouse over the error message, does it indicate the MQTT input node?
If so, can you disconnect the MQTT input node from the "Function" node and change the Output to auto-detect.
Can you then make a screenshot of that first "Debug" node.
What I do not understand is why the sensors are not updated, while the commands are correct.
Question.
1. Is the MQTT out node correctly configured? (Is it pointing to same MQTT server as where Domoticz has subscribed to?)
Are there more MQTT servers?
2. Are the IDX numbers correct and do they match with the configured virtual sensors?
Let me know,
Regards
It looks much better, but I really do not understand why the sensors are not updated.
If I take my values (and my input is exactly the same as yours) and configure the MQTT input node, to receive a string, then it gives me a string of 55 characters. The error you get, "Failed to parse JSON string" indicates a string of 27 characters.
But the output of your MQTT input node is a parsed JSON Object.
I assume that this error message is coming from this flow and not from another flow at another tab.
If you hoover with your mouse over the error message, does it indicate the MQTT input node?
If so, can you disconnect the MQTT input node from the "Function" node and change the Output to auto-detect.
Can you then make a screenshot of that first "Debug" node.
What I do not understand is why the sensors are not updated, while the commands are correct.
Question.
1. Is the MQTT out node correctly configured? (Is it pointing to same MQTT server as where Domoticz has subscribed to?)
Are there more MQTT servers?
2. Are the IDX numbers correct and do they match with the configured virtual sensors?
Let me know,
Regards
Re: Get sensor values with MQTT into Domoticz [Solved]
Hi @FireWizard,
Yes, doesn't it .
It comes from the Arduino code and "StaticJsonDocument", so it should be correct (I suppose):
const int capacity = JSON_OBJECT_SIZE(3);
StaticJsonDocument<capacity> doc;
doc["Phase1"] = Irms1;
doc["Phase2"] = Irms2;
doc["Phase3"] = Irms3;
serializeJson(doc, Serial);
I have a lot of Flows, but showing messages only from the one currently opened. Hoovering over it indicates the incoming MQTT node.
1. Is the MQTT out node correctly configured? (Is it pointing to same MQTT server as where Domoticz has subscribed to?)
Are there more MQTT servers?
Answer: There are more MQTT brokers, but I actually double checked now when you asked - it's the correct one
2. Are the IDX numbers correct and do they match with the configured virtual sensors?
Answer: Yes, they are matching.
Please have a look at the attached debug message.
Best regards Richard
Yes, doesn't it .
It comes from the Arduino code and "StaticJsonDocument", so it should be correct (I suppose):
const int capacity = JSON_OBJECT_SIZE(3);
StaticJsonDocument<capacity> doc;
doc["Phase1"] = Irms1;
doc["Phase2"] = Irms2;
doc["Phase3"] = Irms3;
serializeJson(doc, Serial);
I have a lot of Flows, but showing messages only from the one currently opened. Hoovering over it indicates the incoming MQTT node.
1. Is the MQTT out node correctly configured? (Is it pointing to same MQTT server as where Domoticz has subscribed to?)
Are there more MQTT servers?
Answer: There are more MQTT brokers, but I actually double checked now when you asked - it's the correct one
2. Are the IDX numbers correct and do they match with the configured virtual sensors?
Answer: Yes, they are matching.
Please have a look at the attached debug message.
Best regards Richard
- Attachments
-
- MQTT_to_Domoticz_4.JPG (47.61 KiB) Viewed 2024 times
- FireWizard
- Posts: 1745
- Joined: Tuesday 25 December 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Voorthuizen (NL)
- Contact:
Re: Get sensor values with MQTT into Domoticz [Solved]
Hello @rippe
The problem is caused by the second message with a string, containing only a "carriage return" and this cannot be parsed by the MQTT input node.
This caused the message "Failed to parse JSON string"
In addition, I see also a "carriage return" at the end of the first string, but this one doesn't seem to cause a problem.
To prevent this extra string to give a fault message, we have to block the faulty string or allow the correct strings to pass.
I choose for the second option, as I'am not sure, if other faulty strings may occur.
To do so:
1. Change the Output in the MQTT input node from "a parsed JSON object" to "auto-detect (string or buffer)".
2. Add a "Switch" node after the MQTT input node as follows:
Filter on "contains" and "Phase
That means that only strings, that contains the substring "Phase" will pass.
3. Add a JSON node after the "Switch" node. (As we removed the parsing in the MQTT node, we have to do it now.)
The flow will look as follows:
Can you test this and report back?
Regards
I did and I was able to simulate the problem.Please have a look at the attached debug message.
The problem is caused by the second message with a string, containing only a "carriage return" and this cannot be parsed by the MQTT input node.
This caused the message "Failed to parse JSON string"
In addition, I see also a "carriage return" at the end of the first string, but this one doesn't seem to cause a problem.
To prevent this extra string to give a fault message, we have to block the faulty string or allow the correct strings to pass.
I choose for the second option, as I'am not sure, if other faulty strings may occur.
To do so:
1. Change the Output in the MQTT input node from "a parsed JSON object" to "auto-detect (string or buffer)".
2. Add a "Switch" node after the MQTT input node as follows:
Filter on "contains" and "Phase
That means that only strings, that contains the substring "Phase" will pass.
3. Add a JSON node after the "Switch" node. (As we removed the parsing in the MQTT node, we have to do it now.)
The flow will look as follows:
Can you test this and report back?
Regards
Who is online
Users browsing this forum: No registered users and 0 guests