Invalid Entity Name for sensor.house_total_battery_power_in_w
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 %}
Thanks, I will look into this
I had the same problem with a fresh installation. I renamed the sensor manually in the HA UI. I think there is a mixup between entity_id and unique_id.
Still present in v4.15.1. In home assistant/packages/house_battery_control.yaml, sensor.battery_time_remaining (line 887) reads states('sensor.house_total_battery_power_in_w'). That is the unique_id of "House Total Battery Power", not its entity_id, so the value is always 0 and the sensor always shows "Charging".
One-line fix: states('sensor.house_total_battery_power'). The unique_id itself should stay unchanged, otherwise existing installs get an orphaned entity.
Same fix as proposed in #167. Running it patched locally since 19 Sep without side effects. Details in #195, which I'm closing as a duplicate of this one.