homeassistant-powercalc: huge spikes on templated device_energy groups (throw off energy panel)

System Health details

no health report available

Checklist

  • I have read the FAQ to see if there is a known solution to my problem.
  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues

Describe the issue

using templates ike:

      - unique_id: non_switches_total_device_energy
        state: >
          {{expand('group.non_switches_total_device_energy')
             |map(attribute='state')
             |select('is_number')
             |map('float')|sum}}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing

are often completely throwing off the energy panel:

Scherm­afbeelding 2023-08-24 om 10 34 30

not using an availability template on the template, to prevent false values causing a reset of the sensor. As you can see the has_value() should safeguard individual entities in that group go unknown/unavailable)

the group itself is also made up of pure powercalc sensors, see below:

no ‘discovered’ entities in this group.

Reproduction steps

  1. not sure, just happens intermittently

Debug logs

need to get back on this

Diagnostics dump or YAML config

  non_switches_total_device_energy:
    name: Non Switches total device energy
    entities:
# Non switch devices
      - sensor.airport_express_water_device_energy
      - sensor.googlehome_hall_device_energy
      - sensor.googlehome_hub_device_energy
      - sensor.homepod_keuken_device_energy
      - sensor.luchtreiniger_woonkamer_device_energy
      - sensor.luchtreiniger_hall_device_energy
      - sensor.mco_co2_living_device_energy
      - sensor.plugwise_smile_device_energy
      - sensor.siren_hall_device_energy
      - sensor.watermeter_device_energy
      - sensor.camera_bijkeuken_device_energy
      - sensor.camera_corridor_device_energy
      - sensor.camera_garage_device_energy
      - sensor.camera_hall_device_energy
      - sensor.camera_poort_device_energy
      - sensor.noodlicht_meterkast_device_energy
      - sensor.bel_trafo_device_energy
      - sensor.intercom_trafo_zolder_device_energy
      - sensor.bewegingsensoren_buiten_device_energy
      - sensor.rookmelders_device_energy

and as such there is not much we can do as end user. all of these are set with a fixed config:

    - entity_id: device_tracker.smartgateways_watermeter
      fixed:
        power: 4.9

    - entity_id: device_tracker.airport_express_water
      fixed:
        power: 4.1

    - entity_id: device_tracker.uvc_bijkeuken
      fixed:
        power: 2.1

or

    - entity_id: media_player.homepod_keuken
      standby_power: 2.2
      fixed:
        states_power:
          playing: 2.7
          paused: 2.2
          idle: 2.2

    - entity_id: fan.luchtreiniger_hall
      <<: &ikea_fan
        standby_power: 0.5
        linear:
          attribute: percentage
          calibrate:
            - 10 -> 1.5
            - 18 -> 1.6
            - 20 -> 1.7
            - 30 -> 2.1
            - 40 -> 3.3
            - 50 -> 5.2
            - 60 -> 8.5
            - 70 -> 11.4
            - 80 -> 16.3
            - 90 -> 18.8
            - 100 -> 21.9

and

    - unique_id: powercalc_daily_fixed_noodlicht_meterkast
      daily_fixed_energy:
        value: 1
        unit_of_measurement: W

    - unique_id: powercalc_daily_fixed_rookmelders
      daily_fixed_energy:
        value: 3
        unit_of_measurement: W

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Very nice.

which is very nice (though still find it a bit complex to configure in yaml to have to list both power and energy sensors there)

By default powercalc tries to find an energy sensor on the same device when you only supply power_sensor_id, but this can cause problems when a device has multiple energy sensors. In your scenario this is the case (because there is also an energy sensor created by powercalc). Also shelly PM devices have multiple energy sensors. Powercalc cannot know which energy sensor related to a given power sensor. There is no one-to-one relation in HA installation how I can sense that. So that’s why you need to specify both power_sensor_id and energy_sensor_id.

Why are you using a template sensor for grouping? This is asking for troubles.

Powercalc provides group sensors which have all kind of precautions in place to prevent the group sensor getting negative or spiking. https://homeassistant-powercalc.readthedocs.io/en/latest/sensor-types/group.html

When you do summing yourself using a template sensor and state_class total_increasing the sensor will get reset or spike whenever an energy sensor is getting removed, when a sensor gets unavailable etc. etc. Because regarding to the state class HA expects the sensor to always only increase and a descrease is considered a reset.

Long story short. Just use the grouping functionality powercalc provides.