Skip to content

Commit

Permalink
Refactor GDO distance margin of error into a global variable
Browse files Browse the repository at this point in the history
heythisisnate committed Nov 7, 2023
1 parent f052a45 commit 127bcc9
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/garage-door-esp32-base.yaml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ substitutions:
name: garage-door
friendly_name: Garage Door Opener
project_name: konnected.garage-door-esp32
project_version: "0.4.1"
project_version: "0.4.2"
garage_door_cover_name: Garage Door
switch_name: Switch

@@ -24,7 +24,7 @@ substitutions:
####
# OPEN GARAGE DOOR DISTANCE MARGIN OF ERROR
# The margin of error (+/-) in meters from the value above to consider the garage door in the open position.
open_garage_door_distance_margin_of_error: "0.1"
open_garage_door_distance_margin_of_error: "0.06"

####
# GARAGE DOOR CLOSE WARNING DURATION
2 changes: 1 addition & 1 deletion packages/garage-door-esp8266-base.yaml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ substitutions:
name: garage-door
friendly_name: Garage Door Opener
project_name: konnected.garage-door-esp8266
project_version: "0.4.1"
project_version: "0.4.2"
garage_door_cover_name: Garage Door
switch_name: Switch

10 changes: 8 additions & 2 deletions packages/vl53l0x-range-sensor.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
globals:
- id: gdo_err_margin
type: float
restore_value: true
initial_value: $open_garage_door_distance_margin_of_error

i2c:
sda: $sda
scl: $scl
@@ -40,9 +46,9 @@ binary_sensor:
internal: true
lambda: |-
float calibrated_distance = id(open_garage_door_distance_from_ceiling).state;
if (std::isnan(id(range_sensor).state) || id(range_sensor).state > calibrated_distance + $open_garage_door_distance_margin_of_error) {
if (std::isnan(id(range_sensor).state) || id(range_sensor).state > calibrated_distance + id(gdo_err_margin)) {
return false;
} else if (id(range_sensor).state > calibrated_distance - $open_garage_door_distance_margin_of_error){
} else if (id(range_sensor).state > calibrated_distance - id(gdo_err_margin)){
return true;
} else {
return {};

0 comments on commit 127bcc9

Please sign in to comment.