-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Add iotawatt high-accuracy energy readout sensors #55512
Add iotawatt high-accuracy energy readout sensors #55512
Conversation
Hey there @gtdiehl, mind taking a look at this pull request as it has been labeled with an integration ( |
3556adc
to
62ef2a0
Compare
7a3a0e4
to
9c0c7be
Compare
There were previously two types of sensors: current and energy. The current reads the value that is the average of the last 30s And the energy which is the amount in Wh since the January 1st of the current year. Due to how the iotawatt performs calculation internally, the energy sensors only works with outputs that use a limited set of mathematical operation (e.g. only + and -). More complex ones, such as what you would use to calculate the net energy export and import if you had a net solar system, will read wrong (and read 0 for export). This change adds an extra energy sensor, with a ".accumulated" suffix that will read the last 30s of energy used or produced and progressively add to a permanent counter. This counter would typically always monotically increase or decrease. In order to prevent data from being lost when the iotawatt becomes inaccessible or when the HA instance is offline (such as during an update), the sensor will fetch the missing data from the iotawatt since the last known update upon restart. This requires the iotawattpy 0.1.0 version which was just released. Fly-by fix: remove unused name ad mac_address IotaWattSensor parameters.
9c0c7be
to
c812ec9
Compare
c812ec9
to
4f539de
Compare
Thank you for your contribution thus far! 🎖 Since this is a significant contribution, we would appreciate you'd added yourself to the list of code owners for this integration. ❤️ Please, add your GitHub username to the For more information about "code owners", see: Architecture Decision Record 0008: Code owners. |
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 👍
There were previously two types of sensors: current and energy. The current reads the value that is the average of the last 30s
And the energy which is the amount in Wh since the January 1st of the current year.
Due to how the iotawatt performs calculation internally, the energy sensors only works with outputs that use a limited set of mathematical operation (e.g. only + and -). More complex ones, such as what you would use to calculate the net energy export and import if you had a net solar system, will read wrong (and read 0 for export).
This change adds an extra energy sensor, with an " Accumulated" suffix that will read the last 30s of energy used or produced and progressively add to a permanent counter. This counter would typically always monotically increase or decrease.
In order to prevent data from being lost when the iotawatt becomes inaccessible or when the HA instance is offline (such as during an update), the sensor will fetch the missing data from the iotawatt since the last known update upon restart.
This requires the iotawattpy 0.1.0 version which was just released.
Fly-by fix: remove unused name ad mac_address IotaWattSensor parameters.
Breaking change
None.
This only adds a new sensors to the existing iotawatt integration. They will be automatically added once HA is restarted.
Proposed change
The iotawatt integration doesn't allow to correctly read energy sensors due to the way the iotawatt process the request.
A summary of the problem is in the comment above.
For more details the issue is as follow:
Assume we have defined an output in the iotawatt UI to calculate import and export power from/to the grid.
The calculation would be:
Export = (Consumption+Production) min 0
Import = (Consumption+Production) max 0
where Production is a negative number as the current flows out.
When the current integration queries the energy force those sensors, it does so by requesting the energy value since January 1st of the year.
the iotawatt device will calculate it this way:
Export = (Average(Consumption, period) + Average(Consumption, period)) * duration_in_hour
rather than running the expression on the individual measurements. The reason for this is the lack of processing power by the iotawatt and the slow access speed to the storage medium.
So imagine you power load is a constant 1000W since the beginning of the year. a total of 1kw * 243 days * 24 = 5832kWh
and today you installed a solar system that produced 2000W for 1h; a total of -2kWh since January 2021.
If you query the iotawatt it will then return:
min(0, 5832kWh + -2kW) = 0
When obviously the correct was 1kWh (the excess power was 1000W over an hour)
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: