Fix Tesla smart charging hysteresis

This commit is contained in:
2026-04-06 13:01:06 +02:00
parent 57531a5a23
commit cd6643cd35
+19 -26
View File
@@ -3,29 +3,26 @@
mode: restart mode: restart
trigger: trigger:
# Kør hvert 5. min (responsiv)
- platform: time_pattern - platform: time_pattern
minutes: "/5" minutes: "/5"
# Sikrer re-evaluering ved ny time
- platform: time_pattern - platform: time_pattern
minutes: "0" minutes: "0"
condition: condition:
# Deadline gyldig
- condition: template - condition: template
value_template: > value_template: >
{% set deadline = states('input_datetime.tesla_charge_deadline') %} {% set deadline = states('input_datetime.tesla_charge_deadline') %}
{{ deadline not in ['unknown','unavailable',''] and as_timestamp(deadline) > as_timestamp(now()) }} {{ deadline not in ['unknown','unavailable',''] and as_timestamp(deadline) > as_timestamp(now()) }}
# Kun når bilen er tilsluttet - condition: state
- condition: template entity_id: binary_sensor.tesla_connected
value_template: > state: "on"
{{ states('binary_sensor.tesla_connected') == 'on' }}
action: action:
- variables: - 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: "{{ states('input_datetime.tesla_last_start') }}"
last_start_ts: > last_start_ts: >
{% if last_start not in ['unknown','unavailable',''] %} {% if last_start not in ['unknown','unavailable',''] %}
@@ -38,36 +35,32 @@
- choose: - choose:
# ------------------------- # -------------------------
# START / CONTINUE CHARGING # START CHARGING
# ------------------------- # -------------------------
- conditions: - conditions:
- condition: template - condition: template
value_template: "{{ should_charge }}" value_template: "{{ should_charge }}"
sequence: sequence:
# Hvis ikke allerede i gang → registrer start - if:
- condition: template - condition: template
value_template: > value_template: "{{ not currently_charging }}"
{{ states('switch.home_charging') != 'on' }} then:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.tesla_last_start
data:
datetime: "{{ now().isoformat() }}"
- service: input_datetime.set_datetime - service: switch.turn_on
target: target:
entity_id: input_datetime.tesla_last_start entity_id: switch.home_charging
data:
datetime: "{{ now().isoformat() }}"
- service: switch.turn_on
target:
entity_id: switch.home_charging
# ------------------------- # -------------------------
# STOP CHARGING (med hysterese) # STOP CHARGING (med hysterese)
# ------------------------- # -------------------------
- conditions: - conditions:
- condition: template - condition: template
value_template: > value_template: "{{ currently_charging and not should_charge and runtime > 3600 }}"
{{ not should_charge and runtime > 3600 }}
sequence: sequence:
- service: switch.turn_off - service: switch.turn_off
target: target: