This sensor code provides a 'usable battery' sensor by deducting the unusable minimum SoC and provides a full range 0-100% sensor that represents only the portion of the battery that is usable.
For example if the minimum SoC is set to 10%, only 89% of the battery is actually usable - this 89% is then scaled up to provide a full 0 - 100% sensor.
The sensor below needs to be added to your configuration.yaml file, if you run a different minSoc than the default value of 10, enter the value you use and it will then provide a new sensor.usable_battery
Code: Select all
- sensor:
- name: "Usable Battery"
unit_of_measurement: "%"
state: >
{% set minSoC = 10 | float %}
{% if states("sensor.battery_soc") in ['unknown', 'unavailable', 'none'] %}
{{ states("sensor.battery_soc") }}
{% elif states("sensor.battery_soc")|float >= minSoC%}
{{ ( (states("sensor.battery_soc")|float - minSoC ) * (100/(99-minSoC)) )|round(0, default=0) }}
{% else %}
{{ 0|float }}
{% endif %}
Code: Select all
- sensor:
- name: "Usable Battery"
unit_of_measurement: "%"
device_class: battery
state: >
{% set minSoC = 10 | float %}
{% if states("sensor.battery_soc") in ['unknown', 'unavailable', 'none'] %}
{{ states("sensor.battery_soc") }}
{% elif states("sensor.battery_soc")|float > minSoC%}
{{ ( ((states("sensor.battery_soc")|float - minSoC) * (100/(100-minSoC)) ))|round(0, default=0) }}
{% else %}
{{ 0|int }}
{% endif %}