Nu virker det

This commit is contained in:
2026-03-22 07:49:16 +01:00
parent 5e368938bc
commit 1dc0866fe3
+36 -26
View File
@@ -1,5 +1,5 @@
- alias: Tesla smart charging v3 - alias: Tesla smart charging v4
id: tesla_smart_charging_v3 id: tesla_smart_charging_v4
mode: restart mode: restart
trigger: trigger:
@@ -7,55 +7,65 @@
minutes: "/5" minutes: "/5"
condition: condition:
# Ensure deadline is valid and in the future # Valid future deadline
- 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()) }}
# Only run when car is connected # Car must be connected
- condition: template - condition: state
value_template: > entity_id: binary_sensor.snowywhite_charger
{{ states('binary_sensor.tesla_connected') == 'on' }} state: "on"
action: action:
- variables:
charge_now: "{{ is_state('binary_sensor.tesla_charge_now', 'on') }}"
charger_on: "{{ is_state('switch.home_charging', 'on') }}"
- choose: - choose:
# ------------------------- # -------------------------
# Charge if cheap # START charging (cheap hour)
# ------------------------- # -------------------------
- conditions: - conditions:
- condition: template - condition: template
value_template: > value_template: "{{ charge_now and not charger_on }}"
{{ states('binary_sensor.tesla_charge_now') == 'on' }}
sequence: sequence:
# Reset charger if stuck in finished state - service: system_log.write
- choose: data:
- conditions: message: "Tesla: START charging (cheap hour)"
- condition: template level: info
value_template: >
{{ states('sensor.home_charger_mode') == 'connected_finished' }}
sequence:
- service: switch.turn_off
target:
entity_id: switch.home_charging
- delay: "00:00:05"
# Turn charger on
- service: switch.turn_on - service: switch.turn_on
target: target:
entity_id: switch.home_charging entity_id: switch.home_charging
# ------------------------- # -------------------------
# Stop charging if not cheap # STOP charging (not cheap)
# ------------------------- # -------------------------
- conditions: - conditions:
- condition: template - condition: template
value_template: > value_template: "{{ not charge_now and charger_on }}"
{{ states('binary_sensor.tesla_charge_now') != 'on' }}
sequence: sequence:
- service: system_log.write
data:
message: "Tesla: STOP charging (not cheap)"
level: info
- service: switch.turn_off - service: switch.turn_off
target: target:
entity_id: switch.home_charging 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