Hi, I’m still working on my idea, but it’s not very different from yours
However I still have trouble in managing the scenarios in which you press the button during the transaction from open to close (or the opposite). As soon as I go back to my pc I’ll post my version, maybe someone can fix that part
Finally I made it! I was struggling with some stupid typos… This is a quite simple yet quite complete, version. While I’m writing this I’m already noticing some space for improvements.
Prerequisite: create a three helpers
input_number.garage_door : used to keep track of the position of the door, express a % of aperture. Values: min 0, max 100. Step 10. Display mode: slider.
input_select.garage_door_direction: possible value are Up, Down, None
input_select.garage_door_current_state: possible value are Open, Cloed, Half-Way Closing, Half-Way Opening
You have to change the name of entity used to trigger the automation and adjust the “Delay” steps to better fit the timing of the door transitions from a state to another.
Automation:
Summary
alias: Automation of Garage Door
description: >-
It manages the opening, closing and stop/reverse direction of the garage door
with a single button.
triggers:
- entity_id: input_button.garage_button
trigger: state
actions:
- variables:
button_pressed_at: "{{ as_timestamp(states('input_button.garage_button', 'last_changed')) }}"
- choose:
- conditions:
- condition: or
conditions:
- condition: state
entity_id: input_select.garage_door_current_state
state: Closed
- condition: and
conditions:
- condition: state
entity_id: input_select.garage_door_current_state
state: Half-Way
- condition: state
entity_id: input_select.garage_door_direction
state: Down
alias: If Garage door was closing but interrupted
sequence:
- alias: Set current state to Half-Way
target:
entity_id: input_select.garage_door_current_state
data:
option: Half-Way
action: input_select.select_option
- alias: Set direction to Up
target:
entity_id: input_select.garage_door_direction
data:
option: Up
action: input_select.select_option
- alias: >-
Wait for the door to fully open or till the garage button has been
pressed again
repeat:
sequence:
- alias: Sleep
delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- action: input_number.increment
metadata: {}
data: {}
target:
entity_id: input_number.garage_door
until:
- condition: or
conditions:
- condition: numeric_state
entity_id: input_number.garage_door
above: 99
- alias: Garage button has been pressed again
condition: template
value_template: >-
{{ button_pressed_at !=
as_timestamp(states('input_button.garage_button','last_changed'))
}}
enabled: true
- alias: Set State and Direction
if:
- condition: template
value_template: >-
{{ button_pressed_at ==
as_timestamp(states('input_button.garage_button',
'last_changed')) }}
alias: If NOT interrupeted
then:
- target:
entity_id: input_select.garage_door_current_state
data:
option: Open
action: input_select.select_option
alias: Set door current state = Open
- target:
entity_id: input_select.garage_door_direction
data:
option: None
action: input_select.select_option
alias: Set door direction = None
alias: If 'Closed' or 'Closing'
- conditions:
- condition: or
conditions:
- condition: state
entity_id: input_select.garage_door_current_state
state: Open
- condition: and
conditions:
- condition: state
entity_id: input_select.garage_door_current_state
state: Half-Way
- condition: state
entity_id: input_select.garage_door_direction
state: Up
alias: If Garage door was opening but interrupted
sequence:
- alias: Set state to Half-Way
target:
entity_id: input_select.garage_door_current_state
data:
option: Half-Way
action: input_select.select_option
- alias: Set direction to DOWN
target:
entity_id: input_select.garage_door_direction
data:
option: Down
action: input_select.select_option
- alias: >-
Wait for the door to fully close or till the garage button has
been pressed again
repeat:
sequence:
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- action: input_number.decrement
metadata: {}
data: {}
target:
entity_id: input_number.garage_door
until:
- condition: or
conditions:
- condition: numeric_state
entity_id: input_number.garage_door
below: 1
- alias: Garage button has been pressed again
condition: template
value_template: " {{ button_pressed_at != as_timestamp(states('input_button.garage_button','last_changed')) }}"
enabled: true
- alias: Set State and Direction
if:
- condition: template
value_template: >-
{{ button_pressed_at ==
as_timestamp(states('input_button.garage_button',
'last_changed')) }}
alias: If NOT interrupeted
then:
- target:
entity_id: input_select.garage_door_current_state
data:
option: Closed
action: input_select.select_option
alias: Set current state
- target:
entity_id: input_select.garage_door_direction
data:
option: None
action: input_select.select_option
alias: Set direction
else:
- target:
entity_id: input_select.garage_door_direction
data:
option: None
action: input_select.select_option
alias: If 'Open' or 'Opening'
mode: single
1 Like