diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 0de99c8f4..cd631b09c 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -8,5 +8,6 @@ - Icon for Network - MQTT Formatting payload (nested vs single) is a pull-down option - moved mqtt-topics and texts to local_EN, all topics lower case +- Re-enabled Shower Alert (still experimental) ## Removed diff --git a/src/shower.cpp b/src/shower.cpp index 838edbae8..5f01f299e 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -83,12 +83,19 @@ void Shower::loop() { } // reset everything - timer_start_ = 0; - timer_pause_ = 0; - shower_on_ = false; - shower_alert_stop(); + timer_start_ = 0; + timer_pause_ = 0; + shower_on_ = false; + doing_cold_shot_ = false; + alert_timer_start_ = 0; } } + return; + } + + // at this point we're in the shower cold shot (doing_cold_shot_ == true) + // keep repeating until the time is up + if ((time_now - alert_timer_start_) > SHOWER_COLDSHOT_DURATION) { } } @@ -124,20 +131,17 @@ void Shower::send_mqtt_stat(bool state, bool force) { void Shower::shower_alert_stop() { if (doing_cold_shot_) { LOG_DEBUG(F("Shower Alert stopped")); - // Boiler::set_tapwarmwater_activated(true); + Command::call(EMSdevice::DeviceType::BOILER, "wwtapactivated", "true"); doing_cold_shot_ = false; - // showerColdShotStopTimer.detach(); // disable the timer } } - // turn off hot water to send a shot of cold void Shower::shower_alert_start() { if (shower_alert_) { - LOG_DEBUG(F("Shower Alert started!")); - // Boiler::set_tapwarmwater_activated(false); - doing_cold_shot_ = true; - // start the timer for n seconds which will reset the water back to hot - // showerColdShotStopTimer.attach(SHOWER_COLDSHOT_DURATION, _showerColdShotStop); + LOG_DEBUG(F("Shower Alert started")); + Command::call(EMSdevice::DeviceType::BOILER, "wwtapactivated", "false"); + doing_cold_shot_ = true; + alert_timer_start_ = uuid::get_uptime(); // timer starts now } } diff --git a/src/shower.h b/src/shower.h index 4f451b6f9..7de573ec1 100644 --- a/src/shower.h +++ b/src/shower.h @@ -52,7 +52,7 @@ class Shower { static constexpr uint32_t SHOWER_PAUSE_TIME = 15000; // in ms. 15 seconds, max time if water is switched off & on during a shower static constexpr uint32_t SHOWER_MIN_DURATION = 120000; // in ms. 2 minutes, before recognizing its a shower static constexpr uint32_t SHOWER_OFFSET_TIME = 5000; // in ms. 5 seconds grace time, to calibrate actual time under the shower - static constexpr uint32_t SHOWER_COLDSHOT_DURATION = 10; // in seconds. 10 seconds for cold water before turning back hot water + static constexpr uint32_t SHOWER_COLDSHOT_DURATION = 10000; // 10 seconds for cold water before turning back hot water static constexpr uint32_t SHOWER_MAX_DURATION = 420000; // in ms. 7 minutes, before trigger a shot of cold water void publish_values(); @@ -63,10 +63,13 @@ class Shower { bool shower_alert_; // true if we want the alert of cold water bool ha_configdone_ = false; // for HA MQTT Discovery bool shower_on_; - uint32_t timer_start_; // ms - uint32_t timer_pause_; // ms - uint32_t duration_; // ms - bool doing_cold_shot_; // true if we've just sent a jolt of cold water + uint32_t timer_start_; // ms + uint32_t timer_pause_; // ms + uint32_t duration_; // ms + + // cold shot + uint32_t alert_timer_start_; // ms + bool doing_cold_shot_; // true if we've just sent a jolt of cold water }; } // namespace emsesp diff --git a/src/test/test.cpp b/src/test/test.cpp index eb1508ea8..c065e47f6 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -399,6 +399,17 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { shell.invoke_command("show mqtt"); } + if (command == "shower_alert") { + shell.printfln(F("Testing Shower Alert...")); + + run_test("boiler"); + + DynamicJsonDocument doc(EMSESP_JSON_SIZE_LARGE_DYN); + JsonObject json = doc.to(); + // device type, command, data + Command::call(EMSdevice::DeviceType::BOILER, "wwtapactivated", "false"); + } + if (command == "fr120") { shell.printfln(F("Testing adding a thermostat FR120...")); diff --git a/src/test/test.h b/src/test/test.h index 8f51d379e..d023c5c6e 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -34,7 +34,9 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "mqtt2" // #define EMSESP_DEBUG_DEFAULT "mqtt_nested" // #define EMSESP_DEBUG_DEFAULT "ha" -#define EMSESP_DEBUG_DEFAULT "board_profile" +// #define EMSESP_DEBUG_DEFAULT "board_profile" +#define EMSESP_DEBUG_DEFAULT "shower_alert" + class Test { public: