Prevent wrong triggering by requiring 2 triggers within 30 seconds to initially react. Hopefully that helps preventing accidental triggers.
This commit is contained in:
20
src/main.cpp
20
src/main.cpp
@@ -100,6 +100,10 @@ const int millisPerSecond=1000;
|
||||
long previousMotionMillis=millis();
|
||||
short previousState=0;
|
||||
long previousNoMoNotifyMinutes=0;
|
||||
|
||||
uint repeatTriggerCounter=0;
|
||||
const int repeatTriggerResetSeconds=30;
|
||||
const short requiredRepeatsToTrigger=1;
|
||||
void loop() {
|
||||
if (!mqttClient.connected()) {
|
||||
reconnect();
|
||||
@@ -113,13 +117,27 @@ void loop() {
|
||||
Serial.print(" previousState: ");
|
||||
Serial.println(previousState);
|
||||
if (currentState == HIGH) {
|
||||
send_mqtt("motion");
|
||||
if (repeatTriggerCounter >= requiredRepeatsToTrigger) {
|
||||
send_mqtt("motion");
|
||||
} else {
|
||||
send_mqtt("motion_ignored");
|
||||
}
|
||||
digitalWrite(LED_BUILTIN,HIGH);
|
||||
previousMotionMillis=millis();
|
||||
repeatTriggerCounter++;
|
||||
}
|
||||
previousState = currentState;
|
||||
}
|
||||
|
||||
if (
|
||||
(currentState == LOW)
|
||||
&& (repeatTriggerCounter >= requiredRepeatsToTrigger)
|
||||
&& ((millis()-previousMotionMillis)/millisPerSecond >= repeatTriggerResetSeconds)
|
||||
) {
|
||||
repeatTriggerCounter =0;
|
||||
send_mqtt("motion_repeat_trigger_reset");
|
||||
}
|
||||
|
||||
const int secondsPerMinute=60;
|
||||
long minutesSinceLastMotion=(millis()-previousMotionMillis)/(millisPerSecond*secondsPerMinute);
|
||||
if ((previousNoMoNotifyMinutes != minutesSinceLastMotion) && (0 != minutesSinceLastMotion)) {
|
||||
|
||||
Reference in New Issue
Block a user