Hi - I’ve been working on an automation to give me alerts when one of my sensors hasn’t been seen in a while (dropped offline, etc). I initially thought that the last_updated value would work for me, but unfortunately some of the items I want to monitor are very stable, so the actual value doesn’t change often. They still publish the value via mqtt, but because it is the same, neither last_updated or last_changed is updated.
I’m looking for some feedback from the devs on adding another field in the state object, maybe called ‘last_seen’ or something. My thought is that it would be only saved in the state machine, not be logged/saved, and not generate any events. That way, an entity that reports the same value as before doesn’t trigger any events, but still has a record that it has been heard from.
Does this sound like a reasonable way to go about this? I have a patch in my source tree that is working for me that I can clean up and submit in a PR.
I could really use a feature like this. I built in a similar heartbeat pulse using MQTT and couldn’t always rely on last_updated or last_changed because if they are not updated if the value of the payload is the same to the last publish.
Hi, @proddy - I did submit a PR to add this, but was told it wasn’t the right way to do it. The recommended solution is to add ‘force_update: true’ to the sensors that you want to keep track of - it will cause home assistant to log a state change any time an update is received, even if the state is the same.
One thing to keep in mind - you might want to exclude that sensor from the recorder component if it updates very frequently. It will be logged every time it reports, not just when it changes, so if you have a lot of those sensors, it will grow the recorder database quite a bit.
I’m very new to home assistant and I am struggling. I want to use the advice given in this thread however I have no idea where you add the line force_update: true? Any help will be welcome.
is there a way to apply this to ALL sensors?
Also is it possible for the database to only log the first time the value was received, and then the last timestamp same value was received? In this way we would lose no data, and the database would not grow. More writes, yes, but not a huge problem.
It looks like in current design of the database only logs the first timestamp and then does nothing if more datapoints come with the same value. This is lossy, because there is no way to see if the sensor is dead, if there are connection issues etc.