In this example the home battery system has a capacity of 300Ah (15kWh / 48V).
As a safe minimal value is 15% capacity left is chosen. When grid is failing, there is still 2.5kWh left. When charging occurs, this will be shown instead of the remaining time.
You can use the created sensor ‘sensor.template_time_left_on_battery_min_soc’ to display on your dashboard.
- sensor:
- unique_id: time_left_on_battery_min_soc
# unit_of_measurement: "Hours"
icon: mdi:sort-clock-ascending
state: >
{% set battery_current = states('sensor.battery_current')|float %}
{% set battery_soc = states('sensor.battery_percent')|float %}
{% set loads_current = states('sensor.ac_loads')|float/states('sensor.battery_voltage')|float %}
{% set battery_min_soc = 15 %}
{% set battery_max_capacity = 300 %}
{% if (battery_soc-battery_min_soc) < 0 %}
{{ 0 }}
{% elif (loads_current) < 0 %}
{{ 'Charging' }}
{% else %}
{{ ((((battery_soc-battery_min_soc)*battery_max_capacity)/100)/loads_current | float ) | round(2) }}
{% endif %}