Hi,
I need your help. To run a filtration pump several times a day for one hour, I need automation. So far I’ve created four automations for it, but I think it’s certainly easier.
- id: poolpumpe_an
alias: Poolpumpe an Automation
initial_state: 'on'
condition:
- condition: state
entity_id: input_boolean.automation_poolpumpe
state: 'on'
trigger:
platform: time
at: '8:00:00'
action:
- service: switch.turn_on
entity_id:
- switch.poolpumpe
- id: poolpumpe_aus
alias: Poolpumpe aus Automation
initial_state: 'on'
condition:
- condition: state
entity_id: input_boolean.automation_poolpumpe
state: 'on'
trigger:
platform: time
at: '9:00:00'
action:
- service: switch.turn_off
entity_id:
- switch.poolpumpe
@123 - what would happen if HA is restarted while the pump is running?
Does the ‘for’ trigger still count until the hour is over or would it run until the next on trigger comes around or would the pump run for 1h after the reboot?
as long HA knows that the switch.poolpumpe has the state ’ on ’ yes
‘worst’ thing that can happen is that the pump is running for ~ 01:59:40 hours (when the restart is timed right)
So, if I want to be on the safe side I should probably use the following as a 3rd automation - with the one you wrote as the 2nd one as a fallback in case something strange happens:
- id: poolpumpe_aus
alias: Poolpumpe aus Automation
trigger:
- platform: time
at: '10:00:00'
- platform: time
at: '13:00:00'
- platform: time
at: '19:00:00'
- platform: time
at: '22:00:00'
- service: switch.turn_off
entity_id: switch.poolpumpe
Explicitly specifying the 'off time` is probably the most conservative and reliable way of avoiding scheduling problems that may occur after a restart.
Given Home Assistant’s inability to preserve timers (including the invisible one used with for) after a restart, if someone wanted total reliability they should probably avoid using them. However, that removes some useful tools from the toolbox.
If you intend to specify the precise ‘off time’ then there’s no need to use the for statement as I’ve shown. In other words, 2 automations is sufficient and there’s no need for 3 of them.
As I mentioned in my previous post, there’s no need to use three automations. Two automations dedicated to turning off the pump is unnecessarily redundant. If you are concerned about restarts then simply use an automation with explicit off-times and remove the automation that uses the for qualifier. This is not an issue of “better too much than too little”. Using two automations to turn off the pump is “not understanding how the two automations work”.
I’ve noticed a growing trend in this community where a user takes someone else’s idea(s), makes one immaterial change (or even none at all), then re-posts it as their “solution”. Despite the fact they originally didn’t know the answer, asked for help, were given it, then chose to re-package the supplied answer as their own solution. Even worse, sometimes the re-packaged ‘solution’ is incorrect or employs bad practices (the so-called “solution” serves to mislead other users). Team/community-building is not enhanced by re-branding other people’s ideas as your own.
There’s also a way of achieving ‘time trigger 4 times a day’ using a single automation but I’ll leave that for you as an exercise.