Hi very bright peoples,
I am trying to set up a template calculation that starts my pool the correct number of hours before I want to go swimming.
So I have set up the variables:
In input_numbers.yaml
pool_desired_temp:
name: Desired pool temp
icon: mdi:thermometer-lines
initial: 29
min: 25
max: 32
step: 0.1
mode: box
In input_boolean.yaml
pool_temp_calc:
name: Calculate heating duration
initial: off
icon: mdi:calculator
In input_datetime.yaml
pool_end_time:
name: Pool end time
has_date: false
has_time: true
And in automations.yaml
- alias: Turn pool on at calculated time
trigger:
platform: template
value_template: '{{ (as_timestamp(states.sensor.time.state)) == (as_timestamp(states.input_datetime.pool_end_time.state)) - (((states.input_number.pool_desired_temp ā sensor.wirelesstag_pool_temp_temperature)/0.5)*3600) }}
condition:
condition: state
entity_id: input_boolean.pool_temp_calc
state: 'on'
action:
- service: switch.turn_on
data:
entity_id:
- switch.fibaro_system_fgs223_double_relay_switch
- switch.fibaro_system_fgs223_double_relay_switch_2
The 0.5 is used because the heater heats up the pool at 0.5 deg/hour.
I am turning my head into mush trying to work out how to calculate the trigger.
So far I think I have understood that:
āstates.sensor.time.stateā is better to use than ānow()ā because the latter is dependent on being triggered
āas_timestamp()ā is needed to convert standard time formats into seconds so that times can be used in calculations.
However I just canāt work out how to get the calculation to work. I havenāt even been able to get āas_timestamp(states.sensor.time.state)ā to work in the Template Editor. The result returned states āNoneā.
Thank you for your advice.