WTH, how can I know when the last (unchanged) sensor value was received?

The system is sort of at that point right now with last_updated, however there’s times when the frontend can benefit from this information. Like entities on the map that contain GPS coordinates. The main state essentially doesn’t change if they are still in the same zone, however the GPS coordinates may be bouncing around.

It doesn’t really matter what the name is. In fact, I don’t think we should even discuss the name because it’ll just be another point of contention. We simply just need a new property that doesn’t impact recorder’s recording, that contains the last time a state_object was sent new data from the device.

8 Likes

I have a quick question - it may, or may not be related to this thread. If its not, please redirect me to the correct place. I may also just use the wrong words/terms.

I am looking to display or plot my weight for the last 5 times I weighed myself. This could be 5x times in the last hour, or 5x times in the last 30 days.

The Xiaomi scale is integrated with the BLE sensor. However it always reports my last weight, no matter when that was. So, right now, if I make a card showing the weight sensor, it reports 135lbs, even though I last weighed myself a week ago. The “current” weight should be 0 or not applicable or something.

Is there a way too zero this out after X time, or only report data when it is received, or something?

Thanks for your help.

Home Assistant provides a lot of flexibility around automation triggers. Consequently, a potential solution which might work for some is to use the last_triggered attribute of an automation that’s only triggered when the state of the entity changes.

This won’t work as the triggers OP is referencing are suppressed because state changes do not occur.

I totally agree that the last changed date/time should not be reset when HA restarts. That is not helpful information at the sensor level. There are other ways to determine when HA is restarted. We really want to know when an entity LAST changed which is most likely not when HA was restarted. Perhaps the last changed date/time could be persisted somewhere, if it’s not already, and restored when HA is restarted.

I must say that I had the same problem with the last updated. I thought my sensor is faulty because it sometimes shown 30min on a sensor that sends an update every 1min. This is confusing.
Also I am surprised but it seems there is no way of simply logging values reported by a sensor (just change in value). This leads to a point where it is impossible to know what the actual value was at the exact point in time without some problematic availability logging. Lets say I have 433MHz temperature sensor. It might have weak signal and report at unpredictable intervals. How to setup the availability timeout? It will probably flicker the availability state.
I’m working now on a weather station data logging and charting. The standard charts are limited in their functionality, and it doesn’t look good on those. I switched to plotly (I know it is not officially supported), but changing the line type to e.g. linear distorts the actual data representation, because there are only “change in value” points, not the actual data points. This isn’t such a big deal, it kind of works, but on the other hand simple data logging seems to be a basic functionality that I would expect to exist in such a system. I don’t understand why it isn’t there. Are there any plans of adding that?

4 Likes

I’m looking for a way to make sure my integration is communicating successfuly with it’s endpoint. I found the discussion here which seems to have have become a discussion of semantics.

One example of a specific need is to determine when my Ambient weather station integration is not updating the data we look at. There are two known falut conditions. One the API at Ambient is failing. The other is my station is not connected to Ambient. Trying to develop a framework for montioring all what I consider to be critical sensors and an alert process for them. Another would be the temprature reported by a HVAC thernostat.

I take no sides in that but have not had a case where I was steered wrong by Petro so I appeal to you help define in a language that would be clear the the HA developers understand that there is a need to be able to ensure that information supplied by HA to users is timely and that there is a way to ensure the time accuracy of that data.

1 Like

You can easily add an attribute on your entity that holds the last time you communicated with the API, which in turn will ensure last updated changes. Any integration can do this.

The semantics in this thread are required because OP wants to change a building block of the state machine because he’s unwilling to understand what the property means (not what last_updated implies). Changing this would break many time related things all across HA. Triggers, timers, conditions, durations, you name it. Not including breaking changes for existing templates that users have. It’s not worth the headache to change the current functionality. Adding a new property to the state object would be simple and break nothing.

2 Likes

Wow, it’s almost 2025 and I can’t believe there is still no solution to this “problem” (it works as documented, not a bug, no need to fix… yeah, sure).

1 Like

Because no one is interested in making the change. Anyone can step up to the plate and take this on, even you. This is open source after all. That’s how changes work in open source. If someone is interested in implementing something, they submit a PR and go through the software change process. Since this WTH started, 0 people have attempted to make this change. Maybe you could be the first.

