home-assistant / home-assistant.io

:blue_book: Home Assistant User documentation
https://www.home-assistant.io
Other
4.84k stars 7.23k forks source link

Integrating your electricity grid: manual integration #29386

Open pohly opened 11 months ago

pohly commented 11 months ago

Feedback

https://www.home-assistant.io/docs/energy/electricity-grid/#manual-integration says:

Make sure you set and provide the device_class, state_class, and unit_of_measurement for those sensors.

But what should it be set to?

unit_of_measurement is obvious, but not device_class and state_class.

URL

https://www.home-assistant.io/docs/energy/electricity-grid/

Version

2023.10.3

Additional information

I am using the following in my configuration.yaml to read values from a Sonnenbatterie 10:

# https://www.matusz.ch/blog/2022/07/10/sonnenbatterie-in-homeassistant/
rest:
  - resource: http://sonnenbatterie/api/v2/status
    method: GET
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json
    scan_interval: 10
    timeout: 15
    sensor:
      - name: Solar Power
        value_template: '{{ value_json.Production_W }}'
        unit_of_measurement: W
        device_class: power
      - name: Battery USOC
        value_template: '{{ value_json.USOC }}'
        unit_of_measurement: '%'
        device_class: battery
      - name: Battery RSOC
        value_template: '{{ value_json.RSOC }}'
        unit_of_measurement: '%'
        device_class: battery
      - name: Battery Consumption Production Diff
        value_template: '{{ value_json.Pac_total_W }}'
        unit_of_measurement: W
        device_class: power
      - name: House Consumption
        value_template: '{{ value_json.Consumption_W }}'
        unit_of_measurement: W
        device_class: power
      - name: Battery SoC Energy
        value_template: '{{ value_json.RemainingCapacity_Wh }}'
        unit_of_measurement: Wh
        device_class: energy

state_class is missing. After some further digging, I found https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics. Further up, that page also explains valid values. Perhaps link device_class to https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes and state_class to https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes?

pohly commented 11 months ago

Also not mentioned in the article: the energy dashboard wants sensors that provide energy (Wh), not power (W). "amount of energy flowing through your meter" kind of implies that, but "flowing" could also mean "power" - perhaps it's clearer to a native speaker (which I am not) :sweat_smile:

pohly commented 11 months ago

All of my sensors provide power. I'm solving this by adding helpers which integrate over the values of those sensors, using the default settings for integration - not sure whether those are appropriate.

dannytsang commented 11 months ago

You are correct in your approach. The Integration - Riemann sum integral helper will be able to take power over time and give an energy value. Leave it for a a couple of hours once it has some data and done a calculation the helper should be available to be added to the energy dashboard.