Get sensor values with MQTT into Domoticz [Solved]

Everything about esp8266 and more.

Moderator: leecollings

rippe
Posts: 7
Joined: Monday 07 October 2019 18:33
Target OS: Windows
Domoticz version:
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by rippe »

Marvelous @FireWizard!!!

You've done it again! :D

It works flawless now. I do see a carriage return still, coming from MQTT-in node, but it do not give me any headache in function and looks so I can live with it.

Thank you a thousand times!!! I would like to buy you a cup of coffea at the very least ;-)

Best regards,
Richard
Attachments
Domoticz_2.JPG
Domoticz_2.JPG (53.62 KiB) Viewed 2569 times
MQTT_to_Domoticz_4.JPG
MQTT_to_Domoticz_4.JPG (47.61 KiB) Viewed 2569 times
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Hello Richard, @rippe,

You wrote:
I do see a carriage return still, coming from MQTT-in node
Yes, that "carriage return" comes from the outside world (Arduino). We want, that it has no negative effect en therefore it has been blocked in the "Switch" node. Or better, only messages with the text "Phase" in its payload are allowed to pass.
The result is that the "carriage return" has no effect in the next nodes in the flow.

The only way to stop the "carriage return" showing in a MQTT input node, is that you block it in the Arduino, so that it is not published.
But that is probably more complex than stopping it here.

And buy that cup of coffee, but drink it yourself :D

Regards,
rippe
Posts: 7
Joined: Monday 07 October 2019 18:33
Target OS: Windows
Domoticz version:
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by rippe »

Dear FireWizard,

To your comment:
And buy that cup of coffee, but drink it yourself :D
I made an extra nice cup of coffee and cheered with you ;-)
Thanx a lot again!

Richard
rjblake
Posts: 142
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by rjblake »

@FireWizard, wondering if you can help me out with your expertise on this problem - I cannot get my head around it or decide on the best approach. I have created a flow in node red and it works; but still throws errors although gives me the result I want. I'm missing something somewhere.

