mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
Hydreon updates (#5424)
This commit is contained in:
parent
a794836ebe
commit
a7d817656e
4 changed files with 56 additions and 5 deletions
|
@ -25,6 +25,10 @@ void HydreonRGxxComponent::dump_config() {
|
|||
LOG_SENSOR(" ", #s, this->sensors_[i - 1]); \
|
||||
}
|
||||
HYDREON_RGXX_PROTOCOL_LIST(HYDREON_RGXX_LOG_SENSOR, );
|
||||
|
||||
if (this->model_ == RG9) {
|
||||
ESP_LOGCONFIG(TAG, "disable_led: %s", TRUEFALSE(this->disable_led_));
|
||||
}
|
||||
}
|
||||
|
||||
void HydreonRGxxComponent::setup() {
|
||||
|
@ -187,7 +191,20 @@ void HydreonRGxxComponent::process_line_() {
|
|||
this->cancel_interval("reboot");
|
||||
this->no_response_count_ = 0;
|
||||
ESP_LOGI(TAG, "Boot detected: %s", this->buffer_.substr(0, this->buffer_.size() - 2).c_str());
|
||||
this->write_str("P\nH\nM\n"); // set sensor to polling mode, high res mode, metric mode
|
||||
|
||||
if (this->model_ == RG15) {
|
||||
this->write_str("P\nH\nM\n"); // set sensor to (P)polling mode, (H)high res mode, (M)metric mode
|
||||
}
|
||||
|
||||
if (this->model_ == RG9) {
|
||||
this->write_str("P\n"); // set sensor to (P)polling mode
|
||||
|
||||
if (this->disable_led_) {
|
||||
this->write_str("D 1\n"); // set sensor (D 1)rain detection LED disabled
|
||||
} else {
|
||||
this->write_str("D 0\n"); // set sensor (D 0)rain detection LED enabled
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this->buffer_starts_with_("SW")) {
|
||||
|
@ -227,7 +244,22 @@ void HydreonRGxxComponent::process_line_() {
|
|||
if (n == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
float data = strtof(this->buffer_.substr(n + strlen(PROTOCOL_NAMES[i])).c_str(), nullptr);
|
||||
|
||||
if (n == this->buffer_.find('t', n)) {
|
||||
// The device temperature ('t') response contains both °C and °F values:
|
||||
// "t 72F 22C".
|
||||
// ESPHome uses only °C, only parse °C value (move past 'F').
|
||||
n = this->buffer_.find('F', n);
|
||||
if (n == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
n += 1; // move past 'F'
|
||||
} else {
|
||||
n += strlen(PROTOCOL_NAMES[i]); // move past protocol name
|
||||
}
|
||||
|
||||
// parse value, starting at str position n
|
||||
float data = strtof(this->buffer_.substr(n).c_str(), nullptr);
|
||||
this->sensors_[i]->publish_state(data);
|
||||
ESP_LOGD(TAG, "Received %s: %f", PROTOCOL_NAMES[i], this->sensors_[i]->get_raw_state());
|
||||
this->sensors_received_ |= (1 << i);
|
||||
|
|
|
@ -49,6 +49,8 @@ class HydreonRGxxComponent : public PollingComponent, public uart::UARTDevice {
|
|||
|
||||
float get_setup_priority() const override;
|
||||
|
||||
void set_disable_led(bool disable_led) { this->disable_led_ = disable_led; }
|
||||
|
||||
protected:
|
||||
void process_line_();
|
||||
void schedule_reboot_();
|
||||
|
@ -72,6 +74,7 @@ class HydreonRGxxComponent : public PollingComponent, public uart::UARTDevice {
|
|||
bool lens_bad_ = false;
|
||||
bool em_sat_ = false;
|
||||
bool request_temperature_ = false;
|
||||
bool disable_led_ = false;
|
||||
|
||||
// bit field showing which sensors we have received data for
|
||||
int sensors_received_ = -1;
|
||||
|
|
|
@ -25,12 +25,17 @@ CONF_EVENT_ACC = "event_acc"
|
|||
CONF_TOTAL_ACC = "total_acc"
|
||||
CONF_R_INT = "r_int"
|
||||
|
||||
CONF_DISABLE_LED = "disable_led"
|
||||
|
||||
RG_MODELS = {
|
||||
"RG_9": RGModel.RG9,
|
||||
"RG_15": RGModel.RG15,
|
||||
# https://rainsensors.com/wp-content/uploads/sites/3/2020/07/rg-15_instructions_sw_1.000.pdf
|
||||
# https://rainsensors.com/wp-content/uploads/sites/3/2021/03/2020.08.25-rg-9_instructions.pdf
|
||||
# https://rainsensors.com/wp-content/uploads/sites/3/2021/03/2021.03.11-rg-9_instructions.pdf
|
||||
# RG-15
|
||||
# 1.000 - https://rainsensors.com/wp-content/uploads/sites/3/2020/07/rg-15_instructions_sw_1.000.pdf
|
||||
# RG-9
|
||||
# 1.000 - https://rainsensors.com/wp-content/uploads/sites/3/2021/03/2020.08.25-rg-9_instructions.pdf
|
||||
# 1.100 - https://rainsensors.com/wp-content/uploads/sites/3/2021/03/2021.03.11-rg-9_instructions.pdf
|
||||
# 1.200 - https://rainsensors.com/wp-content/uploads/sites/3/2022/03/2022.02.17-rev-1.200-rg-9_instructions.pdf
|
||||
}
|
||||
SUPPORTED_SENSORS = {
|
||||
CONF_ACC: ["RG_15"],
|
||||
|
@ -39,6 +44,7 @@ SUPPORTED_SENSORS = {
|
|||
CONF_R_INT: ["RG_15"],
|
||||
CONF_MOISTURE: ["RG_9"],
|
||||
CONF_TEMPERATURE: ["RG_9"],
|
||||
CONF_DISABLE_LED: ["RG_9"],
|
||||
}
|
||||
PROTOCOL_NAMES = {
|
||||
CONF_MOISTURE: "R",
|
||||
|
@ -105,6 +111,7 @@ CONFIG_SCHEMA = cv.All(
|
|||
icon=ICON_THERMOMETER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_DISABLE_LED): cv.boolean,
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
|
@ -132,3 +139,6 @@ async def to_code(config):
|
|||
cg.add(var.set_sensor(sens, i))
|
||||
|
||||
cg.add(var.set_request_temperature(CONF_TEMPERATURE in config))
|
||||
|
||||
if CONF_DISABLE_LED in config:
|
||||
cg.add(var.set_disable_led(config[CONF_DISABLE_LED]))
|
||||
|
|
|
@ -347,6 +347,10 @@ sensor:
|
|||
moisture:
|
||||
name: hydreon_rain
|
||||
id: hydreon_rain
|
||||
temperature:
|
||||
name: hydreon_temperature
|
||||
disable_led: true
|
||||
|
||||
- platform: hydreon_rgxx
|
||||
model: RG_15
|
||||
uart_id: uart_6
|
||||
|
@ -358,6 +362,7 @@ sensor:
|
|||
name: hydreon_total_acc
|
||||
r_int:
|
||||
name: hydreon_r_int
|
||||
|
||||
- platform: adc
|
||||
pin: VCC
|
||||
id: my_sensor
|
||||
|
@ -725,6 +730,7 @@ binary_sensor:
|
|||
name: rg9_emsat
|
||||
lens_bad:
|
||||
name: rg9_lens_bad
|
||||
|
||||
- platform: template
|
||||
id: pzemac_reset_energy
|
||||
on_press:
|
||||
|
|
Loading…
Reference in a new issue