From cd6643cd3513aa8259f3fdec8924ee8beb0e704d Mon Sep 17 00:00:00 2001 From: Claus Dethlefsen Date: Mon, 6 Apr 2026 13:01:06 +0200 Subject: [PATCH] Fix Tesla smart charging hysteresis --- include/automations/tesla_smart_charging.yaml | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/include/automations/tesla_smart_charging.yaml b/include/automations/tesla_smart_charging.yaml index a4cd55a..c044255 100644 --- a/include/automations/tesla_smart_charging.yaml +++ b/include/automations/tesla_smart_charging.yaml @@ -3,29 +3,26 @@ mode: restart trigger: - # Kør hvert 5. min (responsiv) - platform: time_pattern minutes: "/5" - # Sikrer re-evaluering ved ny time - platform: time_pattern minutes: "0" condition: - # Deadline gyldig - condition: template value_template: > {% set deadline = states('input_datetime.tesla_charge_deadline') %} {{ deadline not in ['unknown','unavailable',''] and as_timestamp(deadline) > as_timestamp(now()) }} - # Kun når bilen er tilsluttet - - condition: template - value_template: > - {{ states('binary_sensor.tesla_connected') == 'on' }} + - condition: state + entity_id: binary_sensor.tesla_connected + state: "on" action: - variables: - should_charge: "{{ states('binary_sensor.tesla_charge_now') == 'on' }}" + should_charge: "{{ is_state('binary_sensor.tesla_charge_now','on') }}" + currently_charging: "{{ is_state('switch.home_charging', 'on') }}" last_start: "{{ states('input_datetime.tesla_last_start') }}" last_start_ts: > {% if last_start not in ['unknown','unavailable',''] %} @@ -38,36 +35,32 @@ - choose: # ------------------------- - # START / CONTINUE CHARGING + # START CHARGING # ------------------------- - conditions: - condition: template value_template: "{{ should_charge }}" - sequence: - # Hvis ikke allerede i gang → registrer start - - condition: template - value_template: > - {{ states('switch.home_charging') != 'on' }} + - if: + - condition: template + value_template: "{{ not currently_charging }}" + then: + - service: input_datetime.set_datetime + target: + entity_id: input_datetime.tesla_last_start + data: + datetime: "{{ now().isoformat() }}" - - service: input_datetime.set_datetime - target: - entity_id: input_datetime.tesla_last_start - data: - datetime: "{{ now().isoformat() }}" - - - service: switch.turn_on - target: - entity_id: switch.home_charging + - service: switch.turn_on + target: + entity_id: switch.home_charging # ------------------------- # STOP CHARGING (med hysterese) # ------------------------- - conditions: - condition: template - value_template: > - {{ not should_charge and runtime > 3600 }} - + value_template: "{{ currently_charging and not should_charge and runtime > 3600 }}" sequence: - service: switch.turn_off target: