Skip to content

Commit

Permalink
ratgdo32disco (#337)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
  • Loading branch information
3 people authored Feb 3, 2025
1 parent f8ee5e8 commit 8df1cbe
Show file tree
Hide file tree
Showing 44 changed files with 1,229 additions and 51 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
branches:
- main
- ratgdo32
pull_request:
schedule:
- cron: '0 4 * * 1'
Expand Down Expand Up @@ -55,6 +55,24 @@ jobs:
- file: v25iboard_drycontact.yaml
name: V2.5i Board Dry Contact
manifest_filename: v25iboard_drycontact-manifest.json
- file: v32board.yaml
name: V32 Board Security+ 2.0
manifest_filename: v32board-manifest.json
- file: v32board_secplusv1.yaml
name: V32 Board Security+ 1.0
manifest_filename: v32board_secplusv1-manifest.json
- file: v32board_drycontact.yaml
name: V32 Board Board Dry Contact
manifest_filename: v32board_drycontact-manifest.json
- file: v32disco.yaml
name: V32 Disco Board Security+ 2.0
manifest_filename: v32disco-manifest.json
- file: v32disco_secplusv1.yaml
name: V32 Disco Board Security+ 1.0
manifest_filename: v32disco_secplusv1-manifest.json
- file: v32disco_drycontact.yaml
name: V32 Disco Board Dry Contact
manifest_filename: v32disco_drycontact-manifest.json
fail-fast: false
steps:
- name: Checkout source code
Expand All @@ -79,7 +97,7 @@ jobs:


consolidate:
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/ratgdo32'
name: Consolidate firmwares
runs-on: ubuntu-latest
needs: build
Expand All @@ -101,7 +119,7 @@ jobs:
path: output

deploy:
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/ratgdo32'
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
needs: consolidate
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

# ratgdo for ESPHome

This is a port of the ratgdo software for the v2.0/v2.5 board to ESPHome.

[Visit the the store to purchase boards](https://ratcloud.llc)
[Visit the ratcloud.llc to purchase boards](https://ratcloud.llc)

## Installation

- Flash the ESPHome based firmware using the [Web Installer](https://ratgdo.github.io/esphome-ratgdo/)

It is no longer necessary to save the rolling code counter when switching between firmware.

## First use after adding to Home Assistant

The ESPHome firmware will allow you to open the door to any position after calibration. To calibrate the door, open and close it once without stopping.
Expand Down
5 changes: 4 additions & 1 deletion base.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---

external_components:
- source:
type: git
url: https://github.com/ratgdo/esphome-ratgdo
ref: ratgdo32
refresh: 1s
# - source:
# type: local
# path: components

safe_mode:

Expand Down
7 changes: 5 additions & 2 deletions base_drycontact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

external_components:
- source:
# type: local
# path: components
type: git
url: https://github.com/ratgdo/esphome-ratgdo
ref: ratgdo32
refresh: 1s
# - source:
# type: local
# path: components

safe_mode:

Expand All @@ -20,6 +22,7 @@ text_sensor:
ratgdo:
id: ${id_prefix}
output_gdo_pin: ${uart_tx_pin}
input_gdo_pin: ${uart_rx_pin}
input_obst_pin: ${input_obst_pin}
dry_contact_open_sensor: ${id_prefix}_dry_contact_open
dry_contact_close_sensor: ${id_prefix}_dry_contact_close
Expand Down
4 changes: 4 additions & 0 deletions base_secplusv1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ external_components:
- source:
type: git
url: https://github.com/ratgdo/esphome-ratgdo
ref: ratgdo32
refresh: 1s
# - source:
# type: local
# path: components

safe_mode:

Expand Down
3 changes: 3 additions & 0 deletions components/ratgdo/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"obstruction": SensorType.RATGDO_SENSOR_OBSTRUCTION,
"motor": SensorType.RATGDO_SENSOR_MOTOR,
"button": SensorType.RATGDO_SENSOR_BUTTON,
"vehicle_detected": SensorType.RATGDO_SENSOR_VEHICLE_DETECTED,
"vehicle_arriving": SensorType.RATGDO_SENSOR_VEHICLE_ARRIVING,
"vehicle_leaving": SensorType.RATGDO_SENSOR_VEHICLE_LEAVING,
}


Expand Down
22 changes: 22 additions & 0 deletions components/ratgdo/binary_sensor/ratgdo_binary_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ namespace ratgdo {
this->parent_->subscribe_button_state([=](ButtonState state) {
this->publish_state(state == ButtonState::PRESSED);
});
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_DETECTED) {
this->publish_initial_state(false);
this->parent_->subscribe_vehicle_detected_state([=](VehicleDetectedState state) {
this->publish_state(state == VehicleDetectedState::YES);
this->parent_->presence_change(state == VehicleDetectedState::YES);
});
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING) {
this->publish_initial_state(false);
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
this->publish_state(state == VehicleArrivingState::YES);
});
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_LEAVING) {
this->publish_initial_state(false);
this->parent_->subscribe_vehicle_leaving_state([=](VehicleLeavingState state) {
this->publish_state(state == VehicleLeavingState::YES);
});
}
}

