Compare commits
2 Commits
e79c0823e3
...
1f6239ee1d
Author | SHA1 | Date |
---|---|---|
Paul Wieland | 1f6239ee1d | |
Paul Wieland | 7c8cc2e4e2 |
|
@ -87,11 +87,10 @@ binary_sensor:
|
||||||
entity_category: diagnostic
|
entity_category: diagnostic
|
||||||
filters:
|
filters:
|
||||||
- delayed_on_off: 500ms
|
- delayed_on_off: 500ms
|
||||||
# on_state:
|
on_state:
|
||||||
# then:
|
then:
|
||||||
# lambda: |-
|
lambda: |-
|
||||||
# id($id_prefix)->call_protocol(set_open_limit { static_cast<bool>(true) });
|
id($id_prefix)->set_open_limit(x);
|
||||||
|
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
id: "${id_prefix}_dry_contact_close"
|
id: "${id_prefix}_dry_contact_close"
|
||||||
pin:
|
pin:
|
||||||
|
@ -104,12 +103,10 @@ binary_sensor:
|
||||||
entity_category: diagnostic
|
entity_category: diagnostic
|
||||||
filters:
|
filters:
|
||||||
- delayed_on_off: 500ms
|
- delayed_on_off: 500ms
|
||||||
# on_press:
|
on_state:
|
||||||
# - if:
|
then:
|
||||||
# condition:
|
lambda: |-
|
||||||
# binary_sensor.is_off: ${id_prefix}_dry_contact_open
|
id($id_prefix)->set_close_limit(x);
|
||||||
# then:
|
|
||||||
# - cover.close: ${id_prefix}_garage_door
|
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
id: "${id_prefix}_dry_contact_light"
|
id: "${id_prefix}_dry_contact_light"
|
||||||
pin:
|
pin:
|
||||||
|
@ -205,7 +202,7 @@ button:
|
||||||
|
|
||||||
- platform: template
|
- platform: template
|
||||||
id: ${id_prefix}_toggle_door
|
id: ${id_prefix}_toggle_door
|
||||||
name: "Toggle door!"
|
name: "Toggle door"
|
||||||
on_press:
|
on_press:
|
||||||
then:
|
then:
|
||||||
lambda: !lambda |-
|
lambda: !lambda |-
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace ratgdo {
|
||||||
this->last_open_limit_ = 0;
|
this->last_open_limit_ = 0;
|
||||||
this->close_limit_reached_ = 0;
|
this->close_limit_reached_ = 0;
|
||||||
this->last_close_limit_ = 0;
|
this->last_close_limit_ = 0;
|
||||||
|
this->door_state_ = DoorState::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DryContact::loop()
|
void DryContact::loop()
|
||||||
|
@ -36,42 +37,43 @@ namespace ratgdo {
|
||||||
|
|
||||||
void DryContact::sync()
|
void DryContact::sync()
|
||||||
{
|
{
|
||||||
|
ESP_LOG1(TAG, "Ignoring sync action");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DryContact::set_open_limit(bool val)
|
void DryContact::set_open_limit(bool state)
|
||||||
{
|
{
|
||||||
ESP_LOGD(TAG, "Set open_limit_reached to %d", val);
|
ESP_LOGD(TAG, "Set open_limit_reached to %d", state);
|
||||||
this->last_open_limit_ = this->open_limit_reached_;
|
this->last_open_limit_ = this->open_limit_reached_;
|
||||||
this->open_limit_reached_ = val;
|
this->last_close_limit_ = false;
|
||||||
|
this->open_limit_reached_ = state;
|
||||||
this->send_door_state();
|
this->send_door_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DryContact::set_close_limit(bool val)
|
void DryContact::set_close_limit(bool state)
|
||||||
{
|
{
|
||||||
ESP_LOGD(TAG, "Set close_limit_reached to %d", val);
|
ESP_LOGD(TAG, "Set close_limit_reached to %d", state);
|
||||||
this->last_close_limit_ = this->close_limit_reached_;
|
this->last_close_limit_ = this->close_limit_reached_;
|
||||||
this->close_limit_reached_ = val;
|
this->last_open_limit_ = false;
|
||||||
|
this->close_limit_reached_ = state;
|
||||||
this->send_door_state();
|
this->send_door_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DryContact::send_door_state(){
|
void DryContact::send_door_state(){
|
||||||
DoorState door_state;
|
|
||||||
|
|
||||||
if(this->open_limit_reached_){
|
if(this->open_limit_reached_){
|
||||||
door_state = DoorState::OPEN;
|
this->door_state_ = DoorState::OPEN;
|
||||||
}else if(this->close_limit_reached_){
|
}else if(this->close_limit_reached_){
|
||||||
door_state = DoorState::CLOSED;
|
this->door_state_ = DoorState::CLOSED;
|
||||||
}else if(!this->close_limit_reached_ && !this->open_limit_reached_){
|
}else if(!this->close_limit_reached_ && !this->open_limit_reached_){
|
||||||
if(this->last_close_limit_){
|
if(this->last_close_limit_){
|
||||||
door_state = DoorState::OPENING;
|
this->door_state_ = DoorState::OPENING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->last_open_limit_){
|
if(this->last_open_limit_){
|
||||||
door_state = DoorState::CLOSING;
|
this->door_state_ = DoorState::CLOSING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ratgdo_->received(door_state);
|
this->ratgdo_->received(this->door_state_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DryContact::light_action(LightAction action)
|
void DryContact::light_action(LightAction action)
|
||||||
|
@ -88,14 +90,19 @@ namespace ratgdo {
|
||||||
|
|
||||||
void DryContact::door_action(DoorAction action)
|
void DryContact::door_action(DoorAction action)
|
||||||
{
|
{
|
||||||
if (action != DoorAction::TOGGLE) {
|
if (action == DoorAction::OPEN && this->door_state_ != DoorState::CLOSED) {
|
||||||
ESP_LOG1(TAG, "Ignoring door action: %s", DoorAction_to_string(action));
|
ESP_LOGW(TAG, "The door is not closed. Ignoring door action: %s", DoorAction_to_string(action));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (action == DoorAction::CLOSE && this->door_state_ != DoorState::OPEN) {
|
||||||
|
ESP_LOGW(TAG, "The door is not open. Ignoring door action: %s", DoorAction_to_string(action));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ESP_LOG1(TAG, "Door action: %s", DoorAction_to_string(action));
|
ESP_LOG1(TAG, "Door action: %s", DoorAction_to_string(action));
|
||||||
|
|
||||||
this->tx_pin_->digital_write(1);
|
this->tx_pin_->digital_write(1);
|
||||||
this->scheduler_->set_timeout(this->ratgdo_, "", 200, [=] {
|
this->scheduler_->set_timeout(this->ratgdo_, "", 500, [=] {
|
||||||
this->tx_pin_->digital_write(0);
|
this->tx_pin_->digital_write(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ namespace ratgdo {
|
||||||
void light_action(LightAction action);
|
void light_action(LightAction action);
|
||||||
void lock_action(LockAction action);
|
void lock_action(LockAction action);
|
||||||
void door_action(DoorAction action);
|
void door_action(DoorAction action);
|
||||||
void set_open_limit(bool val);
|
void set_open_limit(bool state);
|
||||||
void set_close_limit(bool val);
|
void set_close_limit(bool state);
|
||||||
void send_door_state();
|
void send_door_state();
|
||||||
|
|
||||||
Result call(Args args);
|
Result call(Args args);
|
||||||
|
@ -46,6 +46,7 @@ namespace ratgdo {
|
||||||
RATGDOComponent* ratgdo_;
|
RATGDOComponent* ratgdo_;
|
||||||
Scheduler* scheduler_;
|
Scheduler* scheduler_;
|
||||||
|
|
||||||
|
DoorState door_state_;
|
||||||
bool open_limit_reached_;
|
bool open_limit_reached_;
|
||||||
bool last_open_limit_;
|
bool last_open_limit_;
|
||||||
bool close_limit_reached_;
|
bool close_limit_reached_;
|
||||||
|
|
|
@ -102,6 +102,8 @@ namespace ratgdo {
|
||||||
virtual void dump_config();
|
virtual void dump_config();
|
||||||
|
|
||||||
virtual void sync();
|
virtual void sync();
|
||||||
|
virtual void set_open_limit(bool);
|
||||||
|
virtual void set_close_limit(bool);
|
||||||
|
|
||||||
virtual const Traits& traits() const;
|
virtual const Traits& traits() const;
|
||||||
|
|
||||||
|
|
|
@ -420,6 +420,16 @@ namespace ratgdo {
|
||||||
this->protocol_->sync();
|
this->protocol_->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RATGDOComponent::set_open_limit(bool state)
|
||||||
|
{
|
||||||
|
this->protocol_->set_open_limit(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RATGDOComponent::set_close_limit(bool state)
|
||||||
|
{
|
||||||
|
this->protocol_->set_close_limit(state);
|
||||||
|
}
|
||||||
|
|
||||||
void RATGDOComponent::door_open()
|
void RATGDOComponent::door_open()
|
||||||
{
|
{
|
||||||
if (*this->door_state == DoorState::OPENING) {
|
if (*this->door_state == DoorState::OPENING) {
|
||||||
|
|
|
@ -145,6 +145,8 @@ namespace ratgdo {
|
||||||
void query_status();
|
void query_status();
|
||||||
void query_openings();
|
void query_openings();
|
||||||
void sync();
|
void sync();
|
||||||
|
void set_open_limit(bool);
|
||||||
|
void set_close_limit(bool);
|
||||||
|
|
||||||
// children subscriptions
|
// children subscriptions
|
||||||
void subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f);
|
void subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f);
|
||||||
|
|
Loading…
Reference in New Issue