Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into feat_conditions

This commit is contained in:
MichaelDvP
2024-06-20 14:51:56 +02:00
19 changed files with 144 additions and 96 deletions

View File

@@ -77,6 +77,10 @@
#define EMSESP_DEFAULT_SHOWER_ALERT_TRIGGER 7
#endif
#ifndef EMSESP_DEFAULT_SHOWER_MIN_DURATION
#define EMSESP_DEFAULT_SHOWER_MIN_DURATION 120
#endif
#ifndef EMSESP_DEFAULT_SHOWER_ALERT_COLDSHOT
#define EMSESP_DEFAULT_SHOWER_ALERT_COLDSHOT 10
#endif

View File

@@ -28,8 +28,9 @@ void Shower::start() {
EMSESP::webSettingsService.read([&](WebSettings & settings) {
shower_timer_ = settings.shower_timer;
shower_alert_ = settings.shower_alert;
shower_alert_trigger_ = settings.shower_alert_trigger * 60000; // convert from minutes
shower_alert_coldshot_ = settings.shower_alert_coldshot * 1000; // convert from seconds
shower_alert_trigger_ = settings.shower_alert_trigger * 60; // convert from minutes to seconds
shower_alert_coldshot_ = settings.shower_alert_coldshot; // in seconds
shower_min_duration_ = settings.shower_min_duration; // in seconds
});
Command::add(
@@ -60,7 +61,8 @@ void Shower::loop() {
return;
}
uint32_t time_now = uuid::get_uptime();
// uint32_t time_now = uuid::get_uptime(); // in ms
auto time_now = uuid::get_uptime_sec(); // in sec
// if already in cold mode, ignore all this logic until we're out of the cold blast
if (!doing_cold_shot_) {
@@ -78,7 +80,7 @@ void Shower::loop() {
} else {
// hot water has been on for a while
// first check to see if hot water has been on long enough to be recognized as a Shower/Bath
if (!shower_state_ && (time_now - timer_start_) > SHOWER_MIN_DURATION) {
if (!shower_state_ && (time_now - timer_start_) > shower_min_duration_) {
set_shower_state(true);
LOG_DEBUG("hot water still running, starting shower timer");
}
@@ -99,7 +101,7 @@ void Shower::loop() {
// because its unsigned long, can't have negative so check if length is less than OFFSET_TIME
if ((timer_pause_ - timer_start_) > SHOWER_OFFSET_TIME) {
duration_ = (timer_pause_ - timer_start_ - SHOWER_OFFSET_TIME);
if (duration_ > SHOWER_MIN_DURATION) {
if (duration_ > shower_min_duration_) {
JsonDocument doc;
// duration in seconds
@@ -145,7 +147,7 @@ void Shower::shower_alert_start() {
(void)Command::call(EMSdevice::DeviceType::BOILER, "tapactivated", "false", 9);
doing_cold_shot_ = true;
force_coldshot = false;
alert_timer_start_ = uuid::get_uptime(); // timer starts now
alert_timer_start_ = uuid::get_uptime_sec(); // timer starts now
}
// turn back on the hot water for the shower

View File

@@ -36,11 +36,8 @@ class Shower {
private:
static uuid::log::Logger logger_;
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_MIN_DURATION = 5000; // for testing in ms. 5 seconds
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_PAUSE_TIME = 15; // 15 seconds, max time if water is switched off & on during a shower
static constexpr uint32_t SHOWER_OFFSET_TIME = 5; // 5 seconds grace time, to calibrate actual time under the shower
void shower_alert_start();
void shower_alert_stop();
@@ -49,15 +46,17 @@ class Shower {
bool shower_alert_; // true if we want the alert of cold water
uint32_t shower_alert_trigger_; // default 7 minutes, before trigger a shot of cold water
uint32_t shower_alert_coldshot_; // default 10 seconds for cold water before turning back hot water
uint32_t shower_min_duration_; // default 2 minutes (120 seconds), before recognizing its a shower
uint32_t next_alert_;
bool ha_configdone_ = false; // for HA MQTT Discovery
bool shower_state_;
uint32_t timer_start_; // ms
uint32_t timer_pause_; // ms
uint32_t duration_; // ms
uint32_t timer_start_; // sec
uint32_t timer_pause_; // sec
uint32_t duration_; // sec
// cold shot
uint32_t alert_timer_start_; // ms
uint32_t alert_timer_start_; // sec
bool doing_cold_shot_; // true if we've just sent a jolt of cold water
};

View File

@@ -1452,12 +1452,13 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
// Settings
node = output["Settings"].to<JsonObject>();
EMSESP::webSettingsService.read([&](WebSettings & settings) {
node["board profile"] = settings.board_profile;
node["locale"] = settings.locale;
node["tx mode"] = settings.tx_mode;
node["ems bus id"] = settings.ems_bus_id;
node["shower timer"] = settings.shower_timer;
node["shower alert"] = settings.shower_alert;
node["board profile"] = settings.board_profile;
node["locale"] = settings.locale;
node["tx mode"] = settings.tx_mode;
node["ems bus id"] = settings.ems_bus_id;
node["shower timer"] = settings.shower_timer;
node["shower alert"] = settings.shower_alert;
node["shpwe_min_duration"] = settings.shower_min_duration; // seconds
if (settings.shower_alert) {
node["shower alert coldshot"] = settings.shower_alert_coldshot; // seconds
node["shower alert trigger"] = settings.shower_alert_trigger; // minutes

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.7.0-dev.14"
#define EMSESP_APP_VERSION "3.7.0-dev.15"

View File

@@ -47,6 +47,7 @@ void WebSettings::read(WebSettings & settings, JsonObject root) {
root["shower_alert"] = settings.shower_alert;
root["shower_alert_coldshot"] = settings.shower_alert_coldshot;
root["shower_alert_trigger"] = settings.shower_alert_trigger;
root["shower_min_duration"] = settings.shower_min_duration;
root["rx_gpio"] = settings.rx_gpio;
root["tx_gpio"] = settings.tx_gpio;
root["dallas_gpio"] = settings.dallas_gpio;
@@ -237,6 +238,9 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
prev = settings.shower_alert_trigger;
settings.shower_alert_trigger = root["shower_alert_trigger"] | EMSESP_DEFAULT_SHOWER_ALERT_TRIGGER;
check_flag(prev, settings.shower_alert_trigger, ChangeFlags::SHOWER);
prev = settings.shower_min_duration;
settings.shower_min_duration = root["shower_min_duration"] | EMSESP_DEFAULT_SHOWER_MIN_DURATION;
check_flag(prev, settings.shower_min_duration, ChangeFlags::SHOWER);
prev = settings.shower_alert_coldshot;
settings.shower_alert_coldshot = root["shower_alert_coldshot"] | EMSESP_DEFAULT_SHOWER_ALERT_COLDSHOT;
check_flag(prev, settings.shower_alert_coldshot, ChangeFlags::SHOWER);

View File

@@ -36,8 +36,9 @@ class WebSettings {
bool boiler_heatingoff;
bool shower_timer;
bool shower_alert;
uint8_t shower_alert_trigger;
uint8_t shower_alert_coldshot;
uint8_t shower_alert_trigger; // minutes
uint8_t shower_alert_coldshot; // seconds
uint32_t shower_min_duration; // seconds
bool syslog_enabled;
int8_t syslog_level; // uuid::log::Level
uint32_t syslog_mark_interval;