Background:
8x Xiaomi Temp/Humidity sensors that report out values through Tasmota MQTT (using an ESP32). In order to ensure that the MQTT length is respected, Tasmota breaks this down into 2x separate messages (device grouping seems constant; but may change or sometime it doesn't get a broadcast from all devices, so may have less than 4x devices in the MQTT message.

My sketchy flow:
Screenshot 2021-02-11 at 15.15.24.png
Screenshot 2021-02-11 at 15.15.24.png (46.93 KiB) Viewed 2542 times
Example message here (object):

Code: Select all

{
  "Time":"2021-02-11T14:42:19",
  "ATC1abc06":{
    "mac":"a4c1381abc06",
    "Temperature":19.9,
    "Humidity":38,
    "DewPoint":5.1,
    "Battery":73,
    "RSSI":-82
  },
  "ATC0e70ed":{
    "mac":"a4c1380e70ed",
    "Temperature":20.9,
    "Humidity":38,
    "DewPoint":6,
    "Battery":84,
    "RSSI":-71
  },
  "ATC9c53be":{
    "mac":"a4c1389c53be",
    "Temperature":20.5,
    "Humidity":37,
    "DewPoint":5.3,
    "Battery":83,
    "RSSI":-93
  },
  "ATCbc6b43":{
    "mac":"a4c138bc6b43",
    "Temperature":21.2,
    "Humidity":35,
    "DewPoint":5.1,
    "Battery":78,
    "RSSI":-85
  }
}
I want to be able to update the corresponding devices in Domoticz irrespective of whether I receive info on all.

My function to process the MQTT as follows:

Code: Select all

var msg1 = {};
var msg2 = {};
var msg3 = {};
var msg4 = {};

msg1.payload = {};
msg1.payload.idx = 809;
msg1.payload.svalue = msg.payload.ATC1abc06.Temperature.toString() + ";" + msg.payload.ATC1abc06.Humidity.toString() + ";" + "0";
msg1.payload.Battery = msg.payload.ATC1abc06.Battery;
msg2.payload = {};
msg2.payload.idx = 810;
msg2.payload.svalue = msg.payload.ATC0e70ed.Temperature.toString() + ";" + msg.payload.ATC0e70ed.Humidity.toString() + ";" + "0";
msg2.payload.Battery = msg.payload.ATC0e70ed.Battery;
msg3.payload = {};
msg3.payload.idx = 811;
msg3.payload.svalue = msg.payload.ATC9c53be.Temperature.toString() + ";" + msg.payload.ATC9c53be.Humidity.toString() + ";" + "0";
msg3.payload.Battery = msg.payload.ATC9c53be.Battery;
msg4.payload = {};
msg4.payload.idx = 812;
msg4.payload.svalue = msg.payload.ATCbc6b43.Temperature.toString() + ";" + msg.payload.ATCbc6b43.Humidity.toString() + ";" + "0";
msg4.payload.Battery = msg.payload.ATCbc6b43.Battery;

return [[msg1,msg2,msg3,msg4]];
As mentioned, it works, but I get an error:

Code: Select all

11/02/2021, 14:42:20node: 2nd_4xTherm
function : (error)
"TypeError: Cannot read property 'Temperature' of undefined"
I did try using the following (extract, not all 4x devices), but it will not update the Domoticz device Battery level

Code: Select all

var msg1 = {}; // Device 1
var msg2 = {}; // Device 2
msg1.payload = {"command":"udevice","idx":809,"svalue":msg.payload.ATC1abc06.Temperature.toString() + ";" + msg.payload.ATC1abc06.Humidity.toString() + ";" + "0", "Battery=":msg.payload.ATC1abc06.Battery};
msg2.payload = {"command":"udevice","idx":810,"svalue":msg.payload.ATC0e70ed.Temperature.toString() + ";" + msg.payload.ATC0e70ed.Humidity.toString() + ";" + "0", "Battery=":msg.payload.ATC0e70ed.Battery};
return [[msg1,msg2]];
From a pseudo code perspective, I guess what I'm trying to achieve is the following:
- Receive MQTT
- while device object (with relevant data)
-- update relevant Domoticz device (temp, humidity, battery level)
- end
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Good evening @rjblake

You wrote:
wondering if you can help me out with your expertise on this problem - I cannot get my head around it or decide on the best approach. I have created a flow in node red and it works; but still throws errors although gives me the result I want. I'm missing something somewhere.
Sure, we can try, at least.
8x Xiaomi Temp/Humidity sensors that report out values through Tasmota MQTT (using an ESP32). In order to ensure that the MQTT length is respected, Tasmota breaks this down into 2x separate messages (device grouping seems constant; but may change or sometime it doesn't get a broadcast from all devices, so may have less than 4x devices in the MQTT message.
I think that this is causing a problem.

In your post I see only 4 devices and not eight, but my suggestion can be extended.

Let me explain, what I did.

I see a Time string, followed by 4 JSON objects from 4 different devices.

I splitted this messages in a separate Time string and 4 separated Objects.
The device identifier, I put in the msg.topic and in the Function node I use this as the selector in a Switch/Case statement.
You can compare that with multiple if/then (else) statements.
At the end I deleted the time string.

Can you try the following nodes between your MQTT input node and the MQTT output node to Domoticz.
If this works error free, I will add the Battery, because I have to look at that.

Code: Select all

[{"id":"e50c86cb.a7ed9","type":"split","z":"78424a4d.74778c","name":"Split Objects","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":370,"y":140,"wires":[["c664e05d.ff1c5"]]},{"id":"d062a378.c157d8","type":"debug","z":"78424a4d.74778c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":200,"wires":[]},{"id":"c664e05d.ff1c5","type":"function","z":"78424a4d.74778c","name":"","func":"switch (msg.topic) {\n    \n    case \"ATC1abc06\":\n    msg.payload = {\"command\":\"udevice\",\"idx\":809,\"nvalue\":0,\"svalue\":msg.payload.Temperature.toString() + \";\" + msg.payload.Humidity.toString() + \";\" + \"0\"};\n    break;\n\n    case \"ATC0e70ed\":\n    msg.payload = {\"command\":\"udevice\",\"idx\":810,\"nvalue\":0,\"svalue\":msg.payload.Temperature.toString() + \";\" + msg.payload.Humidity.toString() + \";\" + \"0\"};\n    break;\n\n    case \"ATC9c53be\":\n    msg.payload = {\"command\":\"udevice\",\"idx\":811,\"nvalue\":0,\"svalue\":msg.payload.Temperature.toString() + \";\" + msg.payload.Humidity.toString() + \";\" + \"0\"};\n    break;\n\n    case \"ATCbc6b43\":\n    msg.payload = {\"command\":\"udevice\",\"idx\":812,\"nvalue\":0,\"svalue\":msg.payload.Temperature.toString() + \";\" + msg.payload.Humidity.toString() + \";\" + \"0\"};\n    break;\n    \n    case \"Time\":\n    return null;\n    \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":140,"wires":[["d062a378.c157d8"]]}]
Let me know,

Best regards
rjblake
Posts: 142
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by rjblake »

FireWizard wrote: Thursday 11 February 2021 22:26 Good evening @rjblake

...

Best regards
You are absolutely amazing! Many thanks for this. I had created a split this evening to try something, but was still lost where to go from there trying to work out the 'case' logic. My JS skills are really bad! I've extended to include all 8x of the sensors IDs and it is working perfectly (far more efficient than my bad logic. Would be fantastic if we could work out how to include the Battery % as well.
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Good evening @rjblake

As promised yesterday, I should look to the Battery information.
With the sensors (udevice), you are able to send information about the Battery status.

Unfortunately, this information is only available in Setup > Devices.

See this screenshot:

Screenshot_TestTasmota1.png
Screenshot_TestTasmota1.png (42.64 KiB) Viewed 2515 times

The battery information is not visible on the main screen with the sensor information.

If you want that, we have to define a separate "Percentage" sensor for each "Temperature/Humidity" device.
You decide and let me know.

Another thing, is that the combined Temperature/Humidity sensor requires 3 parameters. You selected for the third parameter a fixed value of "0".
The following values are possible:
0, normal
1, comfortable
2, dry
3, wet
These values are dependent on the Humidity. I included in the "Function" node a function to calculate this "Comfort level".

See the screenshot below (I played a little bit with the "Humidity" in order to show every possible value):

Screenshot_TestTasmota2.png
Screenshot_TestTasmota2.png (252.21 KiB) Viewed 2515 times
If you don't want this extra functionality, you simply remove the function and return to the fixed value of "0".

For the complete contents of the 'Function"node, see below:

Code: Select all

// This function sorts the comfort level for Domoticz based on the humidity.

function comfortlevel(hum) {
    
switch (true) {
    case hum > 70: { hum_stat = 3 } break;
    case hum < 30: { hum_stat = 2 } break;
    case hum >= 30 && hum <= 45: { hum_stat = 0 } break;
    case hum > 45 && hum <= 70: { hum_stat = 1 } break;
    default: { hum_stat = 0 } break;
}
return hum_stat;
}


switch (msg.topic) {
    
    case "ATC1abc06":
    msg.payload = {"command":"udevice","idx":809,"nvalue":0,"svalue":msg.payload.Temperature.toString() + ";" + msg.payload.Humidity.toString() + ";" + comfortlevel(msg.payload.Humidity).toString(),"Battery": msg.payload.Battery};
    break;

    case "ATC0e70ed":
    msg.payload = {"command":"udevice","idx":810,"nvalue":0,"svalue":msg.payload.Temperature.toString() + ";" + msg.payload.Humidity.toString() + ";" + comfortlevel(msg.payload.Humidity).toString(),"Battery": msg.payload.Battery};
    break;

    case "ATC9c53be":
    msg.payload = {"command":"udevice","idx":811,"nvalue":0,"svalue":msg.payload.Temperature.toString() + ";" + msg.payload.Humidity.toString() + ";" + comfortlevel(msg.payload.Humidity).toString(),"Battery": msg.payload.Battery};
    break;

    case "ATCbc6b43":
    msg.payload = {"command":"udevice","idx":812,"nvalue":0,"svalue":msg.payload.Temperature.toString() + ";" + msg.payload.Humidity.toString() + ";" + comfortlevel(msg.payload.Humidity).toString(),"Battery": msg.payload.Battery};
    break;
    
    case "Time":
    return null;
    
}
return msg;
Let me know, what you want regarding the "Battery" presentation.

Regards
rjblake
Posts: 142
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by rjblake »

@FireWizard - I had added the 'Comfort' code, but certainly not as elegantly as your function (my coding is really rusty and bad!). The battery level is perfect being available in the Settings->Device. At least I think I can add separate devices with a % if/when I need based on the help you've provided. I'm hoping for an update to Tasmota that will include the actual Battery Voltage, as the devices use CR2032 batteries that have a quick drop off in voltage so the percentage may not be that useful (have yet to see). I'll definitely have to write the Voltage to a separate device in Domoticz. Assuming my logic is not too bad, I'd just add a line for each device along the lines as follows:

Code: Select all

switch (msg.topic) {
    case "ATC1abc06":
        msg.payload = {"command":"udevice","idx":809,"nvalue":0,"svalue":msg.payload.Temperature.toString() + ";" + msg.payload.Humidity.toString() + ";" + comfortlevel(msg.payload.Humidity).toString(),"Battery": msg.payload.Battery};
        msg.payload = {"command":"udevice","idx":899,"nvalue":0,"svalue":msg.payload.BatteryVoltage.toString()};
        break; 
Where 899 is the actual device id in Domoticz and msg.payload.BatteryVoltage is the MQTT message for the voltage. I can't thank you enough for the awesome help and insights you have provided. I definitely owe you some beers
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Hello @rjblake,
Assuming my logic is not too bad, I'd just add a line for each device along the lines as follows:
No , if you do it that way, the first msg (with Temperature and Humidity) is replaced by the second before it is written to the next node.

Do it as follows:

Declare at the top of the function:

Code: Select all

msg1 = {};
msg2 = {};
Replace your first message with msg1 instead of msg
and the second msg with msg2

Finaly end with

Code: Select all

return [[msg1, msg2]];
I do not know if you receive from MQTT msg.payload.BatteryVoltage, as I did not see it in your previous post.

Best regards
Last edited by FireWizard on Saturday 13 February 2021 11:18, edited 1 time in total.
rjblake
Posts: 142
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by rjblake »

Hi @FireWizard - my bad, forgot to add the msg1 & msg2 when I copied/pasted. I don't know what the msg.payload.BatteryVoltage will be exactly, or if they even change Tasmota to include this, but will adjust if this is supplied. Your supplied Node Red code & flow are working perfectly, so many thanks again.
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by sailmich »

Hello I'm running my beta domoticz on a RPi 2 with lots of zwave and enocean devices. Now I would like to use also WLAN thermostat with mqtt.
In console I get followed information when subscribed to my WLAN thermostat.
I would like to use temperature, targetTemperature and state in Domoticz to build my own heating system.
Spoiler: show
thermostat_wz/tele/log notice: Device state changed -> send device state... thermostat_wz/stat/things/thermostat/properties
thermostat_wz/tele/log notice: Send actual device state via MQTT thermostat_wz/stat/things/thermostat/properties
thermostat_wz/stat/things/thermostat/properties {"idx":"999","ip":"192.xxx.xxx.xx","firmware":"1.19.beta1-fas","switchBackToAuto":true,"temperature":23.50,"targetTemperature":22.00,"deviceOn":true,"schedulesMode":"auto","holdState":"scheduler","ecoMode":false,"locked":false,"mode":"auto","action":"idle","state":"off","mcuId":"IAYz2WK1th0cMLmL1.0.0"}
thermostat_wz/stat/things/thermostat/properties/switchBackToAuto true
thermostat_wz/stat/things/thermostat/properties/temperature 23.50
thermostat_wz/stat/things/thermostat/properties/targetTemperature 22.00
thermostat_wz/stat/things/thermostat/properties/deviceOn true
thermostat_wz/stat/things/thermostat/properties/schedulesMode auto
thermostat_wz/stat/things/thermostat/properties/holdState scheduler
thermostat_wz/stat/things/thermostat/properties/ecoMode false
thermostat_wz/stat/things/thermostat/properties/locked false
thermostat_wz/stat/things/thermostat/properties/mode auto
thermostat_wz/stat/things/thermostat/properties/action idle
thermostat_wz/stat/things/thermostat/properties/state off
thermostat_wz/stat/things/thermostat/properties/mcuId IAYz2WK1th0cMLmL1.0.0
thermostat_wz/tele/log trace: sending heartBeatCommand
thermostat_wz/tele/log trace: Heap Info HeartBeat: MaxFree: 22976
thermostat_wz/tele/log trace: commandCharsToSerial: 55 aa 00 00 00 00, ChckSum 0xff
I tried to do it like descriped on the first page but didn't work. I use yaml because then I get all values. With json I don't get state. I need a little help with the command to domoticz. In this case for sending room temperature to my dummy temperature device in domoticz.
Bildschirmfoto vom 2021-02-18 19-04-34.png
Bildschirmfoto vom 2021-02-18 19-04-34.png (15.99 KiB) Viewed 2465 times
Bildschirmfoto vom 2021-02-18 19-03-27.png
Bildschirmfoto vom 2021-02-18 19-03-27.png (23.12 KiB) Viewed 2465 times
Bildschirmfoto vom 2021-02-18 19-29-46.png
Bildschirmfoto vom 2021-02-18 19-29-46.png (8.99 KiB) Viewed 2465 times
Any help appreciated!
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Hi, @sailmich,

Could you use the following content in your "Function" node:

Code: Select all

msg.payload = {"command":"udevice","idx":325,"nvalue":0,"svalue":msg.payload.toString()};
return msg;
If you need more support. let me know.

Regards
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by sailmich »

Hello FireWizard, thanks a lot for your help! toString() did it.
For the beginning I have two dummys one for temperature and one for targetTemperature. When I change the targetTemperature at WLAN thermostat the value of dummy device change also :) Now I would like to change the targetTemperature from within domoticz. The dummy idx 422 is a thermostat selector. I can't get it together :(
Bildschirmfoto vom 2021-02-19 20-20-50.png
Bildschirmfoto vom 2021-02-19 20-20-50.png (23.58 KiB) Viewed 2451 times
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Hello @sailmich,

I'm sorry to say, that I'm not sure that I understand your question.

Let me explain.
For the beginning I have two dummy's one for temperature and one for targetTemperature.
What I understand, is that you created for test purposes 2 "Dummy Sensors" in Domoticz.
1. Temperature sensor, which is functioning with the previous answer.
2. A Temperature sensor or a Thermostat Setpoint. I assume a Thermostat Setpoint?
When I change the targetTemperature at WLAN thermostat the value of dummy device change also
So you can read the value of your WLAN Thermostat into Domoticz? The correct device?
Now I would like to change the targetTemperature from within domoticz.
If you change the Thermostat Setpoint ( I assumed you have as device created a Thermostat Setpoint, as you cannot change anything, if you use a Temperature Sensor) you want to send the target temperature (setpoint) to your WLAN device?
The dummy idx 422 is a thermostat selector. I can't get it together
The IDX 422 is the IDX of the Thermostat Setpoint.

Can you confirm, that we talk about the device as shown below?

Screenshot_Panasonic6.png
Screenshot_Panasonic6.png (65.44 KiB) Viewed 2447 times
I assume, that if you operate the Thermostat Setpoint selector, that you want to send data FROM Domoticz to your WLAN Thermostat?

So far (and the image of Node Red confirms this) you have only send messages from your Temperature+WZ to Domoticz (topic: domoticz/in)idx; 422.
Can you inform me, what your WLAN Thermostat expects to receive (which MQTT topic and how should the payload look like?)?

Awaiting your response.

Best regards
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by sailmich »

Hello@FireWizard,
my fault I'm not clear enough. Lack of language and technical knowledge :( . I really appreciate your help!
My thermostat Setpoint device with idx 422.
Bildschirmfoto vom 2021-02-20 07-25-05.png
Bildschirmfoto vom 2021-02-20 07-25-05.png (24.13 KiB) Viewed 2439 times
My actual flow.
Bildschirmfoto vom 2021-02-20 07-46-44.png
Bildschirmfoto vom 2021-02-20 07-46-44.png (27.15 KiB) Viewed 2439 times
The part to Domoticz/in is working.
This is what I put into Domoticz/out.
Bildschirmfoto vom 2021-02-20 08-06-22.png
Bildschirmfoto vom 2021-02-20 08-06-22.png (18.41 KiB) Viewed 2439 times
For me it is not clear how to get the value from domoticz to my WLAN Thermostat.
Where and how I have to put the code in the flow.
Cheers
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Hi, @sailmich
my fault I'm not clear enough. Lack of language
If this is a real problem, to express yourself in the English language, you may send me a PM in German.
I can read it. No problem. But in this case it would be better to write in German and use 'Google Translate" to translate it to English.

Then everybody on this forum can read it and learn from it.
technical knowledge
You are going to learn, I'm sure.

Okay,

It is good to know that we talk about the same device.

Let me explain a few things first.

If you decide to use MQTT, you should realize that this is a publish/subscribe protocol, which means that a device publishes a message to a MQTT server, sometimes also called a broker, with a topic name. If one or more other devices subscribe(s) to the same topic name, they will receive that message.

Domoticz publishes its messages under the topic name "domoticz/out" (without the quotes) and subscribes to the topic "domoticz/in"

What you want to achieve is that a message published by your WLAN thermostat is converted in a proper way, so that Domoticz can understand it.

Let look to your flow:

First we receive data by MQTT from your WLAN Thermostat. I wonder how this data looks like. So my question is. Can you connect a "Debug" node and make a screenshot of what you receive by MQTT from your WLAN Thermostat, And send a screenshot.

Then we go through a yaml node. I wonder if that is necessary, but I need to see the output of the "Debug"node first.
Then we go to a "Function" node, where we convert the data in a suitable payload for Domoticz and send that to domoticz/in
As said Domoticz subscribe to domotiz/in and as long as you publish to domoticz/in in a suitable format, it works. You have seen that already.
But you send the same data to domoticz/out. That does not work. Normally only Domoticz may publish messages to domoticz/out.

These should be handled with another application.

So in your case, we will have two flows:

1. FROM the WLAN Thermostat TO Domoticz IN (domoticz/in)
2. FROM Domoticz OUT (domoticz/out) TO your WLAN Thermostat.

First we will clean up your flow from the thermostat to Domoticz.

If I look to your server, I see the Server Name is MQTTHeizung. Your are free to select any name, but this server has no relationship with ONLY heating.
The topic is for the incoming message to Domoticz domoticz/in, if you use the default, and for the outgoing messages domoticz/out

So clean up that first, but let's do it later.
Lets us take first the complete flow from the WLAN Thermostat to Domoticz. I like to see it, in spite you said, it works.

Regards
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by sailmich »

Hello FireWizard,
I changed MQTTHeizung to MQTTRpi. I just want to use mqtt for my heating system! taught it is a good idea to call it after what I use it for. I'm aware that I can use it for many other devices. Here is my debug print.
Spoiler: show

Code: Select all

thermostat_wz/stat/things/thermostat/properties : msg.payload : string[298]{"idx":"999","ip":"192.xxx.xxx.xx","firmware":"1.19.beta1-fas","switchBackToAuto":true,"temperature":23.50,"targetTemperature":20.00,"deviceOn":true,"schedulesMode":"auto","holdState":"scheduler","ecoMode":false,"locked":false,"mode":"auto","action":"idle","state":"off","mcuId":"IAYz2WK1th0cMLmL1.0.0"}
This is my flow now.
Bildschirmfoto vom 2021-02-20 17-47-57.png
Bildschirmfoto vom 2021-02-20 17-47-57.png (13.44 KiB) Viewed 2423 times
I changed yaml to json because it works too with temperature and targetTemperature.
Cheers
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Hello @sailmich,

I clearly understand now, what your intentions are.

First, you have removed the yaml node and replaced it by a JSON node. That is a normal way to do so.
It is even possible to remove the JSON node, if you edit the MQTT input node and replace in the Output "autodetect (string or buffer) with "a parsed JSON object". That is what I did and it saves a node.

Screenshot_thermostat1.png
Screenshot_thermostat1.png (71.14 KiB) Viewed 2416 times

The result after the incoming MQTT node you see in the first message.
You said earlier that you would like to see, the temperature, the targetTemperature and the state in Domoticz.
Regarding the state, what virtual device have you planned to use and what is the IDX of it?

I modified the "Function" node to send two messages, instead of one. You see them at the last two messages in the Debug screen.

At the end we publish the data to a MQTT Output node under the topic domoticz/in and Domoticz cab read that data and will update its virtual sensors as soon as new input is received.

If you remove the two Debug nodes, it is only MQTT In ==> Function node ==> MQTT Out

See the complete flow below. Copy it. paste in in the "Import" window and Import it.

Code: Select all

[{"id":"c4018042.b8c4a","type":"debug","z":"68896a5a.1b56e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":140,"wires":[]},{"id":"7460aa1d.674a04","type":"mqtt in","z":"68896a5a.1b56e4","name":"From WLAN thermostat","topic":"thermostat_wz/stat/things/thermostat/properties","qos":"2","datatype":"json","broker":"f9f13036.e28b58","x":800,"y":200,"wires":[["c4018042.b8c4a","3cbe710b.9dc30e"]]},{"id":"3cbe710b.9dc30e","type":"function","z":"68896a5a.1b56e4","name":"","func":"msg1 = {};\nmsg2 = {};\nmsg1.payload = {\"command\":\"udevice\",\"idx\":325,\"nvalue\":0,\"svalue\":msg.payload.temperature.toString()};\nmsg2.payload = {\"command\":\"udevice\",\"idx\":422,\"nvalue\":0,\"svalue\":msg.payload.targetTemperature.toString()};\nreturn [[msg1,msg2]];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1020,"y":200,"wires":[["64940c6b.232acc","baa0bd5f.a0bf18"]]},{"id":"64940c6b.232acc","type":"debug","z":"68896a5a.1b56e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":140,"wires":[]},{"id":"baa0bd5f.a0bf18","type":"mqtt out","z":"68896a5a.1b56e4","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"f9f13036.e28b58","x":1210,"y":200,"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":""}]
Do not forget to replace the MQTT server, currently 'localhost', with yours.

The next step will be to send the data from the thermostat (IDX 422) to your WLAN

Awaiting your response.

Regards
User avatar
FireWizard
Posts: 1762
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]

Post by FireWizard »

Hello @sailmich,

I googled a little bit and it looks that this is your WLAN Thermostat:

https://github.com/fashberg/WThermostatBeca

Can you confirm?

If so, then it is possible to modify the set point of your thermostat with:
mosquitto_pub -h mqtt -t thermostat_wz/cmnd/things/thermostat/properties/targetTemperature -m "23.5"
If so, can you confirm?

Regards
sailmich
Posts: 235
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Get sensor values with MQTT into Domoticz [Solved]

Post by sailmich »

Hello FireWizard,
Bildschirmfoto vom 2021-02-20 19-28-08.png
Bildschirmfoto vom 2021-02-20 19-28-08.png (7.56 KiB) Viewed 2408 times
That work!
Yes it's one of these thermostat they have all the same inside just other label.
I use mosquitto_pub -h mqtt -t thermostat_wz/cmnd/things/thermostat/properties/targetTemperature -m "23.5" in a console and it changed idx 422 and WLAN thermostat :D
Cheers
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests