You’re almost there!
If you go back and reread my previous reply, I explained that you need to split the automation up. You didn’t do that. You have nothing there that will stop the automation if the timer is cancelled. You also left that delay in, which you don’t need.
You can actually do this in one automation. I just didn’t want to confuse you with additional elements. Anyway, I put it together here for you here. Have a good look so you understand what is happening.
The other change I would make is you just created a button card, not a button helper. Although the way you did this it will technically work it’s not the best practice.
In the same place you created your timer (Helpers Page) you should create a button helper. I would do that first. If you name that button “Open House” this code should work without changes.
- Pressing the new button helper you just created triggers the automation
- The switch turns on (I assume for building door)
- Timer starts (I assume 30 seconds - if not change the wait_for_trigger timeout to match)
- The automation now waits for the timer to finish.
- If the timer does not finish (because you cancelled it) the automation stops here (
continue_on_timeout: false)
- When the timer finishes the automation continues and runs your apartment door script.
You should be able to copy this and paste this into the automation YAML editor exactly the way it is. Make sure you delete everything else in the editor before pasting.
alias: openhouse
description: ''
trigger:
- platform: event
event_type: button.press
event_data:
entity_id: button.open_house
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.sonoff_10007a20b2
- service: timer.start
data: {}
target:
entity_id: timer.upstairs
- wait_for_trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.upstairs
timeout: 30
continue_on_timeout: false
- service: script.opendoorappartment
mode: restart
BTW if you want to simplify, you can get rid of the button card and replace it with just the button entity in an entities card. I’m showing you this so you understand the difference between a button entity and a button card. Try adding both to your lovelace view so you can see the difference, then delete the one you don’t want (probably the entities card).
Option 1 - Entities Card
- type: entities
entities:
- entity: button.open_house
Option 2 - Button Card
I also added in the double tap to run the openappartment script immediately without waiting for the timer to finish also since I have the entity_id now.
- type: button
entity: button.open_house
tap_action:
action: call-service
service: button.press
service_data:
entity_id: button.open_house
double_tap_action:
action: call-service
service: script.opendoorappartment
When you get all this working, get back to me. There is one change you should really make to script.opendoorappartment
to make sure the apartment door doesn’t try to open twice. I’ll help you do that once you’ve got this part working.