Does ESPHome work with the new last_reported feature?

I have a bunch of flow sensors on my pool that I would like to use the statistics integration on, however these break overnight when flow is zero due to: Statistics sensor doesn't handle zero values correctly · Issue #67627 · home-assistant/core · GitHub

It sounds like the new last_reported would solve this but from cursory testing ESPHome sensors seem to operate in one of two modes:

  1. Don’t update Home Assistant if the sensor value didn’t change
  2. Set force_update which updates Home Assistant on every sensor update while ALSO setting the force_update flag on Home Assistant.

It seems like with the new option there needs to be a 3rd choice of “always notify Home Assistant on sensor read but don’t set the force_update flag” so that the last_updated field on the sensor can be correctly incremented.

OR I’m missunderstanding how it all works and need to tweak something else :slight_smile:

I have just spent the morning looking at this problem when using statistics integration and no change in state creating unknown … to solve I used the “old” method of template trigger and timestamp … which works … but now find I could have done this another way … will fiddle more and report!! Thank you for pointing out and asking

Setting force_update on my ESPHome sensors solves the statistics integration problem as well but I’m pretty sure that is going down the anti-pattern of writing an event to the DB every interval.

Querying the HA Database directly makes it look like last_reported is not currently working with the ESPHome Integration. The last_reported field for a sensor who’s value doesn’t change is only incremented when force_update is set.

Digging through the code I’m thinking this is an issue in the ESPHome Integration vs the ESPHome Addon/Device code.

Maybe core/homeassistant/components/esphome/entry_data.py at 1cea22b8bae81c1dc31b8aacfd3587a03eca07ff · home-assistant/core · GitHub is the issue?

This seems to short-circuit data updates if the state hasn’t changed.