From 7d6f8eb495af96da8f4c63e8024b7ef25ca4dcbc Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Mon, 27 Dec 2021 15:40:29 +0100 Subject: [PATCH] WS notifications on PIR state change. --- .../PIR_sensor_switch/usermod_PIR_sensor_switch.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h index 8e683a49..4846c2fe 100644 --- a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h +++ b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h @@ -188,10 +188,12 @@ private: if (sensorPinState == HIGH) { offTimerStart = 0; if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()))) switchStrip(true); + else if (NotifyUpdateMode != CALL_MODE_NO_NOTIFY) updateInterfaces(CALL_MODE_WS_SEND); publishMqtt("on"); - } else /*if (bri != 0)*/ { + } else { // start switch off timer offTimerStart = millis(); + if (NotifyUpdateMode != CALL_MODE_NO_NOTIFY) updateInterfaces(CALL_MODE_WS_SEND); } return true; } @@ -203,14 +205,13 @@ private: */ bool handleOffTimer() { - if (offTimerStart > 0 && millis() - offTimerStart > m_switchOffDelay) - { - if (enabled == true) - { + if (offTimerStart > 0 && millis() - offTimerStart > m_switchOffDelay) { + offTimerStart = 0; + if (enabled == true) { if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()))) switchStrip(false); + else if (NotifyUpdateMode != CALL_MODE_NO_NOTIFY) updateInterfaces(CALL_MODE_WS_SEND); publishMqtt("off"); } - offTimerStart = 0; return true; } return false;