You are right, but only in theory. In practice the vast majority of us cannot make the changes necessary, we do not have the skills required to even begin contemplating what needs to be done.

That is why we must rely on people, like yourself, to solve these issues in a meaningful way. You have previously suggested an alternative solution that is “simple and breaks nothing” while still solving the OPs issue. Why not pick up the gauntlet, even if that simply means raising the issue elsewhere?

Because I don’t want to. I have no need for this. Even if I wanted to, I don’t have the time to maintain it.
Hopefully now you see the downside of open source products. It’s the FIO (Figure it out) philosophy, if you really really really want a feature, you’ll have to figure it out yourself.

I agree. The FIO philosophy is a major downside of open source projects. I’m very surprised though, that this property, which allows to distinguish between a sensor that is not reporting and a sensor that reports the same value multiple times in a row, is not implemented. It’s an important distinction.
What would need to be done? Add one line to the definition of a state? And then add some functionality to every individual integration in HA so the property is actually being used? That effort could be spread over many users of all the integrations. Or is thissomething that should be handled by the core?

Trying to understand, since I don’t have a clue, obviously.

1 Like

For me these are the typical useless discussions in OSS (of course as a developer myself I understand that is not a good idea to change the behaviour of a field from one day to the other but discussions over a year seams to indicate some need). And even if someone implements that feature and provides a MR usually there will be someone who finds a reason why not to add it.

But to add some value to this: At least for zigbee2mqtt there seams to be an option to see that in HomeAssistant.
You first need to enable

advanced:
  last_seen: ISO_8601_local

for zigbee2mqtt in configuration.yaml of zigbee2mqtt (Dont ask me about ISO_8601 or epoch).

I’m not sure if the next step

is still necessary.

You will see it then in HomeAssistant as Attribute of the Entity.

Because there is no generic implementation in HomeAssistant it is not possible to find in the devices tab devices you have not seen for months.

1 Like

Just chiming in to make a note that I have hit this issue with the statistics integration and trying to use a change of humidity in the past 5 minutes as a trigger.

What happens is that the humidity sensor is very stable, and the value is not changing. Then someone takes a shower. The humidity spikes up hard, and I’d really need to capture that original bottom level humidity from which the situation got triggered.

But I don’t, because “it works as specified”. The database doesn’t seem to store the polled humidity values when the value remains the same, and when the statistics integration is working on its 5-minute change calculations, it has no value from the bottom of the humidity graph, even though if I look at the humidity graph in Home Assistant I can see that it draws it mostly correctly in a fashion where the line drawn continues along the not-stored values until the spike up.

But the statistics integration works with the database, not the graph, and when it looks for values in the past 5 minutes, all those times the humidity polled the same old value, went to bit heaven in an acute case of it works as specified.

Now I suppose I could fix all the integrations in home assistant, of course. Or I could fix the core, database, whatever. But alas, I don’t know all the integrations, and there are too many, and I don’t know the core either. So I’m left with the vote button.

I sincerely hope others will take the time, register, and vote. Maybe someday, someone picks this up. Us users, we don’t want to change your beautiful design, it can be as it is, but we want something new - without specifying the “how” in details - that works even a bit better than the initial, beautiful design.

1 Like

This has been implemented as last_reported on the state object.

Will be released in within one of the next few versions of HA. I will update this post when it is fully implemented.

5 Likes

Consider an integration which creates a sensor.
Assume that a corresponding physical object is not changing for some period.
So, the sensor has SAME state & attributes for this period.
Currently DB may contain consecutive records with SAME content (state & attrs) - but with different “last_updated”. Imho “last_updated” should not be changed if a state/attrs do not change - but it happens, and not only on HA reboots. I noticed this behaviour for several integrations.
Now a new property is added - “last_reported”. I wonder - will DB store all records with same content but with different “last_reported”?

read the linked discussion in that blog post, that’s already a concern

2024.4 contains last_reported on the state object.

If you have any questions, please create a new topic in Configuration

{{ states.sensor.temperature.last_reported }}
8 Likes