Skip to content

Invalid Entity Name for sensor.house_total_battery_power_in_w #129

@Jos1958

Description

@Jos1958

The house_battery_control.yaml defines the "House Total Battery Power" which is used by "Battery Time Remaining".

Home Assistant creates for the "House Total Battery Power" an entity id 'sensor.house_total_battery_power' (without '_in_w') and not the expected 'sensor.house_total_battery_power_in_w' for a NEW entity with unique_id "house_total_battery_power_in_w".
I believe this entity id generation was changed by HA in the past.

The confusing part is that the entity id is NOT changed when you already have an entity id 'sensor.house_total_battery_power_in_w' for the unique_id "house_total_battery_power_in_w" in de HA db.

As a result: It works fine for existing users since they already have the entity id with the '_in_w' but not for new users since they have the entity id without the '_in_w'. The battery time remaining cannot find the power value which defaults to 0 and new users will always see the "Charging (xxx kWh)" and will never see the time remaining in hours.

The solution is to add the default_entity_id to the template (as already done below).
For users that already have the wrong entity id this does helas not fix the problem. They will have to rename the entity id manually in HA.
You could adapt the unique_id (e.g. "house_total_battery_power_in_w_2"). However the old one will no longer be defined but will not automatically be removed.

Relevant parts from the yaml:

template:
  # Sensor that calculates how long the batteries can still discharge, keeping in mind that batteries should not go below 11%
  - sensor:
      # Total power delivered by all batteries
      - name: "House Total Battery Power"
        default_entity_id: sensor.house_total_battery_power_in_w
        unique_id: "house_total_battery_power_in_w"
        state_class: measurement
        device_class: "power"
        unit_of_measurement: "W"
        ...... suppressed .....

      # Time Remaining
      - name: "Battery time remaining"
        unique_id: house_battery_time_remaining
        state: >
          {# this value is calculated in the template sensor above #}
          {% set power = max(0, states('sensor.house_total_battery_power_in_w') | float(0)) %}
          {# set power = max(0, states('sensor.house_total_battery_power') | float(0)) #}
          {# this input_number is calculated in the Node-RED flows #}
          {% set capacity_kwh = states('input_number.house_battery_total_available_energy') | float(0) %}
          {# display #}
          {% if power > 0 and capacity_kwh > 0 %}
            {% set time_hrs = (capacity_kwh * 1000) / power %}
            {% set hrs = time_hrs | int %}
            {% set minutes = ((time_hrs - hrs) * 60) | int %}
            {{ '{:02}:{:02}'.format(hrs, minutes) }} hours ({{capacity_kwh | round(2)}} kWh)
          {% else %}
            Charging ({{capacity_kwh | round(2)}} kWh)
          {% endif %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions