Use random client_id in lieu of static remote_id (#76)
Co-authored-by: Paul Wieland <p@ul.sickdimension.com>
This commit is contained in:
parent
e248c705c5
commit
2091be8312
18
README.md
18
README.md
|
@ -5,19 +5,11 @@ This is a port of the ratgdo software for the v2.0/v2.5 board to ESPHome.
|
||||||
|
|
||||||
[Visit the github.io page to purchase boards](https://paulwieland.github.io/ratgdo/#order)
|
[Visit the github.io page to purchase boards](https://paulwieland.github.io/ratgdo/#order)
|
||||||
|
|
||||||
## Moving from stock ratgdo
|
## Installation
|
||||||
|
|
||||||
If you have not used the stock ratgdo firmware, and are starting with a fresh install of the ESPHome based firmware, [skip these steps](#fresh-install-when-the-stock-ratgdo-firmware-was-not-used-before).
|
- Flash the ESPHome based firmware using the [Web Installer](https://ratgdo.github.io/esphome-ratgdo/)
|
||||||
|
|
||||||
- Use the [`Logs & Console`](https://paulwieland.github.io/ratgdo/flash.html) to view and make note of the current rolling code
|
It is no longer necessary to save the rolling code counter when switching between firmware.
|
||||||
- Flash the new ESPHome based firmware using the [Web Installer](https://esphome-ratgdo.github.io/esphome-ratgdo/)
|
|
||||||
- Use the `number` entity in Home Assistant or the built-in ESPHome web-server to set the rolling code.
|
|
||||||
|
|
||||||
<img width="560" alt="number_entity" src="https://github.com/RATGDO/esphome-ratgdo/assets/663432/e177029e-f42f-46a8-a87a-81fa04caaa57">
|
|
||||||
|
|
||||||
## Fresh install when the stock ratgdo firmware was not used before
|
|
||||||
|
|
||||||
- Flash the new ESPHome based firmware using the [Web Installer](https://ratgdo.github.io/esphome-ratgdo/)
|
|
||||||
|
|
||||||
## First use after adding to Home Assistant
|
## First use after adding to Home Assistant
|
||||||
|
|
||||||
|
@ -25,10 +17,6 @@ The ESPHome firmware will allow you to open the door to any position after calib
|
||||||
|
|
||||||
<img width="560" alt="position_demo" src="https://github.com/RATGDO/esphome-ratgdo/assets/663432/22a9873e-67bb-4b2f-bb32-70047cfe666d">
|
<img width="560" alt="position_demo" src="https://github.com/RATGDO/esphome-ratgdo/assets/663432/22a9873e-67bb-4b2f-bb32-70047cfe666d">
|
||||||
|
|
||||||
## Updating from versions older than 2023.07.07
|
|
||||||
|
|
||||||
When updating from older versions, save the rolling counter value and restore it via the number entity after flashing the new firmware. If you forget to save the code, check the Home Assistant history.
|
|
||||||
|
|
||||||
## ESPHome config
|
## ESPHome config
|
||||||
|
|
||||||
- [ESPHome config for v2.0 board with ESP8266 D1 Mini lite](https://github.com/RATGDO/esphome-ratgdo/blob/main/static/v2board_esp8266_d1_mini_lite.yaml)
|
- [ESPHome config for v2.0 board with ESP8266 D1 Mini lite](https://github.com/RATGDO/esphome-ratgdo/blob/main/static/v2board_esp8266_d1_mini_lite.yaml)
|
||||||
|
|
|
@ -14,7 +14,6 @@ ratgdo:
|
||||||
input_gdo_pin: ${uart_rx_pin}
|
input_gdo_pin: ${uart_rx_pin}
|
||||||
output_gdo_pin: ${uart_tx_pin}
|
output_gdo_pin: ${uart_tx_pin}
|
||||||
input_obst_pin: ${input_obst_pin}
|
input_obst_pin: ${input_obst_pin}
|
||||||
remote_id: 0x539
|
|
||||||
on_sync_failed:
|
on_sync_failed:
|
||||||
then:
|
then:
|
||||||
- homeassistant.service:
|
- homeassistant.service:
|
||||||
|
@ -161,6 +160,14 @@ number:
|
||||||
name: "Closing duration"
|
name: "Closing duration"
|
||||||
unit_of_measurement: "s"
|
unit_of_measurement: "s"
|
||||||
|
|
||||||
|
- platform: ratgdo
|
||||||
|
id: ${id_prefix}_client_id
|
||||||
|
type: client_id
|
||||||
|
entity_category: config
|
||||||
|
ratgdo_id: ${id_prefix}
|
||||||
|
name: "Client ID"
|
||||||
|
mode: box
|
||||||
|
|
||||||
cover:
|
cover:
|
||||||
- platform: ratgdo
|
- platform: ratgdo
|
||||||
id: ${id_prefix}_garage_door
|
id: ${id_prefix}_garage_door
|
||||||
|
|
|
@ -24,9 +24,6 @@ DEFAULT_INPUT_GDO = (
|
||||||
CONF_INPUT_OBST = "input_obst_pin"
|
CONF_INPUT_OBST = "input_obst_pin"
|
||||||
DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal
|
DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal
|
||||||
|
|
||||||
CONF_REMOTE_ID = "remote_id"
|
|
||||||
DEFAULT_REMOTE_ID = 0x539
|
|
||||||
|
|
||||||
CONF_RATGDO_ID = "ratgdo_id"
|
CONF_RATGDO_ID = "ratgdo_id"
|
||||||
|
|
||||||
CONF_ON_SYNC_FAILED = "on_sync_failed"
|
CONF_ON_SYNC_FAILED = "on_sync_failed"
|
||||||
|
@ -44,9 +41,6 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
cv.Optional(
|
cv.Optional(
|
||||||
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
|
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
|
||||||
): pins.gpio_input_pin_schema,
|
): pins.gpio_input_pin_schema,
|
||||||
cv.Optional(
|
|
||||||
CONF_REMOTE_ID, default=DEFAULT_REMOTE_ID
|
|
||||||
): cv.uint64_t,
|
|
||||||
cv.Optional(CONF_ON_SYNC_FAILED): automation.validate_automation(
|
cv.Optional(CONF_ON_SYNC_FAILED): automation.validate_automation(
|
||||||
{
|
{
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SyncFailed),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SyncFailed),
|
||||||
|
@ -76,7 +70,6 @@ async def to_code(config):
|
||||||
cg.add(var.set_input_gdo_pin(pin))
|
cg.add(var.set_input_gdo_pin(pin))
|
||||||
pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST])
|
pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST])
|
||||||
cg.add(var.set_input_obst_pin(pin))
|
cg.add(var.set_input_obst_pin(pin))
|
||||||
cg.add(var.set_remote_id(config[CONF_REMOTE_ID]))
|
|
||||||
|
|
||||||
for conf in config.get(CONF_ON_SYNC_FAILED, []):
|
for conf in config.get(CONF_ON_SYNC_FAILED, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
|
|
@ -12,6 +12,7 @@ NumberType = ratgdo_ns.enum("NumberType")
|
||||||
|
|
||||||
CONF_TYPE = "type"
|
CONF_TYPE = "type"
|
||||||
TYPES = {
|
TYPES = {
|
||||||
|
"client_id": NumberType.RATGDO_CLIENT_ID,
|
||||||
"rolling_code_counter": NumberType.RATGDO_ROLLING_CODE_COUNTER,
|
"rolling_code_counter": NumberType.RATGDO_ROLLING_CODE_COUNTER,
|
||||||
"opening_duration": NumberType.RATGDO_OPENING_DURATION,
|
"opening_duration": NumberType.RATGDO_OPENING_DURATION,
|
||||||
"closing_duration": NumberType.RATGDO_CLOSING_DURATION,
|
"closing_duration": NumberType.RATGDO_CLOSING_DURATION,
|
||||||
|
|
|
@ -10,7 +10,9 @@ namespace ratgdo {
|
||||||
void RATGDONumber::dump_config()
|
void RATGDONumber::dump_config()
|
||||||
{
|
{
|
||||||
LOG_NUMBER("", "RATGDO Number", this);
|
LOG_NUMBER("", "RATGDO Number", this);
|
||||||
if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
|
if (this->number_type_ == RATGDO_CLIENT_ID) {
|
||||||
|
ESP_LOGCONFIG(TAG, " Type: Client ID");
|
||||||
|
} else if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
|
||||||
ESP_LOGCONFIG(TAG, " Type: Rolling Code Counter");
|
ESP_LOGCONFIG(TAG, " Type: Rolling Code Counter");
|
||||||
} else if (this->number_type_ == RATGDO_OPENING_DURATION) {
|
} else if (this->number_type_ == RATGDO_OPENING_DURATION) {
|
||||||
ESP_LOGCONFIG(TAG, " Type: Opening Duration");
|
ESP_LOGCONFIG(TAG, " Type: Opening Duration");
|
||||||
|
@ -24,7 +26,11 @@ namespace ratgdo {
|
||||||
float value;
|
float value;
|
||||||
this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash());
|
this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash());
|
||||||
if (!this->pref_.load(&value)) {
|
if (!this->pref_.load(&value)) {
|
||||||
value = 0;
|
if (this->number_type_ == RATGDO_CLIENT_ID) {
|
||||||
|
value = random(0x1, 0xFFFF);
|
||||||
|
} else {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this->publish_state(value);
|
this->publish_state(value);
|
||||||
this->control(value);
|
this->control(value);
|
||||||
|
@ -51,9 +57,11 @@ namespace ratgdo {
|
||||||
this->traits.set_step(0.1);
|
this->traits.set_step(0.1);
|
||||||
this->traits.set_min_value(0.0);
|
this->traits.set_min_value(0.0);
|
||||||
this->traits.set_max_value(180.0);
|
this->traits.set_max_value(180.0);
|
||||||
}
|
} else if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
|
||||||
if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
|
|
||||||
this->traits.set_max_value(0xfffffff);
|
this->traits.set_max_value(0xfffffff);
|
||||||
|
} else if (this->number_type_ == RATGDO_CLIENT_ID) {
|
||||||
|
// not sure how large remote_id can be, assuming not more than 24 bits
|
||||||
|
this->traits.set_max_value(0xffffff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +79,8 @@ namespace ratgdo {
|
||||||
this->parent_->set_opening_duration(value);
|
this->parent_->set_opening_duration(value);
|
||||||
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
|
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
|
||||||
this->parent_->set_closing_duration(value);
|
this->parent_->set_closing_duration(value);
|
||||||
|
} else if (this->number_type_ == RATGDO_CLIENT_ID) {
|
||||||
|
this->parent_->set_client_id(value);
|
||||||
}
|
}
|
||||||
this->pref_.save(&value);
|
this->pref_.save(&value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace esphome {
|
||||||
namespace ratgdo {
|
namespace ratgdo {
|
||||||
|
|
||||||
enum NumberType {
|
enum NumberType {
|
||||||
|
RATGDO_CLIENT_ID,
|
||||||
RATGDO_ROLLING_CODE_COUNTER,
|
RATGDO_ROLLING_CODE_COUNTER,
|
||||||
RATGDO_OPENING_DURATION,
|
RATGDO_OPENING_DURATION,
|
||||||
RATGDO_CLOSING_DURATION,
|
RATGDO_CLOSING_DURATION,
|
||||||
|
|
|
@ -87,7 +87,7 @@ namespace ratgdo {
|
||||||
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
|
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
|
||||||
}
|
}
|
||||||
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", *this->rolling_code_counter);
|
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", *this->rolling_code_counter);
|
||||||
ESP_LOGCONFIG(TAG, " Remote ID: %d", this->remote_id_);
|
ESP_LOGCONFIG(TAG, " Client ID: %d", this->client_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t RATGDOComponent::decode_packet(const WirePacket& packet)
|
uint16_t RATGDOComponent::decode_packet(const WirePacket& packet)
|
||||||
|
@ -101,7 +101,7 @@ namespace ratgdo {
|
||||||
uint16_t cmd = ((fixed >> 24) & 0xf00) | (data & 0xff);
|
uint16_t cmd = ((fixed >> 24) & 0xf00) | (data & 0xff);
|
||||||
data &= ~0xf000; // clear parity nibble
|
data &= ~0xf000; // clear parity nibble
|
||||||
|
|
||||||
if ((fixed & 0xfffffff) == this->remote_id_) { // my commands
|
if ((fixed & 0xfffffff) == this->client_id_) { // my commands
|
||||||
ESP_LOG1(TAG, "[%ld] received mine: rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), rolling, fixed, data);
|
ESP_LOG1(TAG, "[%ld] received mine: rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), rolling, fixed, data);
|
||||||
return static_cast<uint16_t>(Command::UNKNOWN);
|
return static_cast<uint16_t>(Command::UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
|
@ -279,7 +279,7 @@ namespace ratgdo {
|
||||||
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)
|
||||||
{
|
{
|
||||||
auto cmd = static_cast<uint64_t>(command);
|
auto cmd = static_cast<uint64_t>(command);
|
||||||
uint64_t fixed = ((cmd & ~0xff) << 24) | this->remote_id_;
|
uint64_t fixed = ((cmd & ~0xff) << 24) | this->client_id_;
|
||||||
uint32_t send_data = (data << 8) | (cmd & 0xff);
|
uint32_t send_data = (data << 8) | (cmd & 0xff);
|
||||||
|
|
||||||
ESP_LOG2(TAG, "[%ld] Encode for transmit rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), *this->rolling_code_counter, fixed, send_data);
|
ESP_LOG2(TAG, "[%ld] Encode for transmit rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), *this->rolling_code_counter, fixed, send_data);
|
||||||
|
|
|
@ -133,8 +133,7 @@ namespace ratgdo {
|
||||||
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; }
|
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; }
|
||||||
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }
|
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }
|
||||||
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }
|
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }
|
||||||
void set_remote_id(uint64_t remote_id) { this->remote_id_ = remote_id & 0xffffff; } // not sure how large remote_id can be, assuming not more than 24 bits
|
void set_client_id(uint64_t client_id) { this->client_id_ = client_id & 0xffffff; } // not sure how large client_id can be, assuming not more than 24 bits
|
||||||
uint64_t get_remote_id() { return this->remote_id_; }
|
|
||||||
|
|
||||||
void gdo_state_loop();
|
void gdo_state_loop();
|
||||||
uint16_t decode_packet(const WirePacket& packet);
|
uint16_t decode_packet(const WirePacket& packet);
|
||||||
|
@ -206,7 +205,7 @@ namespace ratgdo {
|
||||||
InternalGPIOPin* output_gdo_pin_;
|
InternalGPIOPin* output_gdo_pin_;
|
||||||
InternalGPIOPin* input_gdo_pin_;
|
InternalGPIOPin* input_gdo_pin_;
|
||||||
InternalGPIOPin* input_obst_pin_;
|
InternalGPIOPin* input_obst_pin_;
|
||||||
uint64_t remote_id_;
|
uint64_t client_id_ { 0x539 };
|
||||||
|
|
||||||
}; // RATGDOComponent
|
}; // RATGDOComponent
|
||||||
|
|
||||||
|
|
|
@ -155,9 +155,6 @@
|
||||||
Pick your board to flash your ratgdo board with ESPhome for <a href="https://github.com/PaulWieland/ratgdo#ratgdo">ratgdo</a>.
|
Pick your board to flash your ratgdo board with ESPhome for <a href="https://github.com/PaulWieland/ratgdo#ratgdo">ratgdo</a>.
|
||||||
No programming or other software required.
|
No programming or other software required.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
|
||||||
<b>Be sure to save the value of the rolling code counter and set it again or the board will not be able to control the garage door opener. If you forget to do this, you may be able to restore control by pressing the learn button, or factory resetting the garage door opener by pressing and holding the learn button 3 times for 10 seconds.</b>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="radios">
|
<div class="radios">
|
||||||
<label>
|
<label>
|
||||||
|
@ -198,11 +195,6 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>Updating from versions older than 2023.07.07</h3>
|
|
||||||
<p>
|
|
||||||
When updating from older versions, save the rolling counter value and restore it via the number entity after flashing the new firmware. If you forget to save the code, check the Home Assistant history.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h3>Advanced Users</h3>
|
<h3>Advanced Users</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
|
|
Loading…
Reference in New Issue