Template sensor:🔋 Battery charging time to full and discharging time to empty

Hi! I am using the HACS integration battery_sim to simulate a “Works locally with Home Assistant”-home battery I pre-ordered. Because of this, I have sensors indicating the current capacity in kWh and the current charging and discharging rates in kW.

I wanted to have a sensor that’ll estimate the time to a complete (dis)charge. I couldn’t find any examples on the internet so I decided to make my own and publish it here!

How to reproduce

  • Go to Settings > Devices & Services > Helpers > Create Helper > Template > Template Sensor.
  • Enter any name you want, e.g. “HWE Battery - time to full”.
  • Enter the templates provided below and replace the sensor entities with your own.
  • Set the Device Class to ‘Timestamp’ and leave the other options empty.
  • Done!

:battery: Template to estimate when a battery is full:

  • Replace sensor.battery_sim_hwe_current_charging_rate with your current charging speed in kW.
  • Replace sensor.battery_sim_hwe with your current charge level in kWh.
  • Set full_capacity to the full battery capacity in kWh.
{% if states('sensor.battery_sim_hwe_current_charging_rate') | float > 0 %}
  {% set full_capacity = 2.688 | float %}
  {% set remaining_capacity = full_capacity - states('sensor.battery_sim_hwe') | float %}
  {% set charging_time_seconds = (remaining_capacity / states('sensor.battery_sim_hwe_current_charging_rate') | float) * 3600 %}
  {{ now() + timedelta(seconds=charging_time_seconds) }}
{% endif %}

:low_battery: Template to estimate when a battery is empty:

  • Replace sensor.battery_sim_hwe_current_discharging_rate with your current discharging speed in kW.
  • Replace sensor.battery_sim_hwe with your current charge level in kWh.
{% if states('sensor.battery_sim_hwe_current_discharging_rate') | float > 0 %}
  {% set remaining_capacity = states('sensor.battery_sim_hwe') | float %}
  {% set discharging_time_seconds = (remaining_capacity / states('sensor.battery_sim_hwe_current_discharging_rate') | float) * 3600 %}
  {{ now() + timedelta(seconds=discharging_time_seconds) }}
{% endif %}

They’ll look like this: (state will be ‘Unknown’ when there is no estimate to be made, obviously)

Enjoy, and be sure to let me know if and how you used it or if you improved on it!

1 Like