I have a tasmotized Sonoff with three DS18B20 sensors connected to it. This Sonoff is used to control a fan that is part of an integent ventilation system.
I am able to extract and display the individual sensor data based on the sensor names i.e. DS18B20_1, DS18B20_2 and DS18B20_3.
I would rather extract the values based on the sensor ID’s to be sure of the position of the individual sensors.
My mqtt thing is:
Thing topic sonoff_TH_Thing "Toevoer vent." @ "Tuoro" {
Channels:
Type switch : ventilator [ stateTopic="stat/ventilator/POWER", commandTopic="cmnd/ventilator/POWER", on="ON", off="OFF" ]
Type number : temperature1 [ stateTopic="tele/ventilator/SENSOR", transformationPattern="JSONPATH:$.DS18B20_1.Temperature" ]
Type number : temperature2 [ stateTopic="tele/ventilator/SENSOR", transformationPattern="JSONPATH:$.DS18B20_2.Temperature" ]
Type number : temperature3 [ stateTopic="tele/ventilator/SENSOR", transformationPattern="JSONPATH:$.DS18B20_3.Temperature" ]
}
My items are:
Number Zldr_temp "Temperatuur Zolder [%.1f °C]" <temperature> (Zldr) {channel="mqtt:topic:MqttBrokerTuoro:sonoff_TH_Thing:temperature1"}
Number InblaasTemp "Temperatuur Inblaas [%.1f °C]" <temperature> (Zldr) {channel="mqtt:topic:MqttBrokerTuoro:sonoff_TH_Thing:temperature2"}
Number AanzuigTemp "Temperatuur Buiten [%.1f °C]" <temperature> (Zldr) {channel="mqtt:topic:MqttBrokerTuoro:sonoff_TH_Thing:temperature3"}
I am new to openHAB and this is my first ever use of the json tranformation path. I’ve searched the internet for an answer but could not find one, at least not one that I could understand.
Hi I’ve read that post over and over and tried the solution given there but that does not work for me.
I tried it again but same thing no updated values when I change my thing to :
Thing topic sonoff_TH_Thing "Toevoer vent." @ "Tuoro" {
Channels:
Type switch : ventilator [ stateTopic="stat/ventilator/POWER", commandTopic="cmnd/ventilator/POWER", on="ON", off="OFF" ]
Type number : temperature1 [ stateTopic="tele/ventilatoter/SENSOR", transformationPattern="JSONPATH:$.3C01B6078704.Temperature" ]
Type number : temperature2 [ stateTopic="tele/ventilator/SENSOR", transformationPattern="JSONPATH:$.3C01B607DE10.Temperature" ]
Type number : temperature3 [ stateTopic="tele/ventilator/SENSOR", transformationPattern="JSONPATH:$.3C01B607FA45.Temperature" ]
}
my json string is:
{“Time”:“2020-10-10T20:33:27”,“DS18B20_1”:{“Id”:“3C01B6078704”,“Temperature”:19.4},“DS18B20_2”:{“Id”:“3C01B607DE10”,“Temperature”:19.9},“DS18B20_3”:{“Id”:“3C01B607FA45”,“Temperature”:19.9},“TempUnit”:“C”}
Hi Lester,
That works also for me but when sensor one fails then after a reboot sensor two becomes sensor one, sensor three becomes sensor 2 etc.
Regards Wil
My two cents on that one: I would be afraid of the Sonoff to fail instead of your concerns.
If you really want to go for such a case, do something like this:
Create an ID channel for each sensor and link them with an ID item, the item name should be consistent whith the corresponding linked temperature item ( like temperature1 and ID1).
Create secondary (proxy) items for the temperatures which are not linked to the temperature channel ( temperature_proxy1).
Create a rule that triggers on the change of any linked temperature item. In the rule check wether the ID item name corresponding to the triggering item name does have the correct ID. In this case update the corresponding proxy item with the temperature.
Use only the proxy items to display and persist the temperatures.
I got it to work with a JS transform. The only catch is you’ll need a file for every sensor, unless there is a way to pass an additional argument to the JS transform. Messier than the nice JSONPATH one liner, but cleaner than using a rule I think.
On the thing:
transformationPattern="JS:3C01B6078704.js"
File transform/3C01B6078704.js
(function(message) {
var address = "3C01B6078704"
var data = JSON.parse(message)
for (var key in data) {
if (data[key].hasOwnProperty("Id")) {
if (data[key].Id == address) {
return data[key].Temperature;
}
}
}
return null;
})(input)
That works so I’ve changed mine too. As Willem said, using DS18B20_x is a problem if one fails or drops out. The number changes so this is a much better solution.
Thanks again for your assistance.