From 7a493759ba98c23e2947f8d66ac27cca7172cead Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Sun, 11 Jan 2026 19:13:48 -0600 Subject: [PATCH] issues - most likely caused by light setting --- src/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 565f1af..e128d89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,7 +98,7 @@ void setup() { const int millisPerSecond=1000; long previousMotionMillis=millis(); -short previousState=0; +short previousState=-1; long previousNoMoNotifyMinutes=0; void loop() { @@ -108,16 +108,20 @@ void loop() { mqttClient.loop(); short currentState = digitalRead(PIR_PIN); + // This out pin triggering is dependent not only on movement, but also on light levels which can be configured in the app. + // I set it to 255 and "below" - this triggered it for me..... + //send_mqtt("occupancy_state_debug", currentState); if (currentState != previousState) { Serial.print("Status changed; currentState: "); Serial.print(currentState); Serial.print(" previousState: "); Serial.println(previousState); if (currentState == HIGH) { - send_mqtt("motion"); + send_mqtt("motion"); digitalWrite(LED_BUILTIN,HIGH); previousMotionMillis=millis(); } else { + send_mqtt("no_motion_ignore"); digitalWrite(LED_BUILTIN,LOW); } previousState = currentState; @@ -126,9 +130,9 @@ void loop() { const int secondsPerMinute=60; long minutesSinceLastMotion=(millis()-previousMotionMillis)/(millisPerSecond*secondsPerMinute); if ((previousNoMoNotifyMinutes != minutesSinceLastMotion) && (0 != minutesSinceLastMotion)) { - send_mqtt("no_motion",minutesSinceLastMotion); + send_mqtt("no_motion", minutesSinceLastMotion); previousNoMoNotifyMinutes = minutesSinceLastMotion; } - delay(20); + delay(100); }