This is a hot water recirculation system? I have one and have a very similar situation with multiple buttons and timers.
Is it correct that the physical switch is really like an on/off wall switch, and you want to turn the pump on only when you turn the switch on? (Turning it "off" does nothing?) I'm confused because the entity name seems like a Shelly 1 Mini relay.
And switch.shellyplus1pm_80646fe3598c is the pump, correct?
This is all correct?
- The pump can be started a few different ways
- The pump can only run for three minutes
- Once the pump is started it should not run again for 30 minutes
And this is always the case -- you wouldn't want to manually run the pump for, say, two hours.
You are right to use timers. If your pump switch has an auto-off parameter considering setting that too -- as you don't want to to keep running if HA stops.
May I suggest thinking about it a bit differently? Focus on events. You can avoid all the wait_for_trigger and the odd condition on when the automation last run as well as the redundant control of the pump.
Start with separate automations:
#1 Automation
Trigger: pump turns on: (not just from off, but maybe from unavailable. So just "on")
Actions:
- set the pump turn off timer (3 minutes)
- set a separate 30 minute time
#2 Automation
Trigger 3 minute timer finished
Action: turn off pump
#3 Automation
Triggers: (switch, HA button, etc)
Conditions:
- someone is home. (zone.home > 0)
- 30 minute timer is not running
Action: turn on the pump.
Extra: #4 might be when HA starts check if the pump is on and the timer is off, and set the 3 minute timer or just turn off the pump. This is because the timer might finish when HA is off.
Of course, those can be combined into a single automation.
Minor tip: if you name your devices after the things they are controlling (instead after the name of the device) you might find in six months the automations are easier to understand, and/or if you replace a device you don't have to edit your automations again.
Then the UI stuff is separate. If you use the template button with it being unavailable when the pump is running (or maybe when the 30 minute timer is running) you can make it not something that can be pushed. But it doesn't really matter as pushing it won't do anything until 30 minutes is up.