Expand All @@ -42,6 +58,12 @@ namespace ratgdo {
ESP_LOGCONFIG(TAG, " Type: Motor");
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_BUTTON) {
ESP_LOGCONFIG(TAG, " Type: Button");
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_DETECTED) {
ESP_LOGCONFIG(TAG, " Type: VehicleDetected");
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_ARRIVING) {
ESP_LOGCONFIG(TAG, " Type: VehicleArriving");
} else if (this->binary_sensor_type_ == SensorType::RATGDO_SENSOR_VEHICLE_LEAVING) {
ESP_LOGCONFIG(TAG, " Type: VehicleLeaving");
}
}

Expand Down
5 changes: 4 additions & 1 deletion components/ratgdo/binary_sensor/ratgdo_binary_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace ratgdo {
RATGDO_SENSOR_MOTION,
RATGDO_SENSOR_OBSTRUCTION,
RATGDO_SENSOR_MOTOR,
RATGDO_SENSOR_BUTTON
RATGDO_SENSOR_BUTTON,
RATGDO_SENSOR_VEHICLE_DETECTED,
RATGDO_SENSOR_VEHICLE_ARRIVING,
RATGDO_SENSOR_VEHICLE_LEAVING,
};

class RATGDOBinarySensor : public binary_sensor::BinarySensor, public RATGDOClient, public Component {
Expand Down
2 changes: 2 additions & 0 deletions components/ratgdo/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"rolling_code_counter": NumberType.RATGDO_ROLLING_CODE_COUNTER,
"opening_duration": NumberType.RATGDO_OPENING_DURATION,
"closing_duration": NumberType.RATGDO_CLOSING_DURATION,
"closing_delay": NumberType.RATGDO_CLOSING_DELAY,
"target_distance_measurement": NumberType.RATGDO_TARGET_DISTANCE_MEASUREMENT,
}


Expand Down
24 changes: 24 additions & 0 deletions components/ratgdo/number/ratgdo_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace ratgdo {
ESP_LOGCONFIG(TAG, " Type: Opening Duration");
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
ESP_LOGCONFIG(TAG, " Type: Closing Duration");
} else if (this->number_type_ == RATGDO_CLOSING_DELAY) {
ESP_LOGCONFIG(TAG, " Type: Closing Delay");
} else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) {
ESP_LOGCONFIG(TAG, " Type: Target Distance Measurement");
}
}

Expand Down Expand Up @@ -66,6 +70,14 @@ namespace ratgdo {
this->parent_->subscribe_closing_duration([=](float value) {
this->update_state(value);
});
} else if (this->number_type_ == RATGDO_CLOSING_DELAY) {
this->parent_->subscribe_closing_delay([=](uint32_t value) {
this->update_state(value);
});
} else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) {
// this->parent_->subscribe_target_distance_measurement([=](float value) {
// this->update_state(value);
// });
}
}

Expand All @@ -76,12 +88,20 @@ namespace ratgdo {
this->traits.set_step(0.1);
this->traits.set_min_value(0.0);
this->traits.set_max_value(180.0);
} else if (this->number_type_ == RATGDO_CLOSING_DELAY) {
this->traits.set_step(1);
this->traits.set_min_value(0.0);
this->traits.set_max_value(60.0);
} else if (this->number_type_ == RATGDO_ROLLING_CODE_COUNTER) {
this->traits.set_max_value(0xfffffff);
} else if (this->number_type_ == RATGDO_CLIENT_ID) {
this->traits.set_step(0x1000);
this->traits.set_min_value(0x539);
this->traits.set_max_value(0x7ff539);
} else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) {
this->traits.set_step(1);
this->traits.set_min_value(5);
this->traits.set_max_value(3500);
}
}

