- alias: Tesla failsafe charge
  trigger:
    - platform: template
      value_template: >
        {% set deadline_ts = as_timestamp(states('input_datetime.tesla_charge_deadline')) %}
        {% if deadline_ts %}
          {% set now_ts = as_timestamp(now()) %}
          {{ (deadline_ts - now_ts) <= 3600 }}
        {% else %}
          false
        {% endif %}
  condition:
    - condition: template
      value_template: >
        {{
          states('sensor.snowywhite_battery') | float(0)
          < states('number.snowywhite_charge_limit') | float(100)
        }}
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.home_charging
