bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
1.01k stars 262 forks source link

Issue with groups and existing power sensors #1516

Closed fxstein closed 1 year ago

fxstein commented 1 year ago

Hi,

I am getting some strange error messages when I attempt to create groups from real power sensors paired with powercalced energy sensors.

Am running the following versions:

Home Assistant 2023.2.5
Supervisor 2023.01.1
Operating System 9.5
Frontend 20230202.0 - latest

HACS:
Integration version: | 1.30.1
Frontend version: | 20220906112053
Repositories: | 1206
Downloaded repositories: | 5

PowerCalc: 
v1.3.5

At the highest level:

I am getting power sensors for various solar systems through their APIs, but no energy readings (don't get me started...). So I use Powercalc to calculate an energy sensor and a daily meter for it. Works great. I have set unique IDs by hand for now (will get replaced by serial numbers of the inverters...) to ensure I have a single set of uniqe sensors throughout the custom component I am working on.

The power sensors are defined like that (l0 sensors are the JSON response from the API):

For reference I have labeled the sensors as follows: l0 ... API call, l1 ... sensor mappings, l2 ... energy calculations, l3 ... energy and power aggregations...

        - name: "Pionizer L1 Solax API Inverter 1 MPPT 1 Power"
          state: "{{ state_attr('sensor.pionizer_l0_solax_api_inverter_1', 'powerdc1') }}"
          unit_of_measurement: "W"
          device_class: power
          state_class: measurement
          unique_id: pionizer_l1_solax_api_inverter_1_mppt_1_power
          icon: mdi:solar-power-variant

        - name: "Pionizer L1 Solax API Inverter 1 MPPT 2 Power"
          state: "{{ state_attr('sensor.pionizer_l0_solax_api_inverter_1', 'powerdc2') }}"
          unit_of_measurement: "W"
          device_class: power
          state_class: measurement
          unique_id: pionizer_l1_solax_api_inverter_1_mppt_2_power
          icon: mdi:solar-power-variant

        - name: "Pionizer L1 Solax API Inverter 1 MPPT 3 Power"
          state: "{{ state_attr('sensor.pionizer_l0_solax_api_inverter_1', 'powerdc3') }}"
          unit_of_measurement: "W"
          device_class: power
          state_class: measurement
          unique_id: pionizer_l1_solax_api_inverter_1_mppt_3_power
          icon: mdi:solar-power-variant

They all work great. Getting them every 5 min.

Then I added Energy sensors like that:

    - platform: powercalc
      name: "Pionizer L2 Inverter 1 MPPT 1 Production"
      unique_id: sensor.pionizer_l2_inverter_1_mppt_1_production
      power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_1_power

    - platform: powercalc
      name: "Pionizer L2 Inverter 1 MPPT 2 Production"
      unique_id: sensor.pionizer_l2_inverter_1_mppt_2_production
      power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_2_power

    - platform: powercalc
      name: "Pionizer L2 Inverter 1 MPPT 3 Production"
      unique_id: sensor.pionizer_l2_inverter_1_mppt_3_production
      power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_3_power

together with global settings like this:

  powercalc:
    enable_autodiscovery: false
    power_sensor_naming: "{} Power"
    energy_sensor_naming: "{} Energy"
    create_utility_meters: true
    utility_meter_types:
      - daily

All of them work great as well, including the Daily utility meters.

The problems start when I try to add groups to aggregate the individual sensors at the inverter and system level.

    - platform: powercalc
      create_group: "Pionizer L3 Inverter 1 Solar Production"
      unique_id: sensor.pionizer_l3_inverter_1_solar_production
      entities:
        - power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_1_power
          energy_sensor_id: sensor.pionizer_l2_inverter_1_mppt_1_production_energy
        - power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_2_power
          energy_sensor_id: sensor.pionizer_l2_inverter_1_mppt_2_production_energy
        - power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_3_power
          energy_sensor_id: sensor.pionizer_l2_inverter_1_mppt_3_production_energy

Always result in the following errors:

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:540 
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22)) 
First occurred: 2:51:03 AM (4 occurrences) 
Last logged: 2:51:03 AM

Platform powercalc does not generate unique IDs. ID sensor.pionizer_l2_inverter_1_mppt_1_production_energy_daily is already used by sensor.pionizer_l2_inverter_1_mppt_1_production_energy_daily - ignoring sensor.pionizer_l2_inverter_1_mppt_1_production_energy_daily
Platform powercalc does not generate unique IDs. ID sensor.pionizer_l2_inverter_1_mppt_2_production_energy_daily is already used by sensor.pionizer_l2_inverter_1_mppt_2_production_energy_daily - ignoring sensor.pionizer_l2_inverter_1_mppt_2_production_energy_daily
Platform powercalc does not generate unique IDs. ID sensor.pionizer_l2_inverter_1_mppt_3_production_energy_daily is already used by sensor.pionizer_l2_inverter_1_mppt_3_production_energy_daily - ignoring sensor.pionizer_l2_inverter_1_mppt_3_production_energy_daily
Platform powercalc does not generate unique IDs. ID sensor.pionizer_l2_inverter_1_mppt_4_production_energy_daily is already used by sensor.pionizer_l2_inverter_1_mppt_4_production_energy_daily - ignoring sensor.pionizer_l2_inverter_1_mppt_4_production_energy_daily

I have tried it with and without unique id. If I remove the unique IDs, the group setup actually creates a second set of energy sensors by appending _2 to the l2 energy sensors.

Very much appriciate any guidance!

bramstroker commented 1 year ago

Thanks for your detailed report, this is how an issue should be written ;-). When you create the individual entities and the groups in separate powercalc entries I think it will try to create the utility meters twice, resulting in this error. Best practice is to use the following configuration to define both the group and individual entities in a single entry. I have good hopes this will also resolve your error.

Could you try this:

- platform: powercalc
  create_group: "Pionizer L3 Inverter 1 Solar Production"
  unique_id: sensor.pionizer_l3_inverter_1_solar_production
  entities:
    - name: "Pionizer L2 Inverter 1 MPPT 1 Production"
      unique_id: sensor.pionizer_l2_inverter_1_mppt_1_production
      power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_1_power
    - name: "Pionizer L2 Inverter 1 MPPT 2 Production"
      unique_id: sensor.pionizer_l2_inverter_1_mppt_2_production
      power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_2_power
    - name: "Pionizer L2 Inverter 1 MPPT 3 Production"
      unique_id: sensor.pionizer_l2_inverter_1_mppt_3_production
      power_sensor_id: sensor.pionizer_l1_solax_api_inverter_1_mppt_3_power
fxstein commented 1 year ago

Thanks for the tip. Will be testing today.

bramstroker commented 1 year ago

@fxstein were you able to test this?

bramstroker commented 1 year ago

Closing due to inactivity.