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
This commit is contained in:
Chris Nussbaum 2021-09-20 15:25:11 -05:00 committed by GitHub
parent a8bdeeba22
commit 0e61142081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 17 deletions

View File

@ -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<CleanerMode>(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) {

View File

@ -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();

View File

@ -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