Hi there,
I’m trying to create an automation for my salt water pool chlorine generator. The time the chlorinator must be active and therefore generating chlorine is dependant on the temperature of the water. The hotter it is, the more chlorine is required.
So I want an automation that switches the chlorinator on at sunset and turns off some time later, where the time is determined by pool temp (deg C) * 12. IE for every degree the chlorinator runs for 12 minutes.
My config info is below.
The trouble is that I don’t seem to be able to use any sort of variable for timer duration. The config below, for example, gives the error: extra keys not allowed @ data['data_template']
Is there any other option?
I have a sensor that determines this time:
## Pool chlorinator time needed
- platform: template
sensors:
chlorinate_time:
value_template: >-
{% set time = (states('sensor.pool_temp')|float)|round * 720 %}
{% set minutes = ((time % 3600) / 60) | int %}
{% set hours = ((time % 86400) / 3600) | int %}
"{{ "%02d" | format(hours) }}:{{"%02d" | format(minutes)}}"
sensor.chlorinate_time returns a value like “02:36”
I have a timer set in configuration.yaml:
## timers
timer:
pool_pm:
And I have two automations (nb the chlorinator uses a climate integration as a hack, there is no pool chlorinator component):
- id: chlorinator-on-pm
alias: chlorinator-on-pm
description: 'Turn on pool chlorinator at sunset'
trigger:
- event: sunset
platform: sun
condition: []
action:
- service: climate.set_temperature
data:
entity_id: climate.chlorinator
temperature: 100
- service: timer.start
data_template:
entity_id: timer.pool_pm
duration: '{{states('sensor.chlorinate_time')}}'
- id: chlorinator-off-pm
alias: chlorinator-off-pm
description: Turn off pool chlorinator after temp-calc duration
trigger:
- event_data:
entity_id: timer.pool_pm
event_type: timer.finished
platform: event
condition: []
action:
- data:
entity_id: climate.chlorinator
temperature: 0
service: climate.set_temperature