################################################################################################## # Car heater package # # Version 1.1.4 last changed 2019-09-23 # # Created for and tested with Home Assistant Hassio version 0.86.4 # # Creator Mikael Danell SHG # # Inspiration and code from: # # https://github.com/Danielhiversen/home-assistant_config/blob/master/packages/alarm_clock.yaml # # https://community.home-assistant.io/t/creating-a-alarm-clock/410 # ################################################################################################## # Automation section automation: # triggers 3h before departure time when temp is below -20 and heater status is on, checks if weekend/weekday matches option - alias: "heater minus 20" initial_state: false trigger: - platform: time_pattern minutes: '/5' seconds: 2 condition: condition: or conditions: - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '-20' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 10800 ) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'on' - condition: time weekday: - mon - tue - wed - thu - fri - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '-20' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 10800 ) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'off' action: - service: script.turn_on entity_id: script.heater_on - service: homeassistant.turn_off entity_id: automation.heater_minus_20, automation.heater_minus_10, automation.heater_plus_1, automation.heater_plus_5 # triggers 2h before departure time when temp is below -10 and heater status is on, checks if weekend/weekday matches option - alias: "heater minus 10" initial_state: false trigger: - platform: time_pattern minutes: '/5' seconds: 2 condition: condition: or conditions: - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '-10' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 7200 ) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'on' - condition: time weekday: - mon - tue - wed - thu - fri - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '-10' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 7200 ) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'off' action: - service: script.turn_on entity_id: script.heater_on - service: homeassistant.turn_off entity_id: automation.heater_minus_20, automation.heater_minus_10, automation.heater_plus_1, automation.heater_plus_5 # triggers 1h before departure time when temp is below 1 and heater status is on, checks if weekend/weekday matches option - alias: "heater plus 1" initial_state: false trigger: - platform: time_pattern minutes: '/5' seconds: 2 condition: condition: or conditions: - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '1' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 3600 ) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'on' - condition: time weekday: - mon - tue - wed - thu - fri - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '1' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 3600) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'off' action: - service: script.turn_on entity_id: script.heater_on - service: homeassistant.turn_off entity_id: automation.heater_minus_20, automation.heater_minus_10, automation.heater_plus_1, automation.heater_plus_5 # triggers 30min before departure time when temp is below 5 and heater status is on, checks if weekend/weekday matches option - alias: "heater plus 5" initial_state: false trigger: - platform: time_pattern minutes: '/5' seconds: 2 condition: condition: or conditions: - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '5' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 1800) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'on' - condition: time weekday: - mon - tue - wed - thu - fri - condition: and conditions: - condition: numeric_state entity_id: sensor.heater_outside_temp below: '5' - condition: template value_template: '{{ ((as_timestamp(now()) | int + 1800) | timestamp_custom("%H:%M")) == states.sensor.departuretime.state }}' - condition: state entity_id: input_boolean.heaterstatus state: 'on' - condition: state entity_id: input_boolean.heaterweekday state: 'off' action: - service: script.turn_on entity_id: script.heater_on - service: homeassistant.turn_off entity_id: automation.heater_minus_20, automation.heater_minus_10, automation.heater_plus_1, automation.heater_plus_5 # activates the automations that will trigger the heater depending on temp if the function is activated - alias: "heater enabled" initial_state: true trigger: platform: time at: 02:00 condition: - condition: state entity_id: input_boolean.heaterstatus state: 'on' action: service: homeassistant.turn_on entity_id: automation.heater_minus_20, automation.heater_minus_10, automation.heater_plus_1, automation.heater_plus_5 # Turns the heater off when leaving time is reached - alias: "heater off" initial_state: false trigger: - platform: time_pattern minutes: '/5' seconds: 2 condition: - condition: template value_template: "{{ ((as_timestamp(now()) | int | timestamp_custom('%H:%M')) == states('sensor.engineheaterofftime')) }}" action: - service: light.turn_off entity_id: light.motorvarmare - service: homeassistant.turn_off entity_id: automation.heater_off # Input section input_number: heater_hour: name: Timmar icon: mdi:timer min: 0 max: 23 step: 1 heater_minutes: name: Minuter icon: mdi:timer min: 0 max: 55 step: 5 # Bolean section input_boolean: heaterstatus: name: Aktivera initial: on icon: mdi:check-outline heaterweekday: name: Endast vardagar initial: on icon: mdi:calendar # Sensor section sensor: - platform: template sensors: outside_temperature: friendly_name: "Outside Temperature" unit_of_measurement: '°C' value_template: "{{ state_attr('weather.home', 'temperature') }}" - platform: template sensors: departuretime: friendly_name: 'Avresetid' value_template: '{% if states.input_number.heater_hour.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_number.heater_hour.state|round(0)|string }}:{% if states.input_number.heater_minutes.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_number.heater_minutes.state|round(0)|string }}' # Create our stop time 30 minutes past the departure time, this give # us some headroom so the car is still hot even if we are late - platform: template sensors: engineheaterofftime: friendly_name: 'Avtid' value_template: "{{ (states('input_number.heater_hour') | int * 3600 + states('input_number.heater_minutes') | int * 60 + 1800) | timestamp_custom('%H:%M', false) }}" ############ Outside sensor config ############ - platform: template sensors: heater_outside_temp: friendly_name: 'Utomhus temperatur' value_template: "{{ states('outside_temperature') }}" ## Change to local temperature source # Group section group: heater_controls: name: "Styrning" entities: - automation.heater_enabled - automation.heater_off - automation.heater_minus_20 - automation.heater_minus_10 - automation.heater_plus_1 - automation.heater_plus_5 - script.heater_on # Script section script: # turns on the heater and activates the trigger that will turn it off heater_on: sequence: - service: light.turn_on entity_id: light.motorvarmare - service: homeassistant.turn_on entity_id: automation.heater_off