mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 17:54:13 +01:00
hydreon_rgxx - add resolution option (#6077)
Co-authored-by: functionpointer <suspendfunction@gmail.com>
This commit is contained in:
parent
1dd14254b3
commit
51ab15c40e
5 changed files with 36 additions and 4 deletions
|
@ -6,6 +6,7 @@ DEPENDENCIES = ["uart"]
|
||||||
|
|
||||||
hydreon_rgxx_ns = cg.esphome_ns.namespace("hydreon_rgxx")
|
hydreon_rgxx_ns = cg.esphome_ns.namespace("hydreon_rgxx")
|
||||||
RGModel = hydreon_rgxx_ns.enum("RGModel")
|
RGModel = hydreon_rgxx_ns.enum("RGModel")
|
||||||
|
RG15Resolution = hydreon_rgxx_ns.enum("RG15Resolution")
|
||||||
HydreonRGxxComponent = hydreon_rgxx_ns.class_(
|
HydreonRGxxComponent = hydreon_rgxx_ns.class_(
|
||||||
"HydreonRGxxComponent", cg.PollingComponent, uart.UARTDevice
|
"HydreonRGxxComponent", cg.PollingComponent, uart.UARTDevice
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,6 +22,11 @@ void HydreonRGxxComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, " Disable Led: %s", TRUEFALSE(this->disable_led_));
|
ESP_LOGCONFIG(TAG, " Disable Led: %s", TRUEFALSE(this->disable_led_));
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGCONFIG(TAG, " Model: RG15");
|
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);
|
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());
|
ESP_LOGI(TAG, "Boot detected: %s", this->buffer_.substr(0, this->buffer_.size() - 2).c_str());
|
||||||
|
|
||||||
if (this->model_ == RG15) {
|
if (this->model_ == RG15) {
|
||||||
|
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
|
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) {
|
if (this->model_ == RG9) {
|
||||||
|
|
|
@ -16,6 +16,11 @@ enum RGModel {
|
||||||
RG15 = 2,
|
RG15 = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum RG15Resolution {
|
||||||
|
FORCE_LOW = 1,
|
||||||
|
FORCE_HIGH = 2,
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef HYDREON_RGXX_NUM_SENSORS
|
#ifdef HYDREON_RGXX_NUM_SENSORS
|
||||||
static const uint8_t NUM_SENSORS = HYDREON_RGXX_NUM_SENSORS;
|
static const uint8_t NUM_SENSORS = HYDREON_RGXX_NUM_SENSORS;
|
||||||
#else
|
#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; }
|
void set_em_sat_sensor(binary_sensor::BinarySensor *sensor) { this->em_sat_sensor_ = sensor; }
|
||||||
#endif
|
#endif
|
||||||
void set_model(RGModel model) { model_ = model; }
|
void set_model(RGModel model) { model_ = model; }
|
||||||
|
void set_resolution(RG15Resolution resolution) { resolution_ = resolution; }
|
||||||
void set_request_temperature(bool b) { request_temperature_ = b; }
|
void set_request_temperature(bool b) { request_temperature_ = b; }
|
||||||
|
|
||||||
/// Schedule data readings.
|
/// Schedule data readings.
|
||||||
|
@ -68,7 +74,10 @@ class HydreonRGxxComponent : public PollingComponent, public uart::UARTDevice {
|
||||||
int16_t boot_count_ = 0;
|
int16_t boot_count_ = 0;
|
||||||
int16_t no_response_count_ = 0;
|
int16_t no_response_count_ = 0;
|
||||||
std::string buffer_;
|
std::string buffer_;
|
||||||
|
|
||||||
RGModel model_ = RG9;
|
RGModel model_ = RG9;
|
||||||
|
RG15Resolution resolution_ = FORCE_HIGH;
|
||||||
|
|
||||||
int sw_version_ = 0;
|
int sw_version_ = 0;
|
||||||
bool too_cold_ = false;
|
bool too_cold_ = false;
|
||||||
bool lens_bad_ = false;
|
bool lens_bad_ = false;
|
||||||
|
|
|
@ -5,6 +5,7 @@ from esphome.const import (
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
CONF_MODEL,
|
CONF_MODEL,
|
||||||
CONF_MOISTURE,
|
CONF_MOISTURE,
|
||||||
|
CONF_RESOLUTION,
|
||||||
CONF_TEMPERATURE,
|
CONF_TEMPERATURE,
|
||||||
DEVICE_CLASS_PRECIPITATION_INTENSITY,
|
DEVICE_CLASS_PRECIPITATION_INTENSITY,
|
||||||
DEVICE_CLASS_PRECIPITATION,
|
DEVICE_CLASS_PRECIPITATION,
|
||||||
|
@ -14,7 +15,7 @@ from esphome.const import (
|
||||||
ICON_THERMOMETER,
|
ICON_THERMOMETER,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import RGModel, HydreonRGxxComponent
|
from . import RGModel, RG15Resolution, HydreonRGxxComponent
|
||||||
|
|
||||||
UNIT_INTENSITY = "intensity"
|
UNIT_INTENSITY = "intensity"
|
||||||
UNIT_MILLIMETERS = "mm"
|
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.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
|
# 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_ACC: ["RG_15"],
|
||||||
CONF_EVENT_ACC: ["RG_15"],
|
CONF_EVENT_ACC: ["RG_15"],
|
||||||
CONF_TOTAL_ACC: ["RG_15"],
|
CONF_TOTAL_ACC: ["RG_15"],
|
||||||
CONF_R_INT: ["RG_15"],
|
CONF_R_INT: ["RG_15"],
|
||||||
|
CONF_RESOLUTION: ["RG_15"],
|
||||||
CONF_MOISTURE: ["RG_9"],
|
CONF_MOISTURE: ["RG_9"],
|
||||||
CONF_TEMPERATURE: ["RG_9"],
|
CONF_TEMPERATURE: ["RG_9"],
|
||||||
CONF_DISABLE_LED: ["RG_9"],
|
CONF_DISABLE_LED: ["RG_9"],
|
||||||
|
@ -57,7 +65,7 @@ PROTOCOL_NAMES = {
|
||||||
|
|
||||||
|
|
||||||
def _validate(config):
|
def _validate(config):
|
||||||
for conf, models in SUPPORTED_SENSORS.items():
|
for conf, models in SUPPORTED_OPTIONS.items():
|
||||||
if conf in config:
|
if conf in config:
|
||||||
if config[CONF_MODEL] not in models:
|
if config[CONF_MODEL] not in models:
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
|
@ -75,6 +83,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
upper=True,
|
upper=True,
|
||||||
space="_",
|
space="_",
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_RESOLUTION): cv.enum(RG15_RESOLUTION, upper=False),
|
||||||
cv.Optional(CONF_ACC): sensor.sensor_schema(
|
cv.Optional(CONF_ACC): sensor.sensor_schema(
|
||||||
unit_of_measurement=UNIT_MILLIMETERS,
|
unit_of_measurement=UNIT_MILLIMETERS,
|
||||||
accuracy_decimals=2,
|
accuracy_decimals=2,
|
||||||
|
@ -139,6 +148,9 @@ async def to_code(config):
|
||||||
cg.add(var.set_sensor(sens, i))
|
cg.add(var.set_sensor(sens, i))
|
||||||
|
|
||||||
cg.add(var.set_model(config[CONF_MODEL]))
|
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))
|
cg.add(var.set_request_temperature(CONF_TEMPERATURE in config))
|
||||||
|
|
||||||
if CONF_DISABLE_LED in config:
|
if CONF_DISABLE_LED in config:
|
||||||
|
|
|
@ -409,6 +409,7 @@ sensor:
|
||||||
name: hydreon_total_acc
|
name: hydreon_total_acc
|
||||||
r_int:
|
r_int:
|
||||||
name: hydreon_r_int
|
name: hydreon_r_int
|
||||||
|
resolution: low
|
||||||
|
|
||||||
- platform: adc
|
- platform: adc
|
||||||
pin: VCC
|
pin: VCC
|
||||||
|
|
Loading…
Reference in a new issue