Skip to content
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

Merged
merged 6 commits into from
Sep 9, 2021

Conversation

jyavenard
Copy link
Contributor

@jyavenard jyavenard commented Sep 1, 2021

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue: I didn't open a bug.
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @gtdiehl, mind taking a look at this pull request as it has been labeled with an integration (iotawatt) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@MartinHjelmare MartinHjelmare changed the title [iotawatt] Add high-accuracy energy readout sensors. Add iotawatt high-accuracy energy readout sensors. Sep 1, 2021
@MartinHjelmare MartinHjelmare changed the title Add iotawatt high-accuracy energy readout sensors. Add iotawatt high-accuracy energy readout sensors Sep 1, 2021
@jyavenard jyavenard force-pushed the HighResolutionEnergySensors branch 3 times, most recently from 3556adc to 62ef2a0 Compare September 1, 2021 14:12
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.
@bdraco
Copy link
Member

bdraco commented Sep 4, 2021

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 manifest.json of this integration.

For more information about "code owners", see: Architecture Decision Record 0008: Code owners.

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@bdraco bdraco merged commit 556dcf6 into home-assistant:dev Sep 9, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Sep 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants