Okay so i got a functioning automation:
id: '1613303438594'
alias: carheater_master
description: ''
trigger:
- platform: template
value_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 number in seconds from midnight. #}
{% set timenow = now().hour * 3600 + now().minute * 60 + now().second %}
{# this sets your 'settime' as a number from your input sensor and stores in settime #}
{% set settime = (state_attr('input_datetime.motorvarmare2','timestamp')) %}
{# this gets the temperature (as a float, as that will aid in resolution) #}
{% set tempdeg = states('sensor.termometer_ute_ch4_temperature')| float %}
{# this gets the minute offset from the start based on the temperature#}
{% set offset_mins = ((-2 * tempdeg) + 60) | int %}
{# given the 'offset' we now have a new 'start time' calculated, based on temperature #}
{% set heatstart = settime - (offset_mins * 60) %}
{# this will render true when its time to start the heter and trigger the automation #}
{% if timenow >= heatstart %} true {% else %} false {% endif%}"
- platform: state
entity_id: input_boolean.motorvarmare2
to: 'on'
condition: []
action:
- service: switch.turn_on
data: {}
entity_id: switch.shellyswitch25_84cca8b07a6d_channel_2
- delay: 02:00:00
- service: switch.turn_off
data: {}
entity_id: switch.shellyswitch25_84cca8b07a6d_channel_2
- service: input_boolean.turn_off
data: {}
entity_id: input_boolean.motorvarmare2
mode: single
But now i can’t get the blueprint to work properly.
the blueprint now looks like this:
blueprint:
name: Carheater based on outside temperature
description: 'Will start the car heater based on the formula y= -2*x+60 meaning 0deg C= 60min, -15deg C=90min Note: Requires two helpers Time(input_datetime) sensor with time only and toggle(input_boolean) for manual activation. Configuration->Helpers->add helper'
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'
selector:
entity:
domain: input_datetime
manual_boolean:
name: Manual activation
description: 'Input boolean used for manual activation'
selector:
entity:
domain: input_boolean
outside_temperature:
name: Outside temperature sensor
description: 'Outside temperature sensor'
selector:
entity:
device_class: temperature
delay_time:
name: The maximum time for the heater to run
description: 'The maximum time for the heater to run, default 2h'
default: 02:00:00
selector:
time:
variables:
sensor: !input timestamp_sensor
outside_temperature: !input outside_temperature
trigger:
- platform: template
value_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 number in seconds from midnight. #}
{% set timenow = now().hour * 3600 + now().minute * 60 + now().second %}
{# this sets your 'settime' as a number from your input sensor and stores in settime #}
{% set settime = (state_attr('sensor','timestamp')) %}
{# 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 = ((-2 * tempdeg) + 60) | int %}
{# given the 'offset' we now have a new 'start time' calculated, based on temperature #}
{% set heatstart = settime - (offset_mins * 60) %}
{# this will render true when its time to start the heter and trigger the automation #}
{% if timenow >= heatstart %} true {% else %} false {% endif%}"
- platform: state
entity_id: !input manual_boolean
to: 'on'
action:
- service: switch.turn_on
entity_id: !input switch_entity
- delay: !input delay_time
- service: switch.turn_off
entity_id: !input switch_entity
- service: input_boolean.turn_off
entity_id: !input manual_boolean
mode: single
but apparently having variables in triggers is not supported…