sensor:
- platform: mqtt
name: "Lamp Status"
state_topic: "lamp/switch/status"
qos: 0
timeout: 60 <<----- I wish I have this parameter..
Let’s take an example: I have an mqtt sensor and it send critical data in a known interval every 10 seconds.
If the sensor has not sent any data for more than 1 minute, I can suspect that something has gone wrong the system, either the sensor dies, wifi lost, mqtt broker offline, power failure, etc.
As far as I know, currently HA will keep the last sent sensor value forever: that is until the sensor is “online” again and sending a new data/value and replace the old data/value.
I wish there will be a sensor feature so that if the timeout has been triggered, HA can automatically replace the value with something more informative, for example update the value with the text unknown, instead of kept displaying the old data/value, so I can take immediate action properly.
I can achieve that through a very complicated ways (create a dummy mqtt sensor and heavy use of template sensor / templating), and that have to be done for every single sensor.
I think something like timeout feature should make this easier to accomplish that.
Maybe with a template using the {{ states.your.sensor.last_updated }}
Then you can use some jinja filtering to give the relative time, and create an automation with that.
Thanks for the feedback. I tried that. To be exact, I add "relative time" in the template, like this: {{ relative_time(states.your.sensor.last_change) }}
If the received new sensor value remain the same, the “last update” timer keep increasing - it won’t return to zero - even if the “real” sensor keep sending new data (let’s say every 15 seconds).
I also tried {{ relative_time(states.your.sensor.last_change) }} but does not work either.
Below is another real example.
I have a kWh meter sending the reading via mqtt every 15 seconds.
I am expecting the “last updated” timer will return to zero every 15 seconds - but it’s not.