Skip to content

Conversation

root0x
Copy link

@root0x root0x commented Jan 23, 2025

Description

As suggested by #389 this pull request uses ha-historical sensor.

Motivation and Context

If your smart meter fails to report usage data for some time (1 hour+) the integration currently will sum up all of the missing data points into one statistic. This means that potentially multiple hours usage data is logged as one which is incorrect. This pull request uses the ha-historical-sensor to retroactively add the (previously) missing data points and allow for correct statistics

How Has This Been Tested?

Has been running on my home assistant instance for 1 month now

Notes

For this pr to function you need some other fix pr's to be merged so i suggest running from my main branch https://github.com/root0x/ha-hildebrandglow-dcc/tree/main

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@adequatelyrusty
Copy link

@root0x I've been testing this for a few weeks --- it seemingly fixes the bug with missing data due to API failures/timeouts etc...
but it somehow seems to break the 'current' value for the sensors ?

i.e. the 'Energy Dashboard' seemingly shows the correct data throughout the day - however - if I want to now query the actual values - when looking at 'sensor.electric_consumption_today' for example - HA says the current value is 'Unknown'

I've seen a few things about using a 'repair' to fix data sources etc. - but that doesn't seem to affect or fix this.

Have you seen this ? or any guidance

@root0x
Copy link
Author

root0x commented Apr 25, 2025

@adequatelyrusty regarding the unknown current state that is unfortunately part of using ha-historical-sensor. I would recommend reading their documentation as to why this is done. https://github.com/ldotlopez/ha-historical-sensor

Q. Why is my historical sensor in an "undefined" state?.

A. Historical sensors don't provide the current state. Keep in mind that the last state (from some hours ago) is NOT the current state. The current state is unknown.

@adequatelyrusty
Copy link

adequatelyrusty commented Apr 25, 2025

@adequatelyrusty regarding the unknown current state that is unfortunately part of using ha-historical-sensor. I would recommend reading their documentation as to why this is done. https://github.com/ldotlopez/ha-historical-sensor

Q. Why is my historical sensor in an "undefined" state?.
A. Historical sensors don't provide the current state. Keep in mind that the last state (from some hours ago) is NOT the current state. The current state is unknown.

@root0x - is it possible to set the 'current' state to be the last retrieved daily total though (appreciating that it could be somewhat behind timewise)?

i.e. based on the question that follows the one you quoted?

Q. I want to provide current state AND historical data
A. You need to implement two sensors: one for the current state and another one for historical data.
If you are following the data coordinator pattern it should be straightforward

@root0x
Copy link
Author

root0x commented Apr 25, 2025

@adequatelyrusty regarding the unknown current state that is unfortunately part of using ha-historical-sensor. I would recommend reading their documentation as to why this is done. https://github.com/ldotlopez/ha-historical-sensor

Q. Why is my historical sensor in an "undefined" state?.
A. Historical sensors don't provide the current state. Keep in mind that the last state (from some hours ago) is NOT the current state. The current state is unknown.

@root0x - is it possible to set the 'current' state to be the last retrieved daily total though (appreciating that it could be somewhat behind timewise)?

i.e. based on the question that follows the one you quoted?

Q. I want to provide current state AND historical data
A. You need to implement two sensors: one for the current state and another one for historical data.
If you are following the data coordinator pattern it should be straightforward

I would say that it is possible to create a second sensor to just store that data. Feel free to raise a PR on my repo for this.

@mwilky
Copy link

mwilky commented Apr 28, 2025

@root0x so with your changes mentioned here are you able to get accurate hourly usage in home assistant similar to what is shown in the Bright app's hourly view? As in usage per hour, not a total accumulation updating every hour?

@root0x
Copy link
Author

root0x commented Apr 28, 2025

Yes that's correct, it now shows usage for that period not an accumulated usage. If you use the energy dashboard you can get those totals if you want them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants