62 lines
1.9 KiB
YAML
62 lines
1.9 KiB
YAML
- alias: Tesla smart charging v3
|
|
id: tesla_smart_charging_v3
|
|
mode: restart
|
|
|
|
trigger:
|
|
- platform: time_pattern
|
|
minutes: "/5"
|
|
|
|
condition:
|
|
# Ensure deadline is valid and in the future
|
|
- condition: template
|
|
value_template: >
|
|
{% set deadline = states('input_datetime.tesla_charge_deadline') %}
|
|
{{ deadline not in ['unknown','unavailable',''] and as_timestamp(deadline) > as_timestamp(now()) }}
|
|
|
|
# Only run when car is connected
|
|
- condition: template
|
|
value_template: >
|
|
{{ states('binary_sensor.tesla_connected') == 'on' }}
|
|
|
|
action:
|
|
- choose:
|
|
|
|
# -------------------------
|
|
# Charge if cheap
|
|
# -------------------------
|
|
- conditions:
|
|
- condition: template
|
|
value_template: >
|
|
{{ states('binary_sensor.tesla_charge_now') == 'on' }}
|
|
|
|
sequence:
|
|
# Reset charger if stuck in finished state
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
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
|
|
target:
|
|
entity_id: switch.home_charging
|
|
|
|
# -------------------------
|
|
# Stop charging if not cheap
|
|
# -------------------------
|
|
- conditions:
|
|
- condition: template
|
|
value_template: >
|
|
{{ states('binary_sensor.tesla_charge_now') != 'on' }}
|
|
|
|
sequence:
|
|
- service: switch.turn_off
|
|
target:
|
|
entity_id: switch.home_charging
|