Skip to content

Commit 7bcd6bd

Browse files
Add VL53L1X Tof Sensor Feature
1 parent 35931b1 commit 7bcd6bd

18 files changed

+647
-246
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Secplus GDO is an ESPHome component for controlling Security+ and Security+ 2.0
44
made by Chamberlain Group, including garage door openers sold since 1997 under the Chamberlain,
55
LiftMaster, Craftsman and Merlin brands.
66

7-
## Adapted from [RATGDO](https://github.com/ratgdo) and [Secplus GDO](https://github.com/konnected-io)
7+
## Adapted from [RATGDO](https://github.com/ratgdo) and [Secplus GDO](https://github.com/konnected-io)
88

99

1010

components/secplus_gdo/__init__.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
CONF_INPUT_OBST = "input_obst_pin"
3939
CONF_RF_OUTPUT_PIN = "rf_tx_pin"
4040
CONF_RF_INPUT_PIN = "rf_rx_pin"
41+
CONF_TOF_SDA_PIN = "tof_sda_pin"
42+
CONF_TOF_SCL_PIN = "tof_scl_pin"
4143
CONF_SECPLUS_GDO_ID = "secplus_gdo_id"
4244

4345
CONFIG_SCHEMA = cv.Schema(
@@ -47,6 +49,8 @@
4749
cv.Required(CONF_INPUT_GDO): pins.gpio_input_pin_schema,
4850
cv.Optional(CONF_RF_OUTPUT_PIN): pins.gpio_output_pin_schema,
4951
cv.Optional(CONF_RF_INPUT_PIN): pins.gpio_input_pin_schema,
52+
cv.Optional(CONF_TOF_SDA_PIN): pins.gpio_input_pin_schema,
53+
cv.Optional(CONF_TOF_SCL_PIN): pins.gpio_input_pin_schema,
5054
cv.Optional(CONF_INPUT_OBST): cv.Any(cv.none, pins.gpio_input_pin_schema),
5155
}
5256
).extend(cv.COMPONENT_SCHEMA)
@@ -66,19 +70,23 @@ async def to_code(config):
6670
cg.add_define("GDO_RF_TX_PIN", config[CONF_RF_OUTPUT_PIN]["number"])
6771
if CONF_RF_INPUT_PIN in config and config[CONF_RF_INPUT_PIN]:
6872
cg.add_define("GDO_RF_RX_PIN", config[CONF_RF_INPUT_PIN]["number"])
73+
if CONF_TOF_SDA_PIN in config and config[CONF_TOF_SDA_PIN]:
74+
cg.add_define("GDO_TOF_SDA_PIN", config[CONF_TOF_SDA_PIN]["number"])
75+
cg.add_build_flag("-DTOF_SENSOR")
76+
if CONF_TOF_SCL_PIN in config and config[CONF_TOF_SCL_PIN]:
77+
cg.add_define("GDO_TOF_SCL_PIN", config[CONF_TOF_SCL_PIN]["number"])
6978
if CONF_INPUT_OBST in config and config[CONF_INPUT_OBST]:
7079
cg.add_define("GDO_OBST_INPUT_PIN", config[CONF_INPUT_OBST]["number"])
7180
cg.add_define("GDO_OBST_FROM_STATE", False)
7281
else:
7382
cg.add_define("GDO_OBST_FROM_STATE", True)
7483
cg.add_library(
7584
name="VL53L1",
76-
repository="https://github.com/gelidusresearch/VL53L1.git",
77-
version=None,
85+
repository="https://github.com/gelidusresearch/VL53L1_ESPIDF.git",
86+
version="v1.0.0",
7887
)
7988
cg.add_library(
8089
name="GDOLIB",
81-
repository="https://github.com/gelidusresearch/gdolib.git",
82-
version=None,
83-
)
84-
cg.add_define("USE_DISTANCE")
90+
repository="https://github.com/gelidusresearch/gdolib.git#gdolib.tof",
91+
version="v1.1.5",
92+
)

components/secplus_gdo/binary_sensor/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from esphome.const import CONF_ID
2424

2525
from .. import SECPLUS_GDO_CONFIG_SCHEMA, secplus_gdo_ns, CONF_SECPLUS_GDO_ID
26+
from .. import CONF_TOF_SDA_PIN
2627

2728
DEPENDENCIES = ["secplus_gdo"]
2829

@@ -37,6 +38,9 @@
3738
"motor": "register_motor",
3839
"button": "register_button",
3940
"sync": "register_sync",
41+
"vehicle_parked": "register_vehicle_parked",
42+
"vehicle_arriving": "register_vehicle_arriving",
43+
"vehicle_leaving": "register_vehicle_leaving",
4044
}
4145

4246

components/secplus_gdo/cover/gdo_door.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void GDODoor::do_action_after_warning(const cover::CoverCall &call) {
8181
}
8282

8383

84-
this->set_timeout("pre_close", this->pre_close_duration_, [=]() {
84+
this->set_timeout("pre_close", this->pre_close_duration_, [this, call]() {
8585
this->pre_close_active_ = false;
8686
if (this->pre_close_end_trigger) {
8787
this->pre_close_end_trigger->trigger();

components/secplus_gdo/cover/gdo_door.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "automation.h"
2121
#include "esphome/components/cover/cover.h"
2222
#include "esphome/core/component.h"
23-
#include "gdo.h"
23+
#include "include/gdo.h"
2424

2525
namespace esphome {
2626
namespace secplus_gdo {

components/secplus_gdo/light/gdo_light.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "esphome/components/light/light_output.h"
2222
#include "esphome/core/component.h"
23-
#include "gdo.h"
23+
#include "include/gdo.h"
2424

2525

2626
namespace esphome {

components/secplus_gdo/lock/gdo_lock.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "esphome/components/lock/lock.h"
2121
#include "esphome/core/component.h"
22-
#include "gdo.h"
22+
#include "include/gdo.h"
2323

2424
namespace esphome {
2525
namespace secplus_gdo {

components/secplus_gdo/number/__init__.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
from esphome.const import CONF_ID
2424

2525
from .. import SECPLUS_GDO_CONFIG_SCHEMA, secplus_gdo_ns, CONF_SECPLUS_GDO_ID
26+
from .. import CONF_TOF_SDA_PIN
2627

2728
DEPENDENCIES = ["secplus_gdo"]
2829

2930
GDONumber = secplus_gdo_ns.class_("GDONumber", number.Number, cg.Component)
30-
3131
CONF_TYPE = "type"
3232
TYPES = {
3333
"open_duration": "register_open_duration",
@@ -36,8 +36,7 @@
3636
"rolling_code": "register_rolling_code",
3737
"min_command_interval": "register_min_command_interval",
3838
"time_to_close": "register_time_to_close",
39-
"target_distance": "register_target_distance",
40-
39+
"vehicle_parked_threshold": "register_vehicle_parked_threshold",
4140
}
4241

4342
CONFIG_SCHEMA = (
@@ -47,31 +46,39 @@
4746
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
4847
cv.Optional('min_command_interval', default=50): cv.uint32_t,
4948
cv.Optional('time_to_close', default=300): cv.uint16_t,
50-
cv.Optional('target_distance', default=1000): cv.uint16_t,
49+
cv.Optional('vehicle_parked_threshold', default=100): cv.uint16_t,
5150
}
5251
)
5352
.extend(SECPLUS_GDO_CONFIG_SCHEMA)
5453
)
5554

5655

56+
57+
5758
async def to_code(config):
5859
var = cg.new_Pvariable(config[CONF_ID])
59-
if "duration" in str(config[CONF_TYPE]):
60+
parent = await cg.get_variable(config[CONF_SECPLUS_GDO_ID])
61+
if parent.get(CONF_TOF_SDA_PIN) is None:
62+
print("TOF sensor")
63+
if config[CONF_TYPE] != "vehicle_parked_threshold":
64+
raise cv.Invalid("TOF sensor is only valid with vehicle_parked_threshold")
65+
if config[CONF_TYPE] == "vehicle_parked_threshold":
66+
await number.register_number(var, config, min_value=10, max_value=400, step=10)
67+
elif config[CONF_TYPE] == "duration":
6068
await number.register_number(var, config, min_value=0x0, max_value=0xffff, step=1)
61-
elif "client_id" in str(config[CONF_TYPE]):
69+
elif config[CONF_TYPE] == "client_id":
6270
await number.register_number(var, config, min_value=0x666, max_value=0x7ff666, step=1)
63-
elif "min_command_interval" in str(config[CONF_TYPE]):
71+
elif config[CONF_TYPE] == "min_command_interval":
6472
await number.register_number(var, config, min_value=50, max_value=1000, step=50)
65-
elif "time_to_close" in str(config[CONF_TYPE]):
73+
elif config[CONF_TYPE] == "time_to_close":
6674
await number.register_number(var, config, min_value=0, max_value=65535, step=60)
67-
elif "target_distance" in str(config[CONF_TYPE]):
68-
await number.register_number(var, config, min_value=1000, max_value=40000, step=100)
6975
else:
7076
await number.register_number(var, config, min_value=0x0, max_value=0xffffffff, step=1)
77+
7178
await cg.register_component(var, config)
7279
parent = await cg.get_variable(config[CONF_SECPLUS_GDO_ID])
7380
fcall = str(parent) + "->" + str(TYPES[config[CONF_TYPE]])
7481
text = fcall + "(" + str(var) + ")"
7582
cg.add((cg.RawExpression(text)))
7683
text = "gdo_set_" + str(config[CONF_TYPE])
77-
cg.add(var.set_control_function(cg.RawExpression(text)))
84+
cg.add(var.set_control_function(cg.RawExpression(text)))

components/secplus_gdo/number/gdo_number.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@
1717

1818
#pragma once
1919

20+
#include "esphome/components/number/number.h"
2021
#include "esphome/core/component.h"
2122
#include "esphome/core/preferences.h"
22-
#include "esphome/components/number/number.h"
23+
2324

2425
namespace esphome {
2526
namespace secplus_gdo {
2627

2728
class GDONumber : public number::Number, public Component {
28-
public:
29+
public:
2930
void dump_config() override {}
31+
3032
void setup() override {
3133
float value;
32-
this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash());
34+
this->pref_ =
35+
global_preferences->make_preference<float>(this->get_object_id_hash());
3336
if (!this->pref_.load(&value)) {
3437
value = 0;
3538
}
@@ -58,11 +61,11 @@ class GDONumber : public number::Number, public Component {
5861
}
5962
}
6063

61-
void set_control_function(std::function<int(float)> f) { f_control = f; }
64+
void set_control_function(std::function<void(float)> f) { f_control = f; }
6265

6366
protected:
6467
ESPPreferenceObject pref_;
65-
std::function<int(float)> f_control{nullptr};
68+
std::function<void(float)> f_control{nullptr};
6669
};
67-
} // namespace secplus_gdo
68-
} // namespace esphome
70+
} // namespace secplus_gdo
71+
} // namespace esphome

0 commit comments

Comments
 (0)