Go to the documentation of this file.
71 time_t currentTime = millis();
92 #ifdef EMAIL_NOTIFICATION
93 sendEmailLeakDetected();
102 #ifdef EMAIL_NOTIFICATION
103 void HighLeakDetection::sendEmailLeakDetected() {
106 "High leak detected!",
107 "High leak was just detected\n\r"
109 "limit for leak to be detected: " +
121 #ifdef EMAIL_NOTIFICATION
124 String state =
bypass ?
"on" :
"off";
127 getType() +
" leak detection BYPASS",
128 "bypass is now " + state
144 percentDetected *= 100;
145 return min(100, percentDetected);
152 time_t currentTime = millis();
158 return min(100, percentReset);
162 const String HighLeakDetection::getLogID()
const {
return "[HIGH LEAK]"; }
164 const String HighLeakDetection::getLogDescription()
const {
166 String(
"BYPASS=") + String(
bypass) +
" | " +
167 String(
"ACTIVE=") + String(
active) +
" | " +
170 String(
"CONFIG=") + ((
config == &
alarmConfig) ? String(
"ALARM") : String(
"NORMAL")) +
" | " +
181 return getType() +
" water leak";
185 return String(
"BYPASS=") + String(
bypass) + String(
" | ") + String(
"ACTIVE=") + String(
active);
207 return fce->second(*
this);
212 return String(
"OFF");
218 return String(
"Detected");
219 return String(
"Undetected");
225 return String(
"OFF");
240 if (percentage < 60)
return "rgba(44, 62, 80, 0.301)";
241 if (percentage >= 60 && percentage < 75)
return "#ffdc52";
242 if (percentage >= 75 && percentage < 85)
return "#fca758";
LeakDetectionConfig_t alarmConfig
alarm configuration for when there's nobody in the house
String timeOfDetection
time when the leak has been detected
@ BYPASS
when a bypass changes
HighLeakDetection * highLeakDetection
String getType() const
Returns the type of the water leak detection algorithm.
PulseCounter pulseCounter(SENSOR_PIN)
time_t getLastPulseTime() const
Return the time when the last pulse was detected.
std::map< int, String(*)(const HighLeakDetection &highLeakDetection)> htmlData
A map of different values (keys) and their associated functions which returns the appropriate values.
HighLeakDetection(PulseCounter *pulseCounter, Type type, LeakDetectionConfig_t normalConfig, LeakDetectionConfig_t alarmConfig)
Constructor of the class.
friend String HTML_resetLimitSecsAlarm(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (secs) in the alarm configuration.
time_t limitResetTime
limit reset time e.g. 5 mins, 24h, ....
int limitPulseAction
limit action in pulses
int resetWhenDetected
the reset value (%) when a leak was detected
#define HIGH_ILOCK_LED_PIN
high-water leak LED (detected = on)
float getPercentLeakDetectionReset() const
Returns percentage information about how close a high-water leak is from being detected.
String getFormatOfSettingsToSave() override
Returns the current settings of the algorithm.
LeakDetectionConfig_t * config
pointer to the current configuration
bool detected
indication if a leak has been detected
friend String HTML_activePercentage(const HighLeakDetection &highLeakDetection)
Associated function for returing the [%] information about how close a leak is from being detected.
#define DAYS(time)
Calculates the number of days when formatting the time given in milliseconds.
void reset() override
Resets the algorithm.
int bypassPin
number of the bypass pin
friend String HTML_detectedTime(const HighLeakDetection &highLeakDetection)
Associated function for returing the detection time of a high-water leak.
void testResetLeak() override
Tests if the high-water the algorithm should be reset based on inactivity of pulse on the input pin.
friend String HTML_resetLimitMins(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (mins) in the normal configuration.
const String getRow(int row) const override
Returns the content of the row given as a parameter.
void applyNewConfig()
Applies the new config configuration.
int pulseCount
number of pulses detected so far
static DateTime * getInstance()
Returns the instance of the class.
@ LEAK_DETECTED
when a leak has been detected
static const String UNDEFINED_DATA
string "UNDEFINED"
friend String HTML_bypass(const HighLeakDetection &highLeakDetection)
Associated function for returing information about the state of the bypass.
friend String HTML_resetPercentage(const HighLeakDetection &highLeakDetection)
Associated function for returing the [%] information about how close the algorithm is from being rese...
LeakDetectionConfig_t newNormalConfig
new parameters of the normal config when the user changes them
friend String HTML_detectionLimitAlarm(const HighLeakDetection &highLeakDetection)
Associated function for returing the limit (detection) in terms of the alarm configuration.
unsigned long time_t
Referring to the data type unsigned long as time_t.
#define PULSE_TO_LITER(p)
Converts pulses to liters.
friend String HTML_resetLimitHoursAlarm(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (hours) in the alarm configuration.
Type
The type of the water leak detection algorithm.
byte sendEmail(String subject, String data)
Sends an e-mail off to the smtp2go server.
friend String HTML_detectionLimit(const HighLeakDetection &highLeakDetection)
Associated function for returing the limit (detection) in terms of the normal configuration.
friend String HTML_resetLimitMinsAlarm(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (mins) in the alarm configuration.
String getDateTimeStr() const
Returns the current datatime in a string format.
#define SECS(time)
Calculates the number of seconds when formatting the time given in milliseconds.
int active
indication if a leak has been detected + bypass is off
LeakDetectionConfig_t newAlarmConfig
new parameters of the alarm config when the user changes them
const String getHTMLData(const int id) const override
Since this class is registered as a source of data for the HTML content, it needs return the appropri...
int isActive() const
Returns information if a pulse has been detected.
friend String HTML_resetLimitDaysAlarm(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (days) in the alarm configuration.
friend String HTML_activePercentageColor(const HighLeakDetection &highLeakDetection)
Associated function for returing a color according to [%] information about how close a leak is from ...
friend String HTML_detectedText(const HighLeakDetection &highLeakDetection)
Associated function for returing information about a high-water leak being detected (2)
int oldBypassValue
old bypass value (used for sending e-mails)
void testActiveLeak() override
Tests if a high-water leak has occurred, and if so, it will set the appropriate variables and flags.
friend String HTML_resetLimitDays(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (days) in the normal configuration.
#define DELTA_TIME(time1, time2)
Calculates the time difference between two times given as parameters.
PulseCounter * pulseCounter
instance of a pulse counter (input of the system)
float getPercentLeakDetected() const
Returns percentage information about how close the algorithm is from being reset.
friend String HTML_resetLimitSecs(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (secs) in the normal configuration.
#define MINS(time)
Calculates the number of minutes when formatting the time given in milliseconds.
void update() override
Updates the algorithm.
#define HOURS(time)
Calculates the number of hours when formatting the time given in milliseconds.
friend String HTML_detected(const HighLeakDetection &highLeakDetection)
Associated function for returing information about a high-water leak being detected (1)
LeakDetectionConfig_t normalConfig
normal configuarion for when the house is occupied
static EmailSender * getInstance()
Returns the instance of the class.
friend String HTML_resetLimitHours(const HighLeakDetection &highLeakDetection)
Associated function for returing the reset time (hours) in the normal configuration.