##############################
#Car preheat timing start
- id: start-car-preheat
alias: Start car preheat on time
trigger:
#Check status every 5 minutes, as template trigger only trips the automation on state change
- platform: time
minutes: '/5'
seconds: 0
condition:
- condition: and
conditions:
- condition: template
value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) >= ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) + states.sensor.preheatstarttime.state.split(":")[1] |int)}}'
- condition: template
value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) <= ((states.input_datetime.embarktime.state.split(":")[0] |int * 60) + states.input_datetime.embarktime.state.split(":")[1] |int + 60)}}'
- condition: state
entity_id: switch.telldus_tzwp102_plugin_switch_switch
state: 'off'
- condition: state
entity_id: input_boolean.preheatswitch
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.telldus_tzwp102_plugin_switch_switch
##############################
#Car preheat timing stop
- id: stop-car-preheat
alias: Stop car preheat 60 minutes after embarktime
trigger:
#Check status every 5 minutes, as template trigger only trips the automation on state change
- platform: time
minutes: '/5'
seconds: 0
condition:
- condition: state
entity_id: switch.telldus_tzwp102_plugin_switch_switch
state: 'on'
- condition: state
entity_id: input_boolean.preheatswitch
state: 'on'
- condition: or
conditions:
- condition: template
value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) < ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) + states.sensor.preheatstarttime.state.split(":")[1] |int)}}'
- condition: template
value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) > ((states.input_datetime.embarktime.state.split(":")[0] |int * 60) + states.input_datetime.embarktime.state.split(":")[1] |int + 60)}}'
action:
- service: switch.turn_off
entity_id: switch.telldus_tzwp102_plugin_switch_switch
- service: input_boolean.turn_off
entity_id: input_boolean.loosepowercordnotified
#Check if power cord is plugged
- id: car-power-cord-check
alias: 'Check if heater power cord is plugged'
trigger:
- platform: time
hours: "/1"
minutes: 0
seconds: 0
condition:
- condition: state
entity_id: input_boolean.preheatswitch
state: 'on'
- condition: state
entity_id: input_boolean.loosepowercordnotified
state: 'off'
- condition: or
conditions:
- condition: template
value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) < ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) + states.sensor.preheatstarttime.state.split(":")[1] |int)}}'
- condition: template
value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) > ((states.input_datetime.embarktime.state.split(":")[0] |int * 60) + states.input_datetime.embarktime.state.split(":")[1] |int + 60)}}'
- condition: or
conditions:
- condition: template
# This means that embark time is set for tomorrow, so we will check the power cord attachment between 8pm and 22pm
value_template: '{{(((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) + states.sensor.preheatstarttime.state.split(":")[1] |int)) and (now().hour <= 22) and (now().hour >= 18)}}'
# This means that embark time is set for today. We will check the power cord attachment right after 8am
- condition: template
value_template: '{{(((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) < ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) + states.sensor.preheatstarttime.state.split(":")[1] |int)) and (now().hour > 8) and (now().hour <= 22)}}'
action:
- service: switch.turn_on
entity_id: switch.telldus_tzwp102_plugin_switch_switch
- delay: '00:00:30'
- service: notify.home_assistant_notifications
data_template:
message: |
{% if states('sensor.telldus_tzwp102_plugin_switch_power')|float < 10 %}
Embark time: {{states.input_datetime.embarktime.state.split(":")[0]}}:{{states.input_datetime.embarktime.state.split(":")[1]}}, preheat will start at {{states.sensor.preheatstarttime.state}}
{% if ((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) + states.sensor.preheatstarttime.state.split(":")[1] |int) %}Tomorrow it's {{(states.weather.yweather.attributes.forecast)[1].condition}} and {{(states.weather.yweather.attributes.forecast)[1].temperature}}°C
{% else %}Today it's {{(states.weather.yweather.attributes.forecast)[0].condition}} and {{(states.weather.yweather.attributes.forecast)[0].temperature}}°C
{% endif %}
Car preheat power cord is not plugged! :(
{% else %}
Embark time: {{states.input_datetime.embarktime.state.split(":")[0]}}:{{states.input_datetime.embarktime.state.split(":")[1]}}, preheat will start at {{states.sensor.preheatstarttime.state}}
{% if ((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1] |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) + states.sensor.preheatstarttime.state.split(":")[1] |int) %}Tomorrow it's {{(states.weather.yweather.attributes.forecast)[1].condition}} and {{(states.weather.yweather.attributes.forecast)[1].temperature}}°C
{% else %}Today it's {{(states.weather.yweather.attributes.forecast)[0].condition}} and {{(states.weather.yweather.attributes.forecast)[0].temperature}}°C
{% endif %}
Car preheat power cord is plugged! :)
{% endif %}
- service: switch.turn_off
entity_id: switch.telldus_tzwp102_plugin_switch_switch
- service: input_boolean.turn_on
entity_id: input_boolean.loosepowercordnotified
#Reset notify toggle after enabling preheat
- id: power-cord-notify-reset
alias: 'Reset notify toggle after enabling preheat'
trigger:
platform: state
entity_id: input_boolean.preheatswitch
from: 'off'
to: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.loosepowercordnotified