I have a TH10 who is managing many temperature sensors (1-wire) and who send values each minute to Home Assistant via MQTT (Mosquito). This is working well since 3 years.
I have a device (Rasp Pi 5 who manage a Skycam) who needs to pick up 1 value from MQTT (outside temp). Everything is set well on this side, I checked.
But the value is at 0, null.
I searched and found that on MQTT, the value, between each new value (from my TH10) is null / 0.
And so, I need to enable the RETAIN option at TRUE.
I tried, in the configuration.yaml file, like this:
- name: "Temperature"
unique_id: "73948473"
state_topic: "th10/outside"
value_template: "{{ value if value is defined and value !=0 else this.state }}"
device_class: "temperature"
unit_of_measurement: "°C"
state_class: "measurement"
The TH10 is not sending 0 / null, it’s always sending a good value.
But MQTT dones’t keep value between 2 values sent from the TH10, so my other device sees 0/null, it’s why I need to activate RETAIN, to keep the value in “memory” on HA, like that mon other device can catch/receive the value.
This can set a retain also.
Troubleshooting MQTT? MQTT-Explorer can help you be successful!
If you have Add-ons available, try adding this Add-on repository to your Add-on list. GitHub - GollumDom/addon-repository.
With this you can see that the broker sees and likely find the bug.