tesla charging

This commit is contained in:
2026-03-24 18:24:58 +01:00
parent 6b6b69b766
commit 64032e6682
3 changed files with 41 additions and 108 deletions
+36 -33
View File
@@ -1,71 +1,74 @@
- alias: Tesla smart charging v4
id: tesla_smart_charging_v4
- alias: Tesla smart charging PRO
id: tesla_smart_charging_pro
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:
# Valid future deadline
# 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()) }}
{{ deadline not in ['unknown','unavailable',''] and as_timestamp(deadline) > as_timestamp(now()) }}
# Car must be connected
- condition: state
entity_id: binary_sensor.snowywhite_charger
state: "on"
# Kun når bilen er tilsluttet
- condition: template
value_template: >
{{ states('binary_sensor.tesla_connected') == 'on' }}
action:
- variables:
charge_now: "{{ is_state('binary_sensor.tesla_charge_now', 'on') }}"
charger_on: "{{ is_state('switch.home_charging', 'on') }}"
should_charge: "{{ states('binary_sensor.tesla_charge_now') == 'on' }}"
last_start: "{{ states('input_datetime.tesla_last_start') }}"
last_start_ts: >
{% if last_start not in ['unknown','unavailable',''] %}
{{ as_timestamp(last_start) }}
{% else %}
0
{% endif %}
runtime: "{{ as_timestamp(now()) - last_start_ts }}"
- choose:
# -------------------------
# START charging (cheap hour)
# START / CONTINUE CHARGING
# -------------------------
- conditions:
- condition: template
value_template: "{{ charge_now and not charger_on }}"
value_template: "{{ should_charge }}"
sequence:
- service: system_log.write
# Hvis ikke allerede i gang → registrer start
- condition: template
value_template: >
{{ states('switch.home_charging') != 'on' }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.tesla_last_start
data:
message: "Tesla: START charging (cheap hour)"
level: info
datetime: "{{ now().isoformat() }}"
- service: switch.turn_on
target:
entity_id: switch.home_charging
# -------------------------
# STOP charging (not cheap)
# STOP CHARGING (med hysterese)
# -------------------------
- conditions:
- condition: template
value_template: "{{ not charge_now and charger_on }}"
value_template: >
{{ not should_charge and runtime > 3600 }}
sequence:
- service: system_log.write
data:
message: "Tesla: STOP charging (not cheap)"
level: info
- service: switch.turn_off
target:
entity_id: switch.home_charging
# -------------------------
# Default: do nothing
# -------------------------
- service: system_log.write
data:
message: >
Tesla: No action (charge_now={{ charge_now }},
charger_on={{ charger_on }})
level: debug