Skip to content

Commit

Permalink
Make garage door open and close commands state-aware and report infer…
Browse files Browse the repository at this point in the history
…red opening and closing operations
  • Loading branch information
heythisisnate committed Mar 5, 2024
1 parent 6c525e9 commit cd9f33d
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 83 deletions.
26 changes: 13 additions & 13 deletions garage-door-GDOv1-S.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ substitutions:
name: garage-door
friendly_name: Garage Door Opener
project_name: konnected.garage-door-gdov1-s
project_version: "1.0.0"
project_version: "1.1.0"
garage_door_cover_name: Garage Door
switch_name: Switch

Expand Down Expand Up @@ -107,6 +107,18 @@ packages:
# This package is required
- packages/core-esp8266.yaml

####
# GARAGE DOOR WIRED SENSOR
# Enables a wired contact sensor for reporting the open or closed state of the garage door
# via the physical INPUT terminals.
- packages/garage-door-wired-sensor.yaml

####
# GARAGE DOOR RANGE SENSOR
# Enables the optical laser range sensor included with some Konnected Garage Door opener models to detect
# the open/closed state of an overhead garage door.
- packages/vl53l0x-range-sensor.yaml

####
# GARAGE DOOR COVER
# The Garage Door Cover is the main user interface entity representing a garage door in Home Assistant.
Expand All @@ -122,18 +134,6 @@ packages:
# 3. WIRED & RANGE SENSORS - Include this line.
# - packages/garage-door-cover-wired-and-range.yaml

####
# GARAGE DOOR WIRED SENSOR
# Enables a wired contact sensor for reporting the open or closed state of the garage door
# via the physical INPUT terminals.
- packages/garage-door-wired-sensor.yaml

####
# GARAGE DOOR RANGE SENSOR
# Enables the optical laser range sensor included with some Konnected Garage Door opener models to detect
# the open/closed state of an overhead garage door.
- packages/vl53l0x-range-sensor.yaml

####
# GARAGE DOOR OPENER BUTTON
# Enables the garage door opener relay labeled DOOR on the Konnected Garage Door Opener as a button entity. When
Expand Down
26 changes: 13 additions & 13 deletions garage-door-GDOv2-S.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ substitutions:
name: garage-door
friendly_name: Garage Door Opener
project_name: konnected.garage-door-gdov2-s
project_version: "1.0.0"
project_version: "1.1.0"
garage_door_cover_name: Garage Door
switch_name: STR output

Expand Down Expand Up @@ -116,6 +116,18 @@ packages:
# This package is required and sets up core ESPHome features.
- packages/core-esp32-s3.yaml

####
# GARAGE DOOR WIRED SENSOR
# Enables a wired contact sensor for reporting the open or closed state of the garage door
# via the physical INPUT terminals.
- packages/garage-door-wired-sensor.yaml

####
# GARAGE DOOR RANGE SENSOR
# Enables the optical laser range sensor included with some Konnected Garage Door opener models to detect
# the open/closed state of an overhead garage door.
- packages/vl53l0x-range-sensor.yaml

####
# GARAGE DOOR COVER
# The Garage Door Cover is the main user interface entity representing a garage door in Home Assistant.
Expand All @@ -131,18 +143,6 @@ packages:
# 3. WIRED & RANGE SENSORS - Include this line.
# - packages/garage-door-cover-wired-and-range.yaml

####
# GARAGE DOOR WIRED SENSOR
# Enables a wired contact sensor for reporting the open or closed state of the garage door
# via the physical INPUT terminals.
- packages/garage-door-wired-sensor.yaml

####
# GARAGE DOOR RANGE SENSOR
# Enables the optical laser range sensor included with some Konnected Garage Door opener models to detect
# the open/closed state of an overhead garage door.
- packages/vl53l0x-range-sensor.yaml

####
# GARAGE DOOR OPENER BUTTON
# Enables the garage door opener relay labeled DOOR on the Konnected Garage Door Opener as a button entity. When
Expand Down
5 changes: 5 additions & 0 deletions packages/buzzer-rtttl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ button:
then:
- rtttl.play: $ominous_warning

script:
- id: error_tone
then:
- rtttl.play: err:d=16,o=4,b=100:d#,d#,d#

api:
services:
# Call the play_rtttl service to play any RTTTL song in the garage
Expand Down
38 changes: 19 additions & 19 deletions packages/garage-door-cover-range.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
cover:
- platform: template
name: $garage_door_cover_name
id: garage_door
device_class: garage
lambda: |-
if (id(garage_door_range_sensor).state) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
open_action:
- button.press: garage_door_opener_button
close_action:
- button.press: pre_close_warning
- delay: $garage_door_close_warning_duration
- button.press: garage_door_opener_button
stop_action:
- button.press: garage_door_opener_button

<<: !include garage-door-cover.yaml

