Mqtt data to Domoticz IDX

Hi,

I want to inport data from MQTT to a certain IDX in Domoticz
this is wat I read in MQTT Explorer,

Topïc

FlowA

{
"devices": "A",
"payload": {
"Input": 23,12;
"Output": 23,18
"Flow": 0.19;
"Watt":-50,17
}
}
I'm not that experienced with rednode and MQTT and I would be thankful for som help,

Thanks, Peter.

Hi
Can you clarify your post a little bit more. What is "devices": "A" What do the other elements, like "Input", "Output", "Flow" and "Watt" (negative value) represent? Is it water? Electricity?

Which of these elements do you want to send to Domoticz? Which type of sensor in Domoticz?

I use thes values for my heatpump. Input in temperature from heatpump, output is temperature to heatpump, flow is the waterflow of the heatpump and watt is the calulate thermal power the gives,

for me the most inportant value is Watt, so the thermal power the heatpump produces.
But if that works, it sould be easy to see the other values to in domoticz

this is what MQTT gives,

FlowA = {"devices":"A","payload": {"Input":23.00,"Output":22.50,"Flow":0.19,"Watt":30.00}}

maybe this make things more clear

This is what I already made

[{"id":"48cf0425.199c6c","type":"tab","label":"Heatpump opbrengst","disabled":false,"info":""},{"id":"95bd23bc.97e4","type":"mqtt in","z":"48cf0425.199c6c","name":"Heatmeter FlowA Warmtepomp","topic":"FlowA","qos":"2","datatype":"auto","broker":"5aedb555.d0a26c","x":170,"y":420,"wires":[["a1ae996c.45aab8"]]},{"id":"b66ead6a.3c99b","type":"switch","z":"48cf0425.199c6c","name":"IDX Domoticz instellen","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"2019","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":300,"wires":[["dc478843.170978"]],"info":"IDX 2019 is afgegeven thermisch vermogen warmtepomp"},{"id":"a1ae996c.45aab8","type":"json","z":"48cf0425.199c6c","name":"","property":"payload","action":"str","pretty":false,"x":210,"y":240,"wires":[["b66ead6a.3c99b","d76d5654.fcc368"]]},{"id":"d76d5654.fcc368","type":"debug","z":"48cf0425.199c6c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":100,"wires":[]},{"id":"dc478843.170978","type":"function","z":"48cf0425.199c6c","name":"Prepare event Themal heat","func":"temp = msg.payload;\n\n\nmsg.payload = \"Watt\"\nmsg.payload =  parseFloat(temp.svalue1);\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":660,"y":340,"wires":[[]]},{"id":"ac433500.1f2108","type":"mqtt out","z":"48cf0425.199c6c","name":"","topic":"domoticz/in","qos":"","retain":"true","broker":"5aedb555.d0a26c","x":870,"y":240,"wires":[]},{"id":"5aedb555.d0a26c","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.200","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]```
[{"id":"48cf0425.199c6c","type":"tab","label":"Heatpump opbrengst","disabled":false,"info":""},{"id":"95bd23bc.97e4","type":"mqtt in","z":"48cf0425.199c6c","name":"Heatmeter FlowA Warmtepomp","topic":"FlowA","qos":"2","datatype":"auto","broker":"5aedb555.d0a26c","x":170,"y":420,"wires":[["a1ae996c.45aab8"]]},{"id":"b66ead6a.3c99b","type":"switch","z":"48cf0425.199c6c","name":"IDX Domoticz instellen","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"2019","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":300,"wires":[["dc478843.170978"]],"info":"IDX 2019 is afgegeven thermisch vermogen warmtepomp"},{"id":"a1ae996c.45aab8","type":"json","z":"48cf0425.199c6c","name":"","property":"payload","action":"str","pretty":false,"x":210,"y":240,"wires":[["b66ead6a.3c99b","d76d5654.fcc368"]]},{"id":"d76d5654.fcc368","type":"debug","z":"48cf0425.199c6c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":100,"wires":[]},{"id":"dc478843.170978","type":"function","z":"48cf0425.199c6c","name":"Prepare event Themal heat","func":"temp = msg.payload;\n\n\nmsg.payload = \"Watt\"\nmsg.payload =  parseFloat(temp.svalue1);\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":660,"y":340,"wires":[[]]},{"id":"ac433500.1f2108","type":"mqtt out","z":"48cf0425.199c6c","name":"","topic":"domoticz/in","qos":"","retain":"true","broker":"5aedb555.d0a26c","x":870,"y":240,"wires":[]},{"id":"5aedb555.d0a26c","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.200","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Hello @Smitex,

Your first published flow is not a valid flow, but your second is. So I used the second flow as a starting point.

You did not answer the question

Which type of sensor in Domoticz?

So I choose myself :slight_smile: and I selected an electric sensor, that will show the current usage of electricity in Watt and the cumulative usage in kWh. You should configure a virtual sensor of type Electric + Counter. Set the Energy read configuration of the sensor to "Computed".

Each Domoticz sensor requires it own format,
In this case: {"command":"udevice", "idx":1234, "svalue":"us;cu"}, where us is usage in Watt and cu is cumulative usage in Wh (even though it is displayed in kWh)

An overview of the required formats, you may find: domoticz – PI and more or Domoticz API/JSON URL's - Domoticz

Regarding your flow.

A JSON node is not longer needed after a MQTT Input node, as a setting in this MQTT input node will give you the required parsed JSON format.
For the rest the flow is self explanatory.

The lower part with the Inject node and MQTT Output was just needed for testing and may be omitted.

The first Debug node will show you the output from your MQTT Input node, while the second shows you the data, as needed for this sensor in Domoticz.

Screenshot_Heatpump-debug

Replace my "idx" (16) for yours (2019). Change also the configuration of the MQTT broker, currently localhost to your IP Address (192.168.1.200).

If everything is alright, you will see in Domoticz under the Utility Tab:

Screenshot_Heatpump-widget

Complete flow below:

[{"id":"ac433500.1f2108","type":"mqtt out","z":"48cf0425.199c6c","name":"","topic":"domoticz/in","qos":"","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"f9f13036.e28b58","x":1290,"y":180,"wires":[]},{"id":"f83dc978a8ef0edc","type":"mqtt in","z":"48cf0425.199c6c","name":"Heatmeter FlowA Warmtepomp","topic":"FlowA","qos":"2","datatype":"json","broker":"f9f13036.e28b58","nl":false,"rap":false,"inputs":0,"x":810,"y":180,"wires":[["04a89bf37c602541","f1aa21704f913c55"]]},{"id":"04a89bf37c602541","type":"debug","z":"48cf0425.199c6c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":120,"wires":[]},{"id":"3ce20b3734c40345","type":"mqtt out","z":"48cf0425.199c6c","name":"Heatmeter Out","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"f9f13036.e28b58","x":940,"y":280,"wires":[]},{"id":"6368e6d79d95ae63","type":"inject","z":"48cf0425.199c6c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"FlowA","payload":"{\"devices\":\"A\",\"payload\": {\"Input\":23.00,\"Output\":22.50,\"Flow\":0.19,\"Watt\":30.00}}","payloadType":"json","x":750,"y":280,"wires":[["3ce20b3734c40345"]]},{"id":"f1aa21704f913c55","type":"function","z":"48cf0425.199c6c","name":"Function","func":"msg.payload = { \"command\": \"udevice\", \"idx\": 16, \"svalue\": msg.payload.payload.Watt.toString() + \";0\" }\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":180,"wires":[["fe78ed3a1a4242ee","ac433500.1f2108"]]},{"id":"fe78ed3a1a4242ee","type":"debug","z":"48cf0425.199c6c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":120,"wires":[]},{"id":"f9f13036.e28b58","type":"mqtt-broker","name":"localhost","broker":"127.0.0.1","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Regards

Thanks very much FireWizard,
I see the value now in domoticz, the only "problem" is that, after I seen the value, it goes immediately down to zero, and comes back after the 5 sec interval
I would like that the value stay solid, and reload after the 5 sec interval.

But what I have is is already great!!

I made also the same fuction for temperature and flow, and they work ok. Could it be that because the Watt function is an calcuated value, ( w=(((((flowacount/625.0)*1000)*dta)*4.188)/5); // adjust last to match inteval of sampling sec) it react in a different way?

Suddenly The Value stayed steady, so it works fine, thanks very much FireWizard52

Hi @Smitex

You wrote:

I see the value now in domoticz, the only "problem" is that, after I seen the value, it goes immediately down to zero, and comes back after the 5 sec interval
I would like that the value stay solid, and reload after the 5 sec interval.

The flow is very simple. I just converts the value, it receives from your MQTT input to an output suitable for Domoticz

msg.payload = { "command": "udevice", "idx": 16, "svalue": msg.payload.payload.Watt.toString() + ";0" }
return msg;

So if the values is going down to zero and back, you should see that also in the first Debug node, connected to the output of the MQTT In node.

@Smitex,

You asked also:

Could it be that because the Watt function is an calcuated value, ( w=(((((flowacount/625.0)*1000)*dta)*4.188)/5); // adjust last to match inteval of sampling sec) it react in a different way?

The flow itself does not make any calculations and the Watt calculation is carried out, outside Node-RED. As said the flow just picks the value from your MQTT Input node.

Perhaps one thing you should keep in mind is that the Energy calculation, if done by Domoticz is less accurate than received from the device.
You can do the Energy calculation in Node-RED and send it to Domoticz.

Paul Reed has written an excellent node for it. See node-red-contrib-watt2kwh (node) - Node-RED

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.