RFLink sensor - how to determine when it received data for the last time

Hi All,

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.

Any other ideas?

Check out this template sensor:

Note however that sensor.date__time has changed to sensor.date_time in the last update.

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.

Or I’m missing something?

Yes that false positive could definitely happen.

If you are willing to change sensors the ESPhome devices can send heartbeat and status messages.

Well, I use 433MHz sensors and Arduino MEGA with RFLink as a 433Mhz->MQTT gateway.
Not sure I’m ready to change my sensors.

The thing is rflink component receives and distributes events so it should be possible to listen to them, I just don’t know exactly how…

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.

What service do you call to set a (read only?) sensor value?

It’s not read-only, just tested it

Well, I’d rather do it the following way:

  • get current value
  • set sensor’s value to current value + say, 0.5
  • set the original value

Is should kind of do the trick, but will create a lot of unnecessary jitter, not sure how well the heating component can cope with it.

Again, I hope there is a way to listen to the original rflink events and do the job in parallel without affecting the sensors themselves.

What service did you call to write to a sensor?

I just used Set state in developer tools (under the main menu)
A quick search reveals this

1 Like

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:

  1. 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
  2. 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.

I hope it works for you.

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 :wink:

What do you mean?

Well, it should work with any device.

The same as you, modify it from UI.

I have not played with listeners, but it seems a good idea, although it may be a little complex to start with something like that. I don’t know.

BUT, I have seen that there is another attribute you can play with:

Maybe you can try it first.

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.

Good luck.