Expand All @@ -102,9 +122,13 @@ namespace ratgdo {
this->parent_->set_opening_duration(value);
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
this->parent_->set_closing_duration(value);
} else if (this->number_type_ == RATGDO_CLOSING_DELAY) {
this->parent_->set_closing_delay(value);
} else if (this->number_type_ == RATGDO_CLIENT_ID) {
value = normalize_client_id(value);
this->parent_->call_protocol(SetClientID { static_cast<uint32_t>(value) });
} else if (this->number_type_ == RATGDO_TARGET_DISTANCE_MEASUREMENT) {
this->parent_->set_target_distance_measurement(value);
}
this->update_state(value);
}
Expand Down
2 changes: 2 additions & 0 deletions components/ratgdo/number/ratgdo_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace ratgdo {
RATGDO_ROLLING_CODE_COUNTER,
RATGDO_OPENING_DURATION,
RATGDO_CLOSING_DURATION,
RATGDO_CLOSING_DELAY,
RATGDO_TARGET_DISTANCE_MEASUREMENT,
};

class RATGDONumber : public number::Number, public RATGDOClient, public Component {
Expand Down
36 changes: 36 additions & 0 deletions components/ratgdo/output/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import rtttl
from esphome.const import CONF_ID

CONF_RTTTL = "rtttl"
CONF_SONG = "song"


from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child

DEPENDENCIES = ["esp32", "ratgdo", "rtttl"]

RATGDOOutput = ratgdo_ns.class_("RATGDOOutput", cg.Component)
OutputType = ratgdo_ns.enum("OutputType")

CONF_TYPE = "type"
TYPES = {"beeper": OutputType.RATGDO_BEEPER}

CONFIG_SCHEMA = cv.Schema(
{
cv.Required(CONF_ID): cv.declare_id(RATGDOOutput),
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
cv.Required(CONF_RTTTL): cv.use_id(rtttl),
cv.Required(CONF_SONG): cv.string,
}
).extend(RATGDO_CLIENT_SCHMEA)


async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
rtttl = await cg.get_variable(config[CONF_RTTTL])
cg.add(var.set_rtttl(rtttl))
cg.add(var.set_song(config[CONF_SONG]))
await register_ratgdo_child(var, config)
58 changes: 58 additions & 0 deletions components/ratgdo/output/ratgdo_output.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "ratgdo_output.h"
#include "../ratgdo_state.h"
#include "esphome/core/log.h"

namespace esphome {
namespace ratgdo {

static const char* TAG = "ratgdo.output";

void RATGDOOutput::setup()
{
ESP_LOGD(TAG, "Output was setup");

if (this->output_type_ == OutputType::RATGDO_BEEPER) {
this->beeper_->add_on_finished_playback_callback([=] { this->finished_playback(); });

this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
if (state == VehicleArrivingState::YES) {
this->play();
}
});

this->parent_->subscribe_door_action_delayed([=](DoorActionDelayed state) {
if (state == DoorActionDelayed::YES) {
this->play();
this->repeat_ = true;
} else if (state == DoorActionDelayed::NO) {
this->repeat_ = false;
}
});
}
}

void RATGDOOutput::play()
{
this->beeper_->play(this->rtttlSong_);
}

void RATGDOOutput::finished_playback()
{
if (this->repeat_)
this->play();
}

void RATGDOOutput::dump_config()
{
if (this->output_type_ == OutputType::RATGDO_BEEPER) {
ESP_LOGCONFIG(TAG, " Type: Beeper");
}
}

void RATGDOOutput::set_output_type(OutputType output_type_)
{
this->output_type_ = output_type_;
}

} // namespace ratgdo
} // namespace esphome
32 changes: 32 additions & 0 deletions components/ratgdo/output/ratgdo_output.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "../ratgdo.h"
#include "esphome/components/rtttl/rtttl.h"
#include "esphome/core/component.h"

namespace esphome {
namespace ratgdo {

enum OutputType {
RATGDO_BEEPER
};

class RATGDOOutput : public RATGDOClient, public Component {
public:
void setup() override;
void play();
void finished_playback();
void dump_config() override;
void set_output_type(OutputType output_type);
void set_song(std::string rtttlSong) { this->rtttlSong_ = rtttlSong; }
void set_rtttl(rtttl::Rtttl* output) { this->beeper_ = output; }

protected:
OutputType output_type_;
rtttl::Rtttl* beeper_;
std::string rtttlSong_;
bool repeat_;
};

} // namespace ratgdo
} // namespace esphome
Loading

0 comments on commit 8df1cbe

Please sign in to comment.