As long as you understand that the value won’t update live on screen. Only when you refresh the page.
custom button card with that code I’ve posted in previous post is updated live on screen.
Please post in English
Sorry, I had auto translation activated, but porbably already found a solution via KI I would like to share.
I got charge and decharge limits activated at my Zendure setup (20%min , 85%max). Here is my KI solution that need to check tomorrow and might be improved:
sensor:
- platform: template
sensors:
battery_charge_hours:
value_template: >
{% set ct = states('sensor.remainInputTime') | int %}
{% set current_level = states('sensor.electriclevel') | int %}
{% set charge_limit = 85 %}
{% set remaining_charge = charge_limit - current_level %}
{% set adjusted_ct = (ct * remaining_charge) / (100 - current_level) %}
{% if adjusted_ct == 0 %}
Unavailable
{% elif adjusted_ct > 60 %}
{{ adjusted_ct // 60 }}:{{ '{:0>2d}'.format(adjusted_ct%60) }}
{% else %}
{{ adjusted_ct }} minutes
{% endif %}
charge_finish_time:
value_template: >
{% if is_state('sensor.remainInputTime','unavailable') %}
Unavailable
{% else %}
{% set ct = states('sensor.remainInputTime') | int %}
{% set current_level = states('sensor.electriclevel') | int %}
{% set charge_limit = 85 %}
{% set remaining_charge = charge_limit - current_level %}
{% set adjusted_ct = (ct * remaining_charge) / (100 - current_level) %}
{% if adjusted_ct == 0 %}
Done
{% else %}
{{ (as_timestamp(now()) + adjusted_ct * 60) | timestamp_custom("%H:%M") }}
{% endif %}
{% endif %}
battery_remain_hours:
value_template: >
{% set ct = states('sensor.remainOutTime') | int %}
{% set current_level = states('sensor.electriclevel') | int %}
{% set discharge_limit = 20 %}
{% set remaining_discharge = current_level - discharge_limit %}
{% set adjusted_ct = (ct * remaining_discharge) / current_level %}
{% if adjusted_ct == 0 %}
Unavailable
{% elif adjusted_ct > 60 %}
{{ adjusted_ct // 60 }}:{{ '{:0>2d}'.format(adjusted_ct%60) }}
{% else %}
{{ adjusted_ct }} minutes
{% endif %}
decharge_finish_time:
value_template: >
{% if is_state('sensor.remainOutTime','unavailable') %}
Unavailable
{% else %}
{% set ct = states('sensor.remainOutTime') | int %}
{% set current_level = states('sensor.electriclevel') | int %}
{% set discharge_limit = 20 %}
{% set remaining_discharge = current_level - discharge_limit %}
{% set adjusted_ct = (ct * remaining_discharge) / current_level %}
{% if adjusted_ct == 0 %}
Done
{% else %}
{{ (as_timestamp(now()) + adjusted_ct * 60) | timestamp_custom("%H:%M") }}
{% endif %}
{% endif %}