mirror of
https://github.com/nuttytree/ESPHome-Devices.git
synced 2024-08-30 18:12:19 +00:00
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:
parent
a8bdeeba22
commit
0e61142081
@ -40,7 +40,7 @@ PoolController::PoolController() {
|
|||||||
this->cleaner_select_->set_name("Pool Cleaner Mode");
|
this->cleaner_select_->set_name("Pool Cleaner Mode");
|
||||||
this->cleaner_select_->traits.set_icon("mdi:robot-vacuum");
|
this->cleaner_select_->traits.set_icon("mdi:robot-vacuum");
|
||||||
this->cleaner_select_->traits.set_options({"Off", "Normal", "When Pump Is On"});
|
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();
|
auto options = this->cleaner_select_->traits.get_options();
|
||||||
size_t index = std::find(options.begin(), options.end(), value) - options.begin();
|
size_t index = std::find(options.begin(), options.end(), value) - options.begin();
|
||||||
this->cleaner_mode_ = static_cast<CleanerMode>(index);
|
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_component(this->pump_switch_);
|
||||||
App.register_switch(this->pump_switch_);
|
App.register_switch(this->pump_switch_);
|
||||||
this->pump_switch_->add_turn_off_check([this]() -> bool {
|
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) {
|
if (this->cleaner_switch_->state) {
|
||||||
this->cleaner_switch_->turn_off();
|
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_component(this->cleaner_switch_);
|
||||||
App.register_switch(this->cleaner_switch_);
|
App.register_switch(this->cleaner_switch_);
|
||||||
this->cleaner_switch_->add_turn_on_check([this]() {
|
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) {
|
if (!this->pump_switch_->state) {
|
||||||
this->pump_switch_->turn_on();
|
this->pump_switch_->turn_on();
|
||||||
}
|
}
|
||||||
@ -111,7 +111,9 @@ void PoolController::loop() {
|
|||||||
|
|
||||||
void PoolController::manage_pump_() {
|
void PoolController::manage_pump_() {
|
||||||
uint32_t desired_runtime = 0;
|
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_) {
|
switch (this->pump_mode_) {
|
||||||
case PumpMode::PUMP_MODE_OFF:
|
case PumpMode::PUMP_MODE_OFF:
|
||||||
if (this->pump_switch_->state) {
|
if (this->pump_switch_->state) {
|
||||||
@ -122,15 +124,15 @@ void PoolController::manage_pump_() {
|
|||||||
case PumpMode::PUMP_MODE_NORMAL:
|
case PumpMode::PUMP_MODE_NORMAL:
|
||||||
if (hour >= 4 && hour < 6) {
|
if (hour >= 4 && hour < 6) {
|
||||||
desired_runtime = RUNTIME_30_MINUTES_PER_HALF_HOUR; // normal cleaner run time
|
desired_runtime = RUNTIME_30_MINUTES_PER_HALF_HOUR; // normal cleaner run time
|
||||||
} else if (hour >= 6 && hour < 15) {
|
} else if (day_of_week > 1 && day_of_week < 7 && hour >= 15 && hour < 20 ) {
|
||||||
desired_runtime = RUNTIME_15_MINUTES_PER_HALF_HOUR;
|
|
||||||
} else if (hour >= 15 && hour < 20) {
|
|
||||||
desired_runtime = RUNTIME_10_MINUTES_PER_HALF_HOUR; // peak electric rate
|
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;
|
break;
|
||||||
|
|
||||||
case PumpMode::PUMP_MODE_ALWAYS_EXCEPT_PEAK:
|
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;
|
desired_runtime = RUNTIME_30_MINUTES_PER_HALF_HOUR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -149,7 +151,7 @@ void PoolController::manage_pump_() {
|
|||||||
|
|
||||||
void PoolController::manage_cleaner_() {
|
void PoolController::manage_cleaner_() {
|
||||||
bool desired_state = false;
|
bool desired_state = false;
|
||||||
int hour = this->time_->now().hour;
|
uint8_t hour = this->time_->now().hour;
|
||||||
switch (this->cleaner_mode_) {
|
switch (this->cleaner_mode_) {
|
||||||
case CleanerMode::CLEANER_MODE_OFF:
|
case CleanerMode::CLEANER_MODE_OFF:
|
||||||
if (this->cleaner_switch_->state) {
|
if (this->cleaner_switch_->state) {
|
||||||
@ -167,7 +169,7 @@ void PoolController::manage_cleaner_() {
|
|||||||
if (this->pump_switch_->state) {
|
if (this->pump_switch_->state) {
|
||||||
desired_state = true;
|
desired_state = true;
|
||||||
}
|
}
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->cleaner_switch_->state && desired_state && this->cleaner_switch_->get_current_off_time() > MINIMUM_AUTOMATION_PUMP_OFF_TIME) {
|
if (!this->cleaner_switch_->state && desired_state && this->cleaner_switch_->get_current_off_time() > MINIMUM_AUTOMATION_PUMP_OFF_TIME) {
|
||||||
|
@ -21,6 +21,7 @@ void PoolSelect::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PoolSelect::control(const std::string &value) {
|
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);
|
this->publish_state(value);
|
||||||
|
|
||||||
auto options = this->traits.get_options();
|
auto options = this->traits.get_options();
|
||||||
|
@ -38,15 +38,15 @@ pool_controller:
|
|||||||
pump:
|
pump:
|
||||||
switch_id: pool_pump
|
switch_id: pool_pump
|
||||||
current_id: pool_pump_current
|
current_id: pool_pump_current
|
||||||
min_current: 6.50
|
min_current: 6.45
|
||||||
max_current: 6.70
|
max_current: 6.75
|
||||||
max_out_of_range_duration: 5s
|
max_out_of_range_duration: 5s
|
||||||
cleaner:
|
cleaner:
|
||||||
switch_id: pool_cleaner
|
switch_id: pool_cleaner
|
||||||
current_id: pool_cleaner_current
|
current_id: pool_cleaner_current
|
||||||
min_current: 4.55
|
min_current: 4.50
|
||||||
max_current: 5.10
|
max_current: 5.30
|
||||||
max_out_of_range_duration: 5s
|
max_out_of_range_duration: 10s
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
- platform: ade7953
|
- platform: ade7953
|
||||||
@ -69,12 +69,12 @@ sensor:
|
|||||||
name: Pool Cleaner Power
|
name: Pool Cleaner Power
|
||||||
id: pool_cleaner_power
|
id: pool_cleaner_power
|
||||||
filters:
|
filters:
|
||||||
- lambda: "return x < .1 ? 0 : x * 2;"
|
- lambda: "return x < 1.0 ? 0 : x * 2;"
|
||||||
active_power_b:
|
active_power_b:
|
||||||
name: Pool Pump Power
|
name: Pool Pump Power
|
||||||
id: pool_pump_power
|
id: pool_pump_power
|
||||||
filters:
|
filters:
|
||||||
- lambda: "return abs(x) < .1 ? 0 : abs(x) * 2;"
|
- lambda: "return fabs(x) < 1 ? 0 : fabs(x) * 2;"
|
||||||
update_interval: 1s
|
update_interval: 1s
|
||||||
- platform: ntc
|
- platform: ntc
|
||||||
sensor: temp_resistance_reading
|
sensor: temp_resistance_reading
|
||||||
|
Loading…
Reference in New Issue
Block a user