Create a time-only input_datetime helper called input_datetime.pump_start
.
In the Lovelace UI, set its value to the desired start time (11:00
).
Create a Template Sensor called sensor.pump_stop
whose device_class is timestamp
. The template uses sensor.season
to determine the pump’s duration (in hours) and adds it to the value of input_datetime.pump_start
. The result is the time when the pump should stop.
template:
- sensor:
- name: Pump Stop
device_class: timestamp
state: >
{% set hrs = {'Spring': 6, 'Summer': 8, 'Autumn': 6, 'Winter': 6}.get(states('sensor.season'), 6) %}
{{ today_at(states('input_datetime.pump_start')) + timedelta(hours=hrs) }}
Now you have an input_datetime to set the pump’s start time and a timestamp sensor that automatically computes a seasonally-adjusted stop time.
The following automation controls the pump’s operation.
- id: scheduled_pool_pump
alias: Scheduled Pool Pump
trigger:
- id: on
platform: time
at: input_datetime.pool_start
- id: off
platform: time
at: sensor.pool_stop
condition: []
action:
- service: 'homeassistant.turn_{{ trigger.id }}'
target:
device_id: 0732ac3b46a11b0a6718f1af93ae53dd
Restarting Home Assistant (or executing Reload Automations) won’t affect the pump’s scheduled operations (unless, of course, you restart exactly at the scheduled on/off times … and there are ways to mitigate that as well).