binary_sensor:
- id: !extend garage_door_range_sensor
on_state:
- if:
condition:
lambda: return x;
then:
- cover.template.publish:
id: garage_door
state: OPEN
current_operation: IDLE
else:
- cover.template.publish:
id: garage_door
state: CLOSED
current_operation: IDLE
55 changes: 36 additions & 19 deletions packages/garage-door-cover-wired-and-range.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
cover:
- platform: template
name: $garage_door_cover_name
id: garage_door
device_class: garage
lambda: |-
if (id(garage_door_input).state || id(garage_door_range_sensor).state) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
open_action:
- button.press: garage_door_opener_button
close_action:
- button.press: pre_close_warning
- delay: $garage_door_close_warning_duration
- button.press: garage_door_opener_button
stop_action:
- button.press: garage_door_opener_button
<<: !include garage-door-cover.yaml

# Consider the garage door open if either the optical or range sensor reports open.
# Consider the garage closed if both wired and range sensor report closed.
binary_sensor:
- id: !extend garage_door_input
on_state:
- if:
condition:
lambda: return (x || id(garage_door_range_sensor).state);
then:
- cover.template.publish:
id: garage_door
state: OPEN
current_operation: IDLE
else:
- cover.template.publish:
id: garage_door
state: CLOSED
current_operation: IDLE

- id: !extend garage_door_range_sensor
on_state:
- if:
condition:
lambda: return (x || id(garage_door_input).state);
then:
- cover.template.publish:
id: garage_door
state: OPEN
current_operation: IDLE
else:
- cover.template.publish:
id: garage_door
state: CLOSED
current_operation: IDLE
37 changes: 18 additions & 19 deletions packages/garage-door-cover-wired.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
cover:
- platform: template
name: $garage_door_cover_name
id: garage_door
device_class: garage
lambda: |-
if (id(garage_door_input).state) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
open_action:
- button.press: garage_door_opener_button
close_action:
- button.press: pre_close_warning
- delay: $garage_door_close_warning_duration
- button.press: garage_door_opener_button
stop_action:
- button.press: garage_door_opener_button
<<: !include garage-door-cover.yaml

binary_sensor:
- id: !extend garage_door_input
on_state:
- if:
condition:
lambda: return x;
then:
- cover.template.publish:
id: garage_door
state: OPEN
current_operation: IDLE
else:
- cover.template.publish:
id: garage_door
state: CLOSED
current_operation: IDLE
69 changes: 69 additions & 0 deletions packages/garage-door-cover.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

cover:
- platform: template
name: $garage_door_cover_name
id: garage_door
device_class: garage

# Opens the garage door only if the garage door is currently closed
open_action:
- if:
condition:
lambda: return id(garage_door).position == COVER_CLOSED;
then:
- button.press: garage_door_opener_button
- cover.template.publish:
id: garage_door
current_operation: OPENING
else:
- script.execute: error_tone
- lambda: ESP_LOGW("konnected.gdov2-s","Garage door is already open. Ignoring open action.");


# Closes the garage door only if the garage door is currently open.
# Triggers the pre-close warning before closing
close_action:
- if:
condition:
lambda: return id(garage_door).position == COVER_OPEN;
then:
- button.press: pre_close_warning
- delay: $garage_door_close_warning_duration
- button.press: garage_door_opener_button
- cover.template.publish:
id: garage_door
current_operation: CLOSING
else:
- script.execute: error_tone
- lambda: ESP_LOGW("konnected.gdov2-s","Garage door is already closed. Ignoring close action.");

# Toggles the garage door open or closed
# If the action would cause the door to close, then the pre-close warning is
# triggered prior to closing
toggle_action:
- if:
condition:
lambda: return id(garage_door).position == COVER_OPEN;
then:
- button.press: pre_close_warning
- delay: $garage_door_close_warning_duration
- cover.template.publish:
id: garage_door
current_operation: CLOSING
else:
- cover.template.publish:
id: garage_door
current_operation: OPENING
- button.press: garage_door_opener_button

# Triggers the garage door button to stop only if the garage door is known to be moving
stop_action:
- if:
condition:
not:
lambda: return id(garage_door).current_operation == CoverOperation::COVER_OPERATION_IDLE;
then:
- button.press: garage_door_opener_button
- cover.template.publish:
id: garage_door
current_operation: IDLE
14 changes: 14 additions & 0 deletions packages/warning-beep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ output:
number: $warning_beep_pin
allow_other_uses: $warning_beep_shared

script:
- id: error_tone
then:
- output.turn_on: buzzer_output
- delay: 60ms
- output.turn_off: buzzer_output
- delay: 50ms
- output.turn_on: buzzer_output
- delay: 60ms
- output.turn_off: buzzer_output
- delay: 50ms
- output.turn_on: buzzer_output
- delay: 60ms
- output.turn_off: buzzer_output

light:
- id: warning_beep
Expand Down

0 comments on commit cd9f33d

Please sign in to comment.