Skip to content

Add calculated energy sensor for Home Assistant Energy dashboard - #21

Open
11chri wants to merge 1 commit into
my-PV:mainfrom
11chri:ha-calculated-energy-sensor
Open

Add calculated energy sensor for Home Assistant Energy dashboard#21
11chri wants to merge 1 commit into
my-PV:mainfrom
11chri:ha-calculated-energy-sensor

Conversation

@11chri

@11chri 11chri commented Jul 24, 2026

Copy link
Copy Markdown

Add calculated energy sensor for Home Assistant Energy dashboard

Problem

The integration only exposes a power sensor (W) for my-PV heating devices.
To use the Home Assistant Energy dashboard, users had to manually create a Riemann Sum Integral helper to convert W → kWh.

Solution

Add a built-in Energy sensor that accumulates kWh from the device's power readings using time-delta integration on each coordinator update (every 5s). The sensor is directly compatible with the HA Energy dashboard.

Details

  • New entity: sensor.<device>_energy with device_class: energy,
    state_class: total_increasing, unit: kWh, 3 decimal precision
  • Device detection: Automatically finds the correct power data key
    for each device type:
    Device Power Key
    SOL-THOR power
    AC•THOR 9s power_ac9
    AC•THOR power_act
    AC ELWA 2 power_elwa2
    HEA•THOR IoT power_grid
  • State persistence: Uses RestoreEntity to restore accumulated
    energy on HA restart
  • Offline protection: Skips accumulation if time delta > 1 hour
    to prevent spikes after prolonged disconnections
  • Translations: Added "Energy" name in strings.json and en.json

Files changed

  • sensor.py: Added POWER_KEYS constant, energy sensor creation
    logic in async_setup_entry, and MyPVEnergySensor class
  • strings.json: Added entity translation for energy sensor
  • translations/en.json: Added entity translation for energy sensor

Tests

I rebased my MR to My-PV HA integration, Version 0.0.1rc6 and tested locally with AC•THOR 9s

AC•THOR 9s can now be visualized in Energy Dashboard
grafik

@henningstuy

Copy link
Copy Markdown

A new integration on a good way. Until last week I used the REST-Entities for reading the AC-Thor9s values in a 30 second interval. For EMS the 5 second intervall is great.
However I also missed the energy-sensor. This evening I added the calculated energy-sensor. At the first new start of HomeAssistant the integration was loaded with a failure. I had to delete the old device an create a new device. Now it seems to run.
For testing I used the Boost mode, the energy-sensor raised up.
Energy in HA 0,12kWh
Energy in myPV-Cloud 0,10kWh

But using the Boost mode, the integration lost the connection to the AC-Thor9 for one or two cycles. Maybe there is still a time problem.

HomeAssistant Core 26.7.2
Installation in Docker on Synology NAS
AC-Thor 9s
Firmware: a0022401

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.

2 participants