mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Add ability to lock to set mode (#5924)
This commit is contained in:
parent
84174aeb80
commit
23ceddafed
3 changed files with 10 additions and 5 deletions
|
@ -96,7 +96,7 @@ void HLW8012Component::update() {
|
|||
this->energy_sensor_->publish_state(energy);
|
||||
}
|
||||
|
||||
if (this->change_mode_at_++ == this->change_mode_every_) {
|
||||
if (this->change_mode_every_ != 0 && this->change_mode_at_++ == this->change_mode_every_) {
|
||||
this->current_mode_ = !this->current_mode_;
|
||||
ESP_LOGV(TAG, "Changing mode to %s mode", this->current_mode_ ? "CURRENT" : "VOLTAGE");
|
||||
this->change_mode_at_ = 0;
|
||||
|
|
|
@ -79,8 +79,9 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
cv.Optional(CONF_CURRENT_RESISTOR, default=0.001): cv.resistance,
|
||||
cv.Optional(CONF_VOLTAGE_DIVIDER, default=2351): cv.positive_float,
|
||||
cv.Optional(CONF_MODEL, default="HLW8012"): cv.enum(MODELS, upper=True),
|
||||
cv.Optional(CONF_CHANGE_MODE_EVERY, default=8): cv.All(
|
||||
cv.uint32_t, cv.Range(min=1)
|
||||
cv.Optional(CONF_CHANGE_MODE_EVERY, default=8): cv.Any(
|
||||
"never",
|
||||
cv.All(cv.uint32_t, cv.Range(min=1)),
|
||||
),
|
||||
cv.Optional(CONF_INITIAL_MODE, default=CONF_VOLTAGE): cv.one_of(
|
||||
*INITIAL_MODES, lower=True
|
||||
|
@ -114,6 +115,10 @@ async def to_code(config):
|
|||
cg.add(var.set_energy_sensor(sens))
|
||||
cg.add(var.set_current_resistor(config[CONF_CURRENT_RESISTOR]))
|
||||
cg.add(var.set_voltage_divider(config[CONF_VOLTAGE_DIVIDER]))
|
||||
cg.add(var.set_change_mode_every(config[CONF_CHANGE_MODE_EVERY]))
|
||||
cg.add(var.set_initial_mode(INITIAL_MODES[config[CONF_INITIAL_MODE]]))
|
||||
cg.add(var.set_sensor_model(config[CONF_MODEL]))
|
||||
|
||||
interval = config[CONF_CHANGE_MODE_EVERY]
|
||||
if interval == "never":
|
||||
interval = 0
|
||||
cg.add(var.set_change_mode_every(interval))
|
||||
|
|
|
@ -794,7 +794,7 @@ sensor:
|
|||
update_interval: 15s
|
||||
current_resistor: 0.001 ohm
|
||||
voltage_divider: 2351
|
||||
change_mode_every: 16
|
||||
change_mode_every: "never"
|
||||
initial_mode: VOLTAGE
|
||||
model: hlw8012
|
||||
- platform: total_daily_energy
|
||||
|
|
Loading…
Reference in a new issue