Now that my pool is automated, in that I can control everything remotely and set schedules in Node-RED, I’d like to be able to enter a date and time in Lovelace, as well as a target temperature, and then have Node-RED start heating the pool at the appropriate time. Right now, I’m just using historical data to figure out what that time is, ignoring ambient temperature, UV index, etc… but maybe down the road I can figure those in.
For now, I’m just trying to get the syntax for my template entities right. I don’t code, so I’m trying to adapt syntax from other template entities I’ve seen online. Here’s my approach:
input_number.pool_target_temp
is the temperature I want to set the pool to, and
input_datetime.pool_target_temp_time
is the time I want to hit that temperature.
I’ve also added an input_boolean
to “enable” this schedule; that will kick off my Node-RED flow.
Based on a little bit of data, I figure the heater can heat the pool 15 degrees over 6 hours, so to figure out the hours required to get from the current temperature to the target temperature, I need to multiply the temp delta by 0.4.
Here are the template entities I’ve added to configuration.yaml
:
pool_heating_interval:
value_template: >
{% set currenttemp = states('sensor.pool_thermostat_water_temperature') | int %}
{% set newtemp = states('input_number.pool_target_temp') | int %}
{% set tempdelta = (newtemp - currenttemp) | int %}
{% set timeinterval = (tempdelta * 0.4) | float %}
{{ '%2i'%(timeinterval) }}
# pool_heater_start_time:
# value_template: >
# {{ as_timestamp(states('input_datetime.pool_target_temp_time')) - as_timestamp(states('sensor.pool_heating_interval')) }}
pool_heater_start_time
is commented out thusfar, because I realize that sensor.pool_heating_interval is just going to give me an hour count; it’s not a timestamp. I need help with the date math. However, pool_heating_interval
doesn’t even work, and because I don’t know what I’m doing… I’m not sure why. Can anyone check my work?
EDIT: I got the interval correct! It’s working in HA. The corrected YAML is above. The current temp is 77, the target is 70, and sensor.pool_heating_interval
is equal to -2… which is technically correct, but maybe I should figure out how to only set that template entity to positive values…
Now that I can get the hours needed to heat the pool, I just need some help with my date math for pool_heater_start_time
.
EDIT 2: OK… this works from a syntax perspective, but my pool_heater_start_time
is unavailable:
pool_heater_start_time:
value_template: >
{% set hoursneeded = states('pool_heating_interval') | float %}
{{ as_timestamp(states('input_datetime.pool_target_temp_time')) - timedelta(hours = hoursneeded) }}
Where am I going wrong?