From 167859c7257edb83d8348f6f27020bc71ff726e4 Mon Sep 17 00:00:00 2001 From: Fabrice Devaux Date: Sun, 5 May 2024 12:25:35 +0200 Subject: [PATCH] Fix example rate guesstimate template Fixes #278 --- README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 26fdeae..525f119 100644 --- a/README.md +++ b/README.md @@ -230,17 +230,15 @@ template: - sensor: - name: "Charge speed guesstimate" state: > - {% if is_state('switch._charging', 'on') %} - {% set maxcharge = %} - {% set percentleft = 100 - states('sensor._battery_level') | int %} - {% set hoursleft = states('sensor._charging_time_left').split(':')[0] | int %} - {% set minutesleft = states('sensor._charging_time_left').split(':')[1] | int %} - {% set totalminutesleft = hoursleft*60 + minutesleft %} - {% set chargeleft = maxcharge * percentleft / 100 %} - {% set chargespeed = chargeleft / (totalminutesleft / 60) %} - {{ (chargespeed / 1000) | round(1) }} + {% if is_state('switch.skoda__charging', 'on') %} + {% set battery_capacity = | int %} + {% set charge = { "remaining": states('sensor.skoda__minimum_charge_level') | int - states('sensor.skoda__battery_level') | int } %} + {% set timeleft = states('sensor.skoda__charging_time_left') | int %} + {% set chargeleft = battery_capacity * charge.remaining / 100 %} + {% set chargespeed = chargeleft / (timeleft / 60) %} + {{ chargespeed | round (1) }} {% else %} - 0 + 0 {% endif %} unit_of_measurement: "kW" state_class: measurement