Unexpected bahavior of state.x.last_updated

I would expect that states.sensor.schlage_link_mini_keypad_rfid_access_control_29_9.last_updated

Would give me a timestamp whenever there is an explicit (so no just polling but due to a user action) update received from the Zwave network from this sensor. Even if the sensor state/value (let’s say 255) is the same as it already was.

Is this expected behavior? Is there another way to catch the latest update (even if it is the same state/value)?

1 Like

if you make an templatesensor with that as template it will normally update every time the sensor is updated.
but only if you give explicitly identify the entityID which must cause the update.

but my experience is that last_updated and last_changed very often are just the same.

i think that in most platforms there is a check if a value is the same and then doesnt change/update the value (for performance reason?)
but then they forget to update the updated time.

Hi Rene,

Trying to follow you but not sure how to implement? Could you give me an example?

i have my templatesensors for controle like this:

  - platform: template
    sensors:
      controleaquariumtemp:
        friendly_name: Temp grote aquarium links
        value_template: '{% if states.sensor.arduino_kelder_1_1.last_updated is undefined %}{{"0:00"}}{% else %}{{ states.sensor.arduino_kelder_1_1.state + " (" + ((as_timestamp(states.sensor.date__time.last_updated)-as_timestamp(states.sensor.arduino_kelder_1_1.last_updated))|timestamp_utc)[11:19] + ")"}}{% endif %}'
        entity_id:
          - sensor.date__time

that gives me always the last time the (mysensors)sensor has send a value.
but then again, my sensors send only a new value if something changes.

but i see always the same times for last_updated and last_changed.

Ah, thanks. Will try this as a workaround.

Would expected behavior of state.last_updated not be the actual last update timestamp -independent- if the value was identical of the previous value (last_changed would capture this)?

Hi, I agree with you @Tyfoon.

But the documentation at State objects - Home Assistant says:

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: 14:10:03 13-03-2016.

I think it should be changed to:

state.last_updated Time the state was written to the state machine. Note that writing the exact same state WILL result in this field being updated. Example: 14:10:03 13-03-2016.

The last_updated attribute in the state is the only way to know if the state is reliable or not. For example, I don’t want to use the temperature if it’s last updated 2 days ago. Sensors can go down we have to deal with the failures. Could it be changed?

Hi

Does this mean that to reliably to get last motion from a sensor it is better to create an automation that updates a custom sensor?

Cheers,

//JM

Now you have the expire_after parameter in the MQTT sensor component: