I have some key temperature sensors that I use in my central heating automation.
I want to send a warning when any of those sensors haven’t sent its readings to HA in the last say, 10 minutes.
According to HA docs, it is useless to use last_updated attributed in my case, and there is no last_changed one as far as I can see.
RFLink sensor platform does not provide fire_event option as RFLink switch does.
Thanks for your reply.
The thing is that sensor relies upon last_updated attribute, which according to the documentation:
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.
In case of a temperature sensor, for example, its state won’t be updated as long as the temperature remains the same and we’ll get false positives.
Here is a workaround idea, it’s a bit of a hack.
Create an automation which every 6 mins sets the sensor value to -1, this would be set back to the real temperature on the next reading. But if no reading is made, it will stay at -1.
Then have an automation triggered by the sensor going to -1, with the condition it sleeps for 4 mins before checking again to make sure it’s still -1.
This would then mean the automation would be true and could perform your action.
It would mean making sure your heating automation effectively ignores the -1 value, to avoid it turning on the heating every 6 mins regardless of the actual temperature.
Or depending on how sensitive your temperature sensor is, you could create an automation which triggers if the temperature does not change for 10-20 mins, if you can measure to parts of a degree then should mean plenty of thermal fluctuations to stop the automation running.
I have taken a look at the code and this is what I have seen:
sensor devices can not fire events (as you have said): if self._should_fire_event and identify_event_type(event) == EVENT_KEY_COMMAND:
I believe that RFLink propagates events to HA: self.async_schedule_update_ha_state()
According to the documentation:
state.last_changed This is not updated when there are only updated attributes.
I see two approaches:
extend a sensor with a custom component that can send and extra attribute with a random value. I believe that this will update state.last_updated but not state.last_changed
Every time you check state.last_updated attribute modify one of the sensor attributes hoping that next sensor update will rewrite it and change the state.last_updated. For RFLink devices you don’t have many attributes to modify, maybe you can play around with the name attribute.
I have done a chick test with the developer tools adding a name attribute for one of my RFLink sensors. After a few time, name attribute disapears and state.last_updated attribute gets updated while the state.last_changed remains the same.
By the way, this is not a RFLink sensor issue. This behavior is the ‘normal’ for HA.
You will see the same behavior for any sensor you have (hue, mitemp, yr_symbol, sun…)
Yes, that’s all correct.
I’m not that advanced and don’t know how to extend a sensor with a custom component - are you sure it will work with RFLink?
I don’t quite get how to modify sensor’s attributes - I can do it from UI, but don’t seem to find a way to do it from say, automation.
And what did you do exactly to add an attribute?
I recently noticed that it it is possible to register a listener (by creating a custom component?) to the event bus and be able to analyse any event, thought I might use that approach as a last resort… what do you think? As I said, have no experience with HA custom components development solar, but happy to learn
I mean that this behavior (not updating last_updated attribute for devices) is not a RFLink issue. This is the ‘normal’ behavior for all sensors, so you should not look for a solution in RFLink devices, it is the normal behavior defined by Home Assistant.