Okay, so Ive started to put som code together, tanks to @marieper and the Wake-up light alarm with sunrise effect
Home assistant does not accept the code with the tamplate action but i think i got the input selections right.
When i try to import the blueprint i get this fault message "
Failed to load blueprint: while scanning for the next token found character ‘%’ that cannot start any token in “/config/blueprints/automation/Egna/car_heater_v01.yaml”, line 42, column 6
Maybe someone who actually know how write templates could help out with that bit?
I tried to replace the departure time with a input_datetime helper and changed the formula
blueprint:
name: Carheater based on outside temperature
description: 'Note: Requires time sensor in configuration and input boleean for manual activation'
domain: automation
input:
switch_entity:
name: Car heater outlet
description: The outlet to control.
selector:
entity:
domain: switch
timestamp_sensor:
name: Alarm timestamp sensor
description: 'Sensor with timestamp of departure time'
default: none
selector:
entity:
domain: input_datetime
outside_temperature:
name: Outside temperature sensor
description: 'Outside temperature sensor'
selector:
entity:
device_class: temperature
variables:
switch_entity: !input 'switch_entity'
timestamp_sensor: !input 'timestamp_sensor'
outside_temperature: !input 'outside_temperature'
trigger:
- platform: time_pattern
minutes: '*'
condition:
- condition: template
value_template: '{{ states(''outside_temperature'') | float <= 10
}}'
action:
- service_template: >
# This is a jinja comment and will be ignored by the interpreter
# ALL the below is indented more than it needs to be to show the comments more clearly # }
# This next line (all comments will be as this) gets the time RIGHT NOW and stores it as a
# HUGE number that has both date and time #}
{% set timenow = as_timestamp(now()) %}
# this gets your input time
{% set dept_time = states('timestamp_sensor') | int %}
# this sets your 'settime' as a huge number and stores in settime #}
{% set settime = as_timestamp(now().strftime("%Y-%m-%d " ~ '{0:0=2d}:{1:0=2d}'.format(dept_time))) %}
# as we've already done most of the work we just subtract 3 hours from the
set time to start our evaluation #}
{% set starttime = settime - (2*60*60) %}
# this tests to see if we are 'in' the 'slot' #}
{% set slot = (starttime <= timenow < settime) %}
# this gets the temperature (as a float, as that will aid in resolution) #}
{% set tempdeg = states('outside_temperature') | float %}
# this gets the minute offset from the start based on the temperature #}
{% set offset_mins = ((-0,5 * tempdeg) + 30) | int %}
# given the 'offset' we now have a new 'start time' calculated, based on temperature #}
{% set heatstart = settime - (offset_mins * 60) %}
# this tests that we are (now) in the 'slot' and 'that switch on time' is in the past #}
{% set heat = slot and timenow >= heatstart %}
# this uses the last evaluation to determine if we switch 'on' or 'off' #}
{% if heat %}
switch.turn_on
# switch.turn_off is managed by separate automation that monitors the entity_id being ON for x:y hrs #}
{% endif %}
entity_id: switch_entity
initial_state: true
mode: single
max_exceeded: silent