Added workaround to stop the door by sending toggle twice for those

garage openers that ignore the stop command while door is closing.
This commit is contained in:
Marius Muja 2023-10-08 21:36:09 -07:00
parent 2ea7ca6e3e
commit 9f8e0401b8
3 changed files with 38 additions and 4 deletions

View File

@ -58,6 +58,18 @@ switch:
output: true output: true
name: "Status obstruction" name: "Status obstruction"
entity_category: diagnostic entity_category: diagnostic
- platform: template
id: ${id_prefix}_stop_while_closing_workaround
entity_category: config
name: "Stop while closing workaround"
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
turn_on_action:
- lambda: |-
id(${id_prefix})->set_stop_while_closing_workaround(true);
turn_off_action:
- lambda: |-
id(${id_prefix})->set_stop_while_closing_workaround(false);
binary_sensor: binary_sensor:
- platform: ratgdo - platform: ratgdo

View File

@ -16,8 +16,8 @@
#include "esphome/core/log.h" #include "esphome/core/log.h"
#define ESP_LOG1 ESP_LOGV #define ESP_LOG1 ESP_LOGD
#define ESP_LOG2 ESP_LOGV #define ESP_LOG2 ESP_LOGD
namespace esphome { namespace esphome {
namespace ratgdo { namespace ratgdo {
@ -275,8 +275,8 @@ namespace ratgdo {
auto now = millis(); auto now = millis();
auto duration = this->door_move_delta > 0 ? *this->opening_duration : -*this->closing_duration; auto duration = this->door_move_delta > 0 ? *this->opening_duration : -*this->closing_duration;
auto position = this->door_start_position + (now - this->door_start_moving) / (1000 * duration); auto position = this->door_start_position + (now - this->door_start_moving) / (1000 * duration);
ESP_LOG2(TAG, "[%d] Position update: %f", now, position);
this->door_position = clamp(position, 0.0f, 1.0f); this->door_position = clamp(position, 0.0f, 1.0f);
ESP_LOG2(TAG, "[%d] Position update: %f", now, position);
} }
void RATGDOComponent::encode_packet(Command command, uint32_t data, bool increment, WirePacket& packet) void RATGDOComponent::encode_packet(Command command, uint32_t data, bool increment, WirePacket& packet)
@ -397,6 +397,7 @@ namespace ratgdo {
if (ser_byte != 0x55 && ser_byte != 0x01 && ser_byte != 0x00) { if (ser_byte != 0x55 && ser_byte != 0x01 && ser_byte != 0x00) {
ESP_LOG2(TAG, "Ignoring byte: %02X, baud: %d", ser_byte, this->sw_serial_.baudRate()); ESP_LOG2(TAG, "Ignoring byte: %02X, baud: %d", ser_byte, this->sw_serial_.baudRate());
byte_count = 0; byte_count = 0;
ESP_LOGD(TAG, "Ignoring serial byte %02X", ser_byte);
continue; continue;
} }
msg_start = ((msg_start << 8) | ser_byte) & 0xffffff; msg_start = ((msg_start << 8) | ser_byte) & 0xffffff;
@ -614,7 +615,7 @@ namespace ratgdo {
} }
} }
void RATGDOComponent::door_command(uint32_t data) void RATGDOComponent::door_command_(uint32_t data)
{ {
data |= (1 << 16); // button 1 ? data |= (1 << 16); // button 1 ?
data |= (1 << 8); // button press data |= (1 << 8); // button press
@ -653,6 +654,23 @@ namespace ratgdo {
}); });
} }
void RATGDOComponent::door_command(uint32_t data)
{
if (this->stop_while_closing_workaround && data==data::DOOR_STOP && *this->door_state==DoorState::CLOSING) {
ESP_LOGD(TAG, "Using double toggle door stop");
this->door_command_(data::DOOR_TOGGLE);
this->door_state_received.then([=](DoorState s) {
if (s==DoorState::OPENING) {
this->door_command(data::DOOR_TOGGLE);
}
});
} else {
ESP_LOGD(TAG, "Door command: %X", data);
this->door_command_(data);
}
}
void RATGDOComponent::light_on() void RATGDOComponent::light_on()
{ {
this->light_state = LightState::ON; this->light_state = LightState::ON;

View File

@ -109,6 +109,8 @@ namespace ratgdo {
float start_closing { -1 }; float start_closing { -1 };
observable<float> closing_duration { 0 }; observable<float> closing_duration { 0 };
bool stop_while_closing_workaround { false };
observable<uint16_t> openings { 0 }; // number of times the door has been opened observable<uint16_t> openings { 0 }; // number of times the door has been opened
observable<DoorState> door_state { DoorState::UNKNOWN }; observable<DoorState> door_state { DoorState::UNKNOWN };
@ -148,6 +150,7 @@ namespace ratgdo {
void set_rolling_code_counter(uint32_t code); void set_rolling_code_counter(uint32_t code);
// door // door
void door_command_(uint32_t data);
void door_command(uint32_t data); void door_command(uint32_t data);
void ensure_door_command(uint32_t data, uint32_t delay = 1500); void ensure_door_command(uint32_t data, uint32_t delay = 1500);
void toggle_door(); void toggle_door();
@ -161,6 +164,7 @@ namespace ratgdo {
void schedule_door_position_sync(float update_period = 500); void schedule_door_position_sync(float update_period = 500);
void door_position_update(); void door_position_update();
void cancel_position_sync_callbacks(); void cancel_position_sync_callbacks();
void set_stop_while_closing_workaround(bool enabled) { this->stop_while_closing_workaround = enabled; }
// light // light
void toggle_light(); void toggle_light();