Newbie here, and I’m at a bit of a loss with a Sonoff ZigBee Bridge operating Tasmota 9.5.0.3 and a Sonoff SNZB-02 Sensor reporting, trough the bridge, via MQTT.
The sensor is correctly paired with the Bridge (acting as Coordinator) and the data is sent via MQTT in the form of:
MQT: tele/tasmota_zb/SENSOR = {"ZbReceived":{"0xB585":{"Device":"0xB585","Temperature":30.65,"Humidity":79.69,"Endpoint":1,"LinkQuality":118}}}
On Home Assistant (running in ESXI thanks to the readly available image) the Mosquitto component is correctly receiving data over MQTT from the Bridge.
In Configuration I have the following:
- platform: mqtt
name: "ZB_Est_Temperature"
qos: 1
state_topic: "tele/tasmota_zb/SENSOR"
value_template: "{{ value_json['ZbReceived']['0xB585']['Temperature'] }}"
unit_of_measurement: "°C"
availability_topic: "tele/tasmota_zb/LWT"
payload_available: "Online"
payload_not_available: "Offline"
device_class: temperature
- platform: mqtt
name: "ZB_Est_Humidity"
qos: 1
state_topic: "tele/tasmota_zb/SENSOR"
value_template: "{{ value_json['ZbReceived']['0xB585']['Humidity'] }}"
unit_of_measurement: "%"
availability_topic: "tele/tasmota_zb/LWT"
payload_available: "Online"
payload_not_available: "Offline"
device_class: humidity
I can read the sensor latest data on my Lovevalce Card, but only when the Sensor is sending updated data. If, for example, temperature isn’t changed from last measurement and the MQTT message is just:
MQT: tele/tasmota_zb/SENSOR = {"ZbReceived":{"0xB585":{"Device":"0xB585","Humidity":64.36,"Endpoint":1,"LinkQuality":113}}}
Then I get the " 0°C " value instead of the last know value. I’m pretty sure the sulution is very simple and I’m dumb enough to have missed it, but after reading all the docs I could find I’m still missing it.
One of things I tried, without success, is using a if/then statement to try and filter out the value like this:
value_template: >
{% if "Temperature" in "value_json['ZbReceived']['0xB585']" %}
{{ "value_json['ZbReceived']['0xB585']['Temperature']" }}
{% else %}
{{states('sensor.ZB_Est_Temperature') }}
{% endif %}
I’ve also tried to use this statement, derived from another post here on the forum, but doing so I couldn’t show the temperature value while beeing able to see the latest value in the time chart; this convinced me even more that I’m just “one stupid mistake away” fom learning how to do it.
value_template: >
{% if "Temperature" in value_json["0xB585"] %}
{{ value_json["0xB585"]["Temperature"] }}
{% else %}
{{states('sensor.Temperature') }}
{% endif %}
I’m hoping someone could be kind enough to point me in the right direction to solve this.