hydreon_rgxx - add resolution option (#6077)

Co-authored-by: functionpointer <suspendfunction@gmail.com>
This commit is contained in:
mrtoy-me 2024-03-12 12:31:58 +10:00 committed by GitHub
parent 1dd14254b3
commit 51ab15c40e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 4 deletions

View file

@ -6,6 +6,7 @@ DEPENDENCIES = ["uart"]
hydreon_rgxx_ns = cg.esphome_ns.namespace("hydreon_rgxx")
RGModel = hydreon_rgxx_ns.enum("RGModel")
RG15Resolution = hydreon_rgxx_ns.enum("RG15Resolution")
HydreonRGxxComponent = hydreon_rgxx_ns.class_(
"HydreonRGxxComponent", cg.PollingComponent, uart.UARTDevice
)

View file

@ -22,6 +22,11 @@ void HydreonRGxxComponent::dump_config() {
ESP_LOGCONFIG(TAG, " Disable Led: %s", TRUEFALSE(this->disable_led_));
} else {
ESP_LOGCONFIG(TAG, " Model: RG15");
if (this->resolution_ == FORCE_HIGH) {
ESP_LOGCONFIG(TAG, " Resolution: high");
} else {
ESP_LOGCONFIG(TAG, " Resolution: low");
}
}
LOG_UPDATE_INTERVAL(this);
@ -195,7 +200,11 @@ void HydreonRGxxComponent::process_line_() {
ESP_LOGI(TAG, "Boot detected: %s", this->buffer_.substr(0, this->buffer_.size() - 2).c_str());
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->resolution_ == FORCE_HIGH) {
this->write_str("P\nH\nM\n"); // set sensor to (P)polling mode, (H)high res mode, (M)metric mode
} else {
this->write_str("P\nL\nM\n"); // set sensor to (P)polling mode, (L)low res mode, (M)metric mode
}
}
if (this->model_ == RG9) {

View file

@ -16,6 +16,11 @@ enum RGModel {
RG15 = 2,
};
enum RG15Resolution {
FORCE_LOW = 1,
FORCE_HIGH = 2,
};
#ifdef HYDREON_RGXX_NUM_SENSORS
static const uint8_t NUM_SENSORS = HYDREON_RGXX_NUM_SENSORS;
#else
@ -37,6 +42,7 @@ class HydreonRGxxComponent : public PollingComponent, public uart::UARTDevice {
void set_em_sat_sensor(binary_sensor::BinarySensor *sensor) { this->em_sat_sensor_ = sensor; }
#endif
void set_model(RGModel model) { model_ = model; }
void set_resolution(RG15Resolution resolution) { resolution_ = resolution; }
void set_request_temperature(bool b) { request_temperature_ = b; }
/// Schedule data readings.
@ -68,7 +74,10 @@ class HydreonRGxxComponent : public PollingComponent, public uart::UARTDevice {
int16_t boot_count_ = 0;
int16_t no_response_count_ = 0;
std::string buffer_;
RGModel model_ = RG9;
RG15Resolution resolution_ = FORCE_HIGH;
int sw_version_ = 0;
bool too_cold_ = false;
bool lens_bad_ = false;

View file

@ -5,6 +5,7 @@ from esphome.const import (
CONF_ID,
CONF_MODEL,
CONF_MOISTURE,
CONF_RESOLUTION,
CONF_TEMPERATURE,
DEVICE_CLASS_PRECIPITATION_INTENSITY,
DEVICE_CLASS_PRECIPITATION,
@ -14,7 +15,7 @@ from esphome.const import (
ICON_THERMOMETER,
)
from . import RGModel, HydreonRGxxComponent
from . import RGModel, RG15Resolution, HydreonRGxxComponent
UNIT_INTENSITY = "intensity"
UNIT_MILLIMETERS = "mm"
@ -37,11 +38,18 @@ RG_MODELS = {
# 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 = {
RG15_RESOLUTION = {
"low": RG15Resolution.FORCE_LOW,
"high": RG15Resolution.FORCE_HIGH,
}
SUPPORTED_OPTIONS = {
CONF_ACC: ["RG_15"],
CONF_EVENT_ACC: ["RG_15"],
CONF_TOTAL_ACC: ["RG_15"],
CONF_R_INT: ["RG_15"],
CONF_RESOLUTION: ["RG_15"],
CONF_MOISTURE: ["RG_9"],
CONF_TEMPERATURE: ["RG_9"],
CONF_DISABLE_LED: ["RG_9"],
@ -57,7 +65,7 @@ PROTOCOL_NAMES = {
def _validate(config):
for conf, models in SUPPORTED_SENSORS.items():
for conf, models in SUPPORTED_OPTIONS.items():
if conf in config:
if config[CONF_MODEL] not in models:
raise cv.Invalid(
@ -75,6 +83,7 @@ CONFIG_SCHEMA = cv.All(
upper=True,
space="_",
),
cv.Optional(CONF_RESOLUTION): cv.enum(RG15_RESOLUTION, upper=False),
cv.Optional(CONF_ACC): sensor.sensor_schema(
unit_of_measurement=UNIT_MILLIMETERS,
accuracy_decimals=2,
@ -139,6 +148,9 @@ async def to_code(config):
cg.add(var.set_sensor(sens, i))
cg.add(var.set_model(config[CONF_MODEL]))
if CONF_RESOLUTION in config:
cg.add(var.set_resolution(config[CONF_RESOLUTION]))
cg.add(var.set_request_temperature(CONF_TEMPERATURE in config))
if CONF_DISABLE_LED in config:

View file

@ -409,6 +409,7 @@ sensor:
name: hydreon_total_acc
r_int:
name: hydreon_r_int
resolution: low
- platform: adc
pin: VCC