Skip to content

Commit

Permalink
Merge pull request #63 from colwilliamsnz/master
Browse files Browse the repository at this point in the history
Update to support HA 2019.9.x (note breaking change)
  • Loading branch information
safepay committed Sep 4, 2021
2 parents ab44241 + b8188fa commit 8200043
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,37 @@ If you have a SmartMeter installed this component:
* compatible with the custom [Power Wheel Card](https://github.com/gurbyz/power-wheel-card/tree/master) if using PowerFlow

### Energy dashboard support - HA 2021.8+
All energy and power sensors provide required attributes to allow long term statistics to be recorded which enables support for the new Energy dashboard introduced in HA 2021.8. The following "lifetime" sensors can be added to the energy configuration:
All energy and power sensors provide required attributes to allow long term statistics to be recorded which enables support for the new Energy dashboard introduced in HA 2021.8.

#### BREAKING CHANGE - HA 2021.9.x

Unfortunately HA 2021.9 breaks energy sensors in earlier releases of this component. To upgrade to HA 2021.9.x, ensure you update to this release immediately afterwards. 2021.8.x can be made compatible by using customize.yaml to override the required entities as follows.

If it doesn't already exist, add the following into configuration.yaml:
```yaml
homeassistant:
customize: !include customize.yaml
```

If it doesn't already exist, create a "customize.yaml" file in the same directory as configuration.yaml and add the following:
```yaml
sensor.fronius_total_energy:
state_class: measurement
last_reset: "homeassistant.util.dt.utc_from_timestamp(0)"
sensor.fronius_smartmeter_energy_ac_consumed:
state_class: measurement
last_reset: "homeassistant.util.dt.utc_from_timestamp(0)"
sensor.fronius_smartmeter_energy_ac_sold:
state_class: measurement
last_reset: "homeassistant.util.dt.utc_from_timestamp(0)"
```

Where "fronius" in the sensor name needs to match the name of the integration. Once upgraded to HA 2021.9.x the above entries may be safely removed.


#### Configuring the Energy dashboard:

The following "lifetime" sensors can be added to the energy configuration:

* Solar production: ``total_energy``
* Grid consumption: ``smartmeter_energy_ac_consumed``
Expand Down
2 changes: 1 addition & 1 deletion custom_components/fronius_inverter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"dependencies": [],
"codeowners": ["@safepay"],
"requirements": [],
"version": "v0.9.7"
"version": "v0.9.8"
}
12 changes: 5 additions & 7 deletions custom_components/fronius_inverter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)

from homeassistant.components.sensor import (
PLATFORM_SCHEMA, STATE_CLASS_MEASUREMENT, SensorEntity,
PLATFORM_SCHEMA, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, SensorEntity,
)

from homeassistant.helpers.event import async_track_time_interval
Expand Down Expand Up @@ -207,17 +207,15 @@ def __init__(self, device_data, name, sensor_type, scope, units, device_id, powe
self._smartmeter = smartmeter
self._always_log = always_log

# add device class and state class attributes to energy and power sensors to support long term statistics
# and energy dashboard, new in HA 2021.8. Ref https://developers.home-assistant.io/docs/core/entity/sensor/
# add attributes to support Energy dashboard and statistics for power sensors, new in HA 2021.8
# and updated in 2021.9 due to bugs in the orginal HA implementation.
# ref https://developers.home-assistant.io/docs/core/entity/sensor/
if self._convert_units == "power":
self._attr_device_class = DEVICE_CLASS_POWER
self._attr_state_class = STATE_CLASS_MEASUREMENT
elif self._convert_units == "energy":
self._attr_device_class = DEVICE_CLASS_ENERGY
self._attr_state_class = STATE_CLASS_MEASUREMENT
self._attr_last_reset = dt_util.utc_from_timestamp(0)
# TODO: When HA 2021.9 is released (or at least before HA 2021.11) the two lines above should be replaced by the line below
#self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING

@property
def name(self):
Expand Down

0 comments on commit 8200043

Please sign in to comment.