The problem
I noticed that with my calculation for export/import when using the right method, I always go widely inaccurate results; even though from a mathematical standpoint it should be the best method.
I use a iotawatt sensor provides readings of a defined output for both import and export:
The sensor is defined as a calculation:
Export = (Phase1 + Phase2 + Phase3 + Tesla1 + Tesla2 + Tesla3 + Pool + Solar1 + Solar2 + AC1 + AC2 + AC3 + HotWater) min 0
Import = (Phase1 + Phase2 + Phase3 + Tesla1 + Tesla2 + Tesla3 + Pool + Solar1 + Solar2 + AC1 + AC2 + AC3 + HotWater) max 0
values for Import would be negative.
As the energy screen requires data that is positive; I use a template for that:
- platform: template
sensors:
power_grid_import:
friendly_name: "Grid Power Import"
unit_of_measurement: W
device_class: power
value_template: "{{ states('sensor.iotawatt_output_import')|float|abs }}"
availability_template: "{{ states('sensor.iotawatt_output_import') not in ['unavailable', 'unknown', 'none' ] }}"
attribute_templates:
last_reset: "{{ state_attr('sensor.iotawatt_output_import', 'last_reset') }}"
state_class: "{{ state_attr('sensor.iotawatt_output_import', 'state_class') }}"
power_grid_export:
friendly_name: "Grid Power Export"
unit_of_measurement: W
device_class: power
value_template: "{{ states('sensor.iotawatt_output_export')|float|abs }}"
availability_template: "{{ states('sensor.iotawatt_output_export') not in ['unavailable', 'unknown', 'none' ] }}"
attribute_templates:
last_reset: "{{ state_attr('sensor.iotawatt_output_export', 'last_reset') }}"
state_class: "{{ state_attr('sensor.iotawatt_output_export', 'state_class') }}"
I then use the integration integration as followed:
- platform: integration
source: sensor.power_grid_export
name: energy_grid_export_wh_r
unit_prefix: k
method: right
- platform: integration
source: sensor.power_grid_import
name: energy_grid_import_wh_r
unit_prefix: k
method: right
This however provides extremely inaccurate result .
Consider the history plot for the export power reading:

However, when you look at the graph out of the integration:

What appears to happen is that the power sensor will read 0, and with a utility_meter reset at 0
The first read that is not 0 is at around 9:00AM and has a value of 188W
This is calculated as 188W*9h = 1.69kWh for the first entry; which is obviously wrong.
In that graph again, we can see that it then reads 0 again, and then 2000W 30 minutes later and that again is calculated as an extra 1kWh
So you end up shortly with an energy calculated significantly higher that what it actually is.
With Trapezoidal you also see a similar issue, though not as bad ; left works fine as it only measure from the first read (left side)

This are the value plotted using all 3 methods; the actual value reported by the energy meter is 3.9kWh export and 19.3kWh import.
As you can see, the Right value (on the left) is almost 50% over-valued.
What is version of Home Assistant Core has the issue?
core-2021.8.8
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
integration (Riemann Sum)
Link to integration documentation on our website
https://www.home-assistant.io/integrations/integration/#energy
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response
The problem
I noticed that with my calculation for export/import when using the right method, I always go widely inaccurate results; even though from a mathematical standpoint it should be the best method.
I use a iotawatt sensor provides readings of a defined output for both import and export:
The sensor is defined as a calculation:
Export = (Phase1 + Phase2 + Phase3 + Tesla1 + Tesla2 + Tesla3 + Pool + Solar1 + Solar2 + AC1 + AC2 + AC3 + HotWater) min 0Import = (Phase1 + Phase2 + Phase3 + Tesla1 + Tesla2 + Tesla3 + Pool + Solar1 + Solar2 + AC1 + AC2 + AC3 + HotWater) max 0values for Import would be negative.
As the energy screen requires data that is positive; I use a template for that:
I then use the
integrationintegration as followed:This however provides extremely inaccurate result .

Consider the history plot for the export power reading:
However, when you look at the graph out of the integration:

What appears to happen is that the power sensor will read 0, and with a utility_meter reset at 0
The first read that is not 0 is at around 9:00AM and has a value of 188W
This is calculated as 188W*9h = 1.69kWh for the first entry; which is obviously wrong.
In that graph again, we can see that it then reads 0 again, and then 2000W 30 minutes later and that again is calculated as an extra 1kWh
So you end up shortly with an energy calculated significantly higher that what it actually is.
With Trapezoidal you also see a similar issue, though not as bad ; left works fine as it only measure from the first read (left side)

This are the value plotted using all 3 methods; the actual value reported by the energy meter is 3.9kWh export and 19.3kWh import.
As you can see, the Right value (on the left) is almost 50% over-valued.
What is version of Home Assistant Core has the issue?
core-2021.8.8
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
integration (Riemann Sum)
Link to integration documentation on our website
https://www.home-assistant.io/integrations/integration/#energy
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response