bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
974 stars 258 forks source link

Cannot load sensors after upgrade #809

Closed Ov3r0n closed 2 years ago

Ov3r0n commented 2 years ago

I recently upgraded powercalc to the latest version and I'm getting this error everytime HA starts:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 235, in _async_setup_component
    result = await task
  File "/config/custom_components/powercalc/__init__.py", line 166, in async_setup
    await autodiscover_entities(config, domain_config, hass)
  File "/config/custom_components/powercalc/__init__.py", line 205, in autodiscover_entities
    manual_configuration = get_manual_configuration(config, entity_entry.entity_id)
  File "/config/custom_components/powercalc/__init__.py", line 245, in get_manual_configuration
    for item in sensor_config:
TypeError: 'NoneType' object is not iterable

My sensors are configured like this:

configuration.yaml:

powercalc:
  create_utility_meters: true
  energy_sensor_naming: "{}"

template:
  binary_sensor:
  - name: fridge_always_on
    state: on
  - name: ha_server_always_on
    state: on
  - name: router_always_on
    state: on
  - name: alarm_always_on
    state: on
  - name: alarm_range_extender_always_on
    state: on
  - name: doorbell_always_on
    state: on
  - name: wifi_btdisks_always_on
    state: on
  - name: switch_estudio_always_on
    state: on
  - name: switch_utility_always_on
    state: on
  - name: camara_entrada_always_on
    state: on
  - name: camara_ruben_always_on
    state: on
  - name: echo_show_always_on
    state: on
  - name: echo_dot_always_on
    state: on
  - name: echo_always_on
    state: on
  - name: siro_always_on
    state: on
  - name: wdmycloud_always_on
    state: on
  sensor:
  - name: roomba_charging_state
    unique_id: roomba_charging_state
    icon: 'mdi: battery-charging-medium'
    state: >
      {% if states('vacuum.roomba') == 'docked' %}
        {% if int(state_attr('vacuum.roomba', 'battery_level')) < 100 %}
          charging
        {% else %}
          docked
        {% endif %}
      {% else %}
        cleaning
      {% endif %}

sensor powercalc_label: !include powercalc.yaml

powercalc.yaml:

- platform: powercalc
  create_group: All Estimated Usage
  entities:
    - create_group: All Lights
      entities:
        - create_group: Upstairs Lights
          entities:
            - entity_id: light.luz_de_arriba_de_las_escaleras

            - create_group: Bedroom Lights
              entities:
                - entity_id: light.luz_papel_dormitorio

            - create_group: Studio Lights
              entities:
                - entity_id: light.luz_mesa_estudio
                - entity_id: light.luz_estudio

        - create_group: Downstairs Lights
          entities:
            - entity_id: light.luz_pie_comedor
            - entity_id: light.ledscocina

    - create_group: Always On Devices
      entities:
        # The following devices are integrated into HA, but are generally always on.
        - entity_id: binary_sensor.fridge_always_on
          name: Frigorifico
          fixed:
            power: 50
        - entity_id: binary_sensor.smoke_detectors_always_on
          name: Smoke Detectors
          fixed:
            # See https://community.element14.com/challenges-projects/design-challenges/energy-harvesting/b/blog/posts/carbon-monoxide-detector-power-consumption
            # 1mA @ 3V = 0.003W
            # X2 (kitchen, hall, bedrooms)
            power: 0.015
        - entity_id: binary_sensor.switch_estudio_always_on
          name: Studio Network Switch
          fixed:
            power: 4.9
        - entity_id: binary_sensor.switch_utility_always_on
          name: Utility Network Switch
          fixed:
            power: 4.9
        - entity_id: binary_sensor.doorbell_always_on
          name: Doorbell
          fixed:
            power: 1.2
        - entity_id: binary_sensor.alarm_always_on
          name: Alarm Base Station
          fixed:
            power: 12.4
        - entity_id: binary_sensor.router_always_on
          name: Router
          fixed:
            power: 7
        - entity_id: binary_sensor.ha_server_always_on
          name: Servidor Domotica
          fixed:
            power: 37.6

    - create_group: Variable Consumption Devices
      entities:

        - entity_id: sensor.roomba_charging_state
          name: Roomba
          fixed:
            states_power:
              charging: 28
              docked: 3.6
              cleaning: 0

I've tried disabling and re-enabling some of the sensors with no luck. Any help will be much appreciated (BTW great work with the component, love it!!)

bramstroker commented 2 years ago

Should be fixed in v0.22.1

usma0118 commented 2 years ago

Should be fixed in v0.22.1

Verified. Works as expected.