I want to start my pool pump from lovelance button. The pump skall run for 30 minutes and then stop.
I have tryed to use the Timer integration and a script but I don´t understand how I should do it.
Sequence:
Press Lovelance button
Start pump
Start timer
Wait for timer to run out
Stop pump
My problem is I want to check on the event “timer.finished” but I dont understand how I should do that in a script.
You can’t check the event in a script.
You need to use an automation for that (at least as far as I know).
I would suggest the script starts the pump and sets a input datetime with now() + 30 minutes, then have an automation trigger on after input datetime to turn off the pump.
That way you are not relying on HA being online the duration of the pump cycle.
It can be rebooted and when back online if time has passed 30 minutes it will turn off the pump.
Yes this can be done with an automation and by making a lovelace button for the switch.
Automations are set via Settings / Automations
Automation example:
`# Example automations.yaml entry
- alias: "Timerswitch"
id: "Timerstart"
# Timer is started when the switch pumprun is set to on.
trigger:
- platform: state
entity_id: switch.pumprun
to: "on"
action:
- service: timer.start
target:
entity_id: timer.test
# When timer is stopped, the time run out, another message is sent
- alias: "Timerstop"
id: "Timerstop"
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.test
action:
- service: `switch.turn_off
data:
entity_id: switch.pumprun
You can also consider to add a Helper input boolean here. If you add an automation based on the triggering of the switch that controls the pump, it will always stop after 30 minutes. Don’t know if that’s the desired behaviour?
If you add this input_boolean as a switch to Lovelace, you can make an automation to start the pump switch including the 30 minutes, based on this input boolean. That way you can still switch the pump manually on without the limit of 30 minutes.
What’s the difference between toggle a input_boolean and a switch?
The boolean is not needed since it will only be a duplicate entity that could be out of phase.
It gives you two possibilties, the input_boolean will start an automation in which the pump is being run for 30 minutes. Switching the switch.pump direclty will run it indefinitely untill you manually turn off.
You can add an extra automation for the input boolean to be turned off too, when the switch is manually turned to off while input boolean is on. Then they won’t be out of phase.
Delay is acceptable if it is short but 30 minutes is long running out of electric, restarting home assistant (unintentionally :-)) etc will break the sequence, so it is better to rely on state machine rather than time keeping.
Agree, but OP is using a UI element to start pump for 30mins. You don’t usually restart HA immediately after. And you can’t press that button when grid is down.
But it can go down.
And OP might be working on automations then just realizes that he needs to start the pump, a few minutes later he saves an automation and the automations are cancelled and reloaded.
I honestly think that delays should be limited to one minute in the automations, it would clear so many issues