-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set last_reset for integrated entities in IoTaWatt #65143
Conversation
Hey there @gtdiehl, @jyavenard, mind taking a look at this pull request as it has been labeled with an integration ( |
For entities which integrate over time (like energy in watt hours) the iotawattpy library uses the beginning of the year as start date by default (using relative time specification "y", see [1]). Since PR home-assistant#56974 state class has been changed from TOTAL_INCREASING to TOTAL. However, the relative start date of "y" causes the value to reset to zero at the beginning of the year. This fixes it by setting last_reset properly, which takes such resets into account. While at it, let's set the cycle to one day. This lowers the load on IoTaWatt (fetching with start date beginning of the day seems to response faster than beginning of the year). [1]: https://docs.iotawatt.com/en/master/query.html#relative-time
70ff794
to
a635d55
Compare
It seems that the entities with the accumulated suffix (introduced with #55512) are not affected by this problem, which make sense since those query energy values only in time slices. That said, I am question why we need to have two entities for energy (watt hours), at least today: When using a fixed starting point, there should be no lost data (unless HA is offline more than a period length, which would be 1d in this case). The accumulating sensor seems to be somewhat of a re-implementation of features available with state_class @emontnemery @jyavenard thoughts? |
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Accumulated sensors do no measure exactly the same period as the energy one. They round to the previous minute while energy the value calculated since the beginning of the year up to the current query time. It is possible that they accumulate overtime some rounding error as by default it’s using only 3 digits accuracy. But that should be barely measurable over an hour or a day as used by the energy screen |
I understand the difference, but do you feel there is still a need for that accumulating sensor (now that there are integration sensors on IoTaWatt side)?
Surprisingly, my screenshot show a difference of 0.3kWh at a daily use of 6kWh, that is about 5%. Not huge, but also somewhat surprising that rounding leads to such a big difference... I did not restart or do anything to the instance at that day (I picked that day because I know I was not at home) 😄 |
For most, I'd say we now longer need the accumulating sensor. However, issue with IotaWatt integration side is that they never reset nor can you reset them. The advantage of the accumulated sensor is that their lifetime is entirely controlled by HA, I can delete their value and they will start accruing at the time I want. Hence, why I've kept the accumulated sensors, because selfishly, I use and need them. |
So far we asked for a yearly total, so they did reset once a year.
Do you use the state/values of the accumulated energy entities directly? If so, what is the use case for that?
I see, but with that change we ask for the daily total, which leads to a reset every day. You will still get a peak at the hour you add a new sensor, but it won't be as bad as before. So would this change then cover your use case? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Breaking change
Proposed change
For entities which integrate over time (like energy in watt hours) the
iotawattpy library uses the beginning of the year as start date by
default (using relative time specification "y", see 1). Since
PR #56974 state class has been changed from TOTAL_INCREASING to TOTAL.
However, the relative start date of "y" causes the value to reset to
zero at the beginning of the year.
This fixes it by setting last_reset properly, which takes such resets
into account.
While at it, let's set the cycle to one day. This lowers the load on
IoTaWatt (fetching with start date beginning of the day seems to
response faster than beginning of the year).
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: