Is there a way to check for an MQTT message NOT received? Like if the topic receives no messages for an hour?
Thanks
Is there a way to check for an MQTT message NOT received? Like if the topic receives no messages for an hour?
Thanks
Could you not just check whether the entity that is connected to this topic received an update in the last hour?
Sadly not, I considered doing that first. Sometimes the MQTT message is the same as the old one meaning it doesn’t get changed. Although if some ‘attribute’ or parameter receives a new ‘updated’ state all the same…?
As far as I can remember, the last updated attribute doesn’t care wether the state is the same as before or not, it will be updated anyway. Can’t check right now.
Can you maybe explain what your problem exactly is and what the end goal of this is? Maybe there are other, easier solutions.
state.last_updated | Time the state was written to the state machine. Note that writing the exact same state including attributes will not result in this field being updated. Example: 2017-10-28 08:13:36.715874+00:00. |
---|---|
state.last_changed | Time the state changed. This is not updated when there are only updated attributes. Example: 2017-10-28 08:13:36.715874+00:00. |
I don’t think there is a way to detect missing updates from a sensor that rarely changes. i ran into this for a flood sensor. In a happy world it would never report a new value (i.e. that my water heater is leaking). What i did was change the MQTT client side to report a second topic which is a counter that increments with each report. This is a heartbeat sensor for the client. The last_updated value for the heartbeat sensor is always the time of the last report.
What we really need is an optional watchdog event in core that can be configured for any sensor. Polls or reports of the sensor would reset the watchdog.
You may wish to consider using the expire_after option.
expire_after integer (optional, default: 0)
Defines the number of seconds after the sensor’s state expires, if it’s not updated. After expiry, the sensor’s state becomes
unavailable
.
For example, if you specify expire_after: 3600
it means if the sensor doesn’t receive a value within 1 hour of the previous one, its state will be set to unavailable
.
Wheels spinning. Now i just need a notification based on that value.
Simply create an automation with a State Trigger using to: 'unavailable'
In some cases, at startup some sensors may have a brief initial state of unavailable
. I don’t think that will be the case here but you should know it’s a possibility. As a result, you might get a notification on startup informing you that the sensor’s state is unavailable
. There are simple techniques to suppress reporting this ‘nuisance event’ and we can explore them if you encounter the problem.
now i need to implement expire_after for Insteon motion sensors.