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

Backport HA iotawatt integration changes #26

Closed
wants to merge 15 commits into from

Conversation

jyavenard
Copy link
Contributor

This pull request is to be put on top of https://github.com/jyavenard/iotawatt_ha/tree/IntegrateLocally

It backports all the changes made into HA's official iotawatt integration and add the high resolution energy sensors.

Querying the iotawatt for accumulated energy of a power output sensor will typically return the wrong value due to how the calculations are performed.

So rather than relying on the Iotawatt to perform those calculations we instead calculate the energy value locally by using the Riemann Sum Integration. The energy will be calculated after each read (performed every 30s)

The generated sensor will have a name in the format:
"IotaWatt Output Sensor Integral".

One downside over the energy sensor (ending with .wh) is that the energy will not accumulate following a reboot and the data will be lost.

This could be improved by querying the IotaWatt for the average power since it was last queried.

Fixes gtdiehl#18
…ted by reading at regular intervals the energy value from the iotawatt.

When declaring outputs relying on a mathematical expression (using other than + and - operator), the default energy sensors can't be used

While the `integration` integration could be used, the advantage of those sensors is that they won't lose data if the connection to the iotawatt is lost or if rebooting the HA instance.
In these cases, the sensor will fetch the data from when it last stop.

This change requires iotawattpy 0.1.0

Fixes gtdiehl#18
fly-by change, re-organise method order to be more consistent with other modules.
…rom iotawatt to quickly populate the accumulated energy sensors rather than wait for an extra 30s
…ns. There can't be accuracy loss resulting from this operation, making it unnecessary to use fractionals.
@wishie
Copy link

wishie commented Sep 1, 2021

So I have just updated HA to 2021.9.0 and am now using the 'built in' integration, but I have issues with sensors in the energy dashboard. The instructions on the HA page are not clear, or not working as expected. Can you explain what I need to do to have valid sensors for the energy dashboard?

@jyavenard
Copy link
Contributor Author

If you are using a net solar system and need import and export ; the current version in iotawatt can't work.
The one in this branch can.

Simply put the custom_components/iotawatt folder in the HA custom_components and restart HA

@jyavenard
Copy link
Contributor Author

So I have just updated HA to 2021.9.0 and am now using the 'built in' integration, but I have issues with sensors in the energy dashboard. The instructions on the HA page are not clear, or not working as expected. Can you explain what I need to do to have valid sensors for the energy dashboard?

It's a last minute change in HA that broke it: home-assistant/core#55554

This branch fixes it ; you just need to use the integration in custom_components for now.

@wishie
Copy link

wishie commented Sep 2, 2021

So Im not installing the 0.0.8 release, but a specific branch? How do I achieve this?

@gtdiehl
Copy link
Owner

gtdiehl commented Sep 2, 2021

So Im not installing the 0.0.8 release, but a specific branch? How do I achieve this?

If you want to get up and running right now, update the configuration.yaml with the integration sensor for each of your sensors from the IoTaWatt that has a Unit of Watts

This is the example for the Home Assistant webpage

sensor iotawatt:
  - platform: integration
    source: sensor.mainsexport
    name: Total Grid Export
    unit_prefix: k
  - platform: integration
    source: sensor.mainsconsumption
    name: Total Grid Consumption
    unit_prefix: k

In the above example there are two sensors on the IoTaWatt, sensor.mainsexport and sensor.mainsconsumption. Replace those with the sensors from your IoTaWatt. Of course you probably have more than two, so just copy and paste and create as many given each one a unique name. Restart HA and the sensors with the names you gave will be available in the selection list for the Energy Dashboard

Comment on lines +83 to +87
"WattHours": IotaWattSensorEntityDescription(
"WattHours",
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
"WattHours": IotaWattSensorEntityDescription(
"WattHours",
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
"WattHours": IotaWattSensorEntityDescription(
"WattHours",
native_unit_of_measurement=ENERGY_WATT_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=DEVICE_CLASS_ENERGY,
),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The class is already set on the high resolution sensor.

custom_components/iotawatt/sensor.py Show resolved Hide resolved
@jyavenard
Copy link
Contributor Author

this will only work with 2021.9 ; will approach this differently.

@jyavenard jyavenard closed this Sep 2, 2021
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.

3 participants