Difference between “Last Changed” and “Last Updated” (if any)?

Who can explain what the difference is between the “Last Changed” and “Last Updated” attributes that can be selected as Secondary Information for an entity on a Lovelace card?
I always assumed that “Last Changed” was the moment that the value was modified and “Last Updated” was the moment that another (possibly not changed) value was received by HA.
I wanted to use the “Last Updated” attribute to check whether the sensor value was still received within a certain timeframe. However, it looks like this is not how it is working.

As a test I added an Entities card with two entries of some sensors, each with both the “Last Changed” attribute and the “Last Updated” attribute selected. I now always see the exact same information for both attributes for every sensor.
Both attributes appear to only reset to “Now” when the value is changed, even though I am sure that some sensors are sending their unchanged value more often.
This are some examples:

LC-LU-test5

LC-LU-test7

LC-LU-test9

On the State Objects page these two state objects are specified:

state.last_updated
Time the state was written to the state machine in UTC time.
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 in the state machine in UTC time.
This is not updated when there are only updated attributes.
Example: 2017-10-28 08:13:36.715874+00:00.

Unfortunately these descriptions are (at least for me) rather cryptic: I don’t understand what is meant by “Note that writing the exact same state including attributes will not result in this field being updated” and “This is not updated when there are only updated attributes”.
Who can shed some light on this and can give an example of when the two attributes would be different for the same sensor?
And is it possible somehow to make it visible on the Lovelace frontpage when an (even unchanged) sensor value was last received?

1 Like

If you have a sensor with temperature as the state and humidity as an attribute, then an update with the same temperature but a different humidity will update last_updated but not last_changed, as only the attribute has been updated.

The four possibilities for an update:

  • Temperature changed, humidity changed → both times changed (state change)
  • Temperature static, humidity changed → only last_updated changed (attribute change only)
  • Temperature changed, humidity static → both times changed (state change)
  • Both static → neither time changed
5 Likes

Thank you @Troon.

OK, so there are occasions where there will be a difference between last_updated and last_changed.

But now I have to understand the difference between a state and an attribute: in my original post I am using the word “attribute” differently (incorrectly?) than is meant here.

All these different terms like state, attribute, object, entity, value etc. are confusing me…

I have several sensors that give both a temperature and a humidity value, but these values both appear in Home Assistant as separate entities, and not as attributes?

As far as I know I have never up to now seen a sensor with one main value (the state?) and some secondary values (attributes?). Is that how this would look like?

Still, is there a possibility to somehow make it visible on the Lovelace frontend when an (even unchanged) sensor value was last received, to check the connection?

It’s explained in the link you posted (States documentation).

Here’s my climate entity. All entities have exactly one state and zero or more atrtibutes:

Read this: State Objects - Home Assistant

What sensor are you wanting to inspect? Do you have any control over what is sent?

1 Like

I’d like to add that quite a few integrations add a last_update or any change date/time related stuff in the attributes too which makes it often quite hard to find out what/when

Yes, thank you @Taras, I read that page, but still find it difficult to fully understand.
But it is coming slowly :wink:
I now have a better understanding of the difference between a state and an attribute.
This is from the Home Assistant “State” page:

So this sensor entity has the temperature as state and some additional info as attributes (no humidity in this case).
So there are sensors that show the temperature there as state and the humidity as attribute?

Thanks @Troon !
That is interesting to see.
The sensor I wanted to monitor is a temperature and humidity sensor from a Lidl Auriol weather station.
It works via RF 433 MHz and I am receiving the data via an RFXtrx, but I am not sure about the reliability of the connection.
Of course I can look at the HA logs with the RFXtrx logging level set as Debug, but I hoped to be able to use the last_updated info to make it directly visible in Lovelace.

Yes. However, Home Assistant’s core development team prefers that an integration produces separate sensor entities (for example, one reporting temperature and a separate one reporting humidity) as opposed to a single sensor with multiple attributes reporting humidity, wind speed, rainfall, etc.

Why? Because an entity’s history (and long-term statistics) is exclusively for its state value not for any of its attributes. To be able to record the history of a sensor’s attribute, you would have to create a Template Sensor (reporting the attribute’s value). That’s more work for the user so it’s preferable to have the integration report various characteristics of the device (for example, energy, power, voltage, current, etc) as separate sensors.

That was just an example — I could easily make one if I wanted to. It’s more straightforward to have separate sensors for simple cases like that.

My typography (underlined state and slanted attribute) isn’t a convention — it was just to make my post hopefully a bit easier to read.

Also, last_changed and last_updated get reset to the current time if you restart HASS so using them for automations may not be possible.