From 0e61142081f0ee0cf810562b6cc996e5b46cc43c Mon Sep 17 00:00:00 2001 From: Chris Nussbaum Date: Mon, 20 Sep 2021 15:25:11 -0500 Subject: [PATCH] Pool Controller Bug Fixes: (#26) * Fix cleaner mode callback * Fix turn on/off check logging * Peak rate time doesn't apply on weekends * Actually turn on the cleaner in "When Pump Is On" mode * Expand current range * Use floating point abs for pump power --- .../pool_controller/pool_controller.cpp | 22 ++++++++++--------- components/pool_controller/pool_select.cpp | 1 + devices/pool_pumps.yaml | 14 ++++++------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/components/pool_controller/pool_controller.cpp b/components/pool_controller/pool_controller.cpp index 621520b..ce0b932 100644 --- a/components/pool_controller/pool_controller.cpp +++ b/components/pool_controller/pool_controller.cpp @@ -40,7 +40,7 @@ PoolController::PoolController() { this->cleaner_select_->set_name("Pool Cleaner Mode"); this->cleaner_select_->traits.set_icon("mdi:robot-vacuum"); this->cleaner_select_->traits.set_options({"Off", "Normal", "When Pump Is On"}); - this->pump_select_->add_on_state_callback([this](std::string value) -> void { + this->cleaner_select_->add_on_state_callback([this](std::string value) -> void { auto options = this->cleaner_select_->traits.get_options(); size_t index = std::find(options.begin(), options.end(), value) - options.begin(); this->cleaner_mode_ = static_cast(index); @@ -79,7 +79,7 @@ void PoolController::set_pump_switch(switch_::Switch *pump_switch) { App.register_component(this->pump_switch_); App.register_switch(this->pump_switch_); this->pump_switch_->add_turn_off_check([this]() -> bool { - ESP_LOGD(TAG, "Pump switch turn off check is checking the state of %s", this->get_name().c_str()); + ESP_LOGD(TAG, "Pump switch turn off check is checking the state of the pool cleaner"); if (this->cleaner_switch_->state) { this->cleaner_switch_->turn_off(); } @@ -92,7 +92,7 @@ void PoolController::set_cleaner_switch(switch_::Switch *cleaner_switch) { App.register_component(this->cleaner_switch_); App.register_switch(this->cleaner_switch_); this->cleaner_switch_->add_turn_on_check([this]() { - ESP_LOGD(TAG, "Cleaner switch turn on check is checking the state of %s", this->get_name().c_str()); + ESP_LOGD(TAG, "Cleaner switch turn on check is checking the state of the pool pump"); if (!this->pump_switch_->state) { this->pump_switch_->turn_on(); } @@ -111,7 +111,9 @@ void PoolController::loop() { void PoolController::manage_pump_() { uint32_t desired_runtime = 0; - int hour = this->time_->now().hour; + time::ESPTime now = this->time_->now(); + uint8_t hour = now.hour; + uint8_t day_of_week = now.day_of_week; switch (this->pump_mode_) { case PumpMode::PUMP_MODE_OFF: if (this->pump_switch_->state) { @@ -122,15 +124,15 @@ void PoolController::manage_pump_() { case PumpMode::PUMP_MODE_NORMAL: if (hour >= 4 && hour < 6) { desired_runtime = RUNTIME_30_MINUTES_PER_HALF_HOUR; // normal cleaner run time - } else if (hour >= 6 && hour < 15) { - desired_runtime = RUNTIME_15_MINUTES_PER_HALF_HOUR; - } else if (hour >= 15 && hour < 20) { + } else if (day_of_week > 1 && day_of_week < 7 && hour >= 15 && hour < 20 ) { desired_runtime = RUNTIME_10_MINUTES_PER_HALF_HOUR; // peak electric rate + } else if (hour >= 6 && hour < 20) { + desired_runtime = RUNTIME_15_MINUTES_PER_HALF_HOUR; } break; case PumpMode::PUMP_MODE_ALWAYS_EXCEPT_PEAK: - if (hour < 15 && hour >= 20) { + if (day_of_week == 1 || day_of_week == 7 || hour < 15 || hour >= 20) { desired_runtime = RUNTIME_30_MINUTES_PER_HALF_HOUR; } break; @@ -149,7 +151,7 @@ void PoolController::manage_pump_() { void PoolController::manage_cleaner_() { bool desired_state = false; - int hour = this->time_->now().hour; + uint8_t hour = this->time_->now().hour; switch (this->cleaner_mode_) { case CleanerMode::CLEANER_MODE_OFF: if (this->cleaner_switch_->state) { @@ -167,7 +169,7 @@ void PoolController::manage_cleaner_() { if (this->pump_switch_->state) { desired_state = true; } - return; + break; } if (!this->cleaner_switch_->state && desired_state && this->cleaner_switch_->get_current_off_time() > MINIMUM_AUTOMATION_PUMP_OFF_TIME) { diff --git a/components/pool_controller/pool_select.cpp b/components/pool_controller/pool_select.cpp index 58b8bf3..09cc7e0 100644 --- a/components/pool_controller/pool_select.cpp +++ b/components/pool_controller/pool_select.cpp @@ -21,6 +21,7 @@ void PoolSelect::setup() { } void PoolSelect::control(const std::string &value) { + ESP_LOGD(TAG, "%s changed to option %s", this->get_name().c_str(), value.c_str()); this->publish_state(value); auto options = this->traits.get_options(); diff --git a/devices/pool_pumps.yaml b/devices/pool_pumps.yaml index d5b59b7..7bec069 100644 --- a/devices/pool_pumps.yaml +++ b/devices/pool_pumps.yaml @@ -38,15 +38,15 @@ pool_controller: pump: switch_id: pool_pump current_id: pool_pump_current - min_current: 6.50 - max_current: 6.70 + min_current: 6.45 + max_current: 6.75 max_out_of_range_duration: 5s cleaner: switch_id: pool_cleaner current_id: pool_cleaner_current - min_current: 4.55 - max_current: 5.10 - max_out_of_range_duration: 5s + min_current: 4.50 + max_current: 5.30 + max_out_of_range_duration: 10s sensor: - platform: ade7953 @@ -69,12 +69,12 @@ sensor: name: Pool Cleaner Power id: pool_cleaner_power filters: - - lambda: "return x < .1 ? 0 : x * 2;" + - lambda: "return x < 1.0 ? 0 : x * 2;" active_power_b: name: Pool Pump Power id: pool_pump_power filters: - - lambda: "return abs(x) < .1 ? 0 : abs(x) * 2;" + - lambda: "return fabs(x) < 1 ? 0 : fabs(x) * 2;" update_interval: 1s - platform: ntc sensor: temp_resistance_reading