diff --git a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h index 6682dde3d..03839d8df 100644 --- a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h +++ b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h @@ -72,6 +72,9 @@ private: // on and off presets uint8_t m_onPreset = 0; uint8_t m_offPreset = 0; + // nighttime presets (optional) + uint8_t m_onNighttime = 0; + uint8_t m_offNighttime = 0; // flag to indicate that PIR sensor should activate WLED during nighttime only bool m_nightTimeOnly = false; // flag to send MQTT message only (assuming it is enabled) @@ -88,6 +91,8 @@ private: static const char _enabled[]; static const char _onPreset[]; static const char _offPreset[]; + static const char _onNighttime[]; + static const char _offNighttime[]; static const char _nightTime[]; static const char _mqttOnly[]; static const char _offOnly[]; @@ -97,24 +102,23 @@ private: * if sunrise/sunset is not defined (no NTP or lat/lon) default to nighttime */ bool isDayTime() { - bool isDayTime = false; updateLocalTime(); uint8_t hr = hour(localTime); uint8_t mi = minute(localTime); if (sunrise && sunset) { if (hour(sunrise)
hr) { - isDayTime = true; + return true; } else { if (hour(sunrise)==hr && minute(sunrise)mi) { - isDayTime = true; + return true; } } } - return isDayTime; + return false; } /** @@ -124,17 +128,33 @@ private: { if (m_offOnly && bri && (switchOn || (!PIRtriggered && !switchOn))) return; PIRtriggered = switchOn; - if (switchOn && m_onPreset) { - applyPreset(m_onPreset); - } else if (!switchOn && m_offPreset) { - applyPreset(m_offPreset); - } else if (switchOn && bri == 0) { - bri = briLast; - colorUpdated(NotifyUpdateMode); - } else if (!switchOn && bri != 0) { - briLast = bri; - bri = 0; - colorUpdated(NotifyUpdateMode); + if (switchOn) { + if (m_onNighttime && !isDayTime()) { + applyPreset(m_onNighttime); + return; + } else if (m_onPreset) { + applyPreset(m_onPreset); + return; + } + // preset not assigned + if (bri == 0) { + bri = briLast; + colorUpdated(NotifyUpdateMode); + } + } else { + if (m_offNighttime && !isDayTime()) { + applyPreset(m_offNighttime); + return; + } else if (m_offPreset) { + applyPreset(m_offPreset); + return; + } + // preset not assigned + if (bri != 0) { + briLast = bri; + bri = 0; + colorUpdated(NotifyUpdateMode); + } } } @@ -248,11 +268,21 @@ public: JsonObject user = root["u"]; if (user.isNull()) user = root.createNestedObject("u"); - if (enabled) - { - // off timer - String uiDomString = F("PIR "); - JsonArray infoArr = user.createNestedArray(uiDomString); // timer value + String uiDomString = F(""); + JsonArray infoArr = user.createNestedArray(uiDomString); // timer value + + if (enabled) { if (m_offTimerStart > 0) { uiDomString = ""; @@ -282,8 +312,6 @@ public: infoArr.add(sensorPinState ? F("sensor on") : F("inactive")); } } else { - String uiDomString = F("PIR sensor"); - JsonArray infoArr = user.createNestedArray(uiDomString); infoArr.add(F("disabled")); } } @@ -302,11 +330,18 @@ public: * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). * Values in the state object may be modified by connected clients */ -/* + void readFromJsonState(JsonObject &root) { + if (!initDone) return; // prevent crash on boot applyPreset() + JsonObject usermod = root[FPSTR(_name)]; + if (!usermod.isNull()) { + if (usermod[FPSTR(_enabled)].is()) { + enabled = usermod[FPSTR(_enabled)].as(); + } + } } -*/ + /** * provide the changeable values @@ -314,14 +349,16 @@ public: void addToConfig(JsonObject &root) { JsonObject top = root.createNestedObject(FPSTR(_name)); - top[FPSTR(_enabled)] = enabled; + top[FPSTR(_enabled)] = enabled; top[FPSTR(_switchOffDelay)] = m_switchOffDelay / 1000; - top["pin"] = PIRsensorPin; - top[FPSTR(_onPreset)] = m_onPreset; - top[FPSTR(_offPreset)] = m_offPreset; - top[FPSTR(_nightTime)] = m_nightTimeOnly; - top[FPSTR(_mqttOnly)] = m_mqttOnly; - top[FPSTR(_offOnly)] = m_offOnly; + top["pin"] = PIRsensorPin; + top[FPSTR(_onPreset)] = m_onPreset; + top[FPSTR(_offPreset)] = m_offPreset; + top[FPSTR(_onNighttime)] = m_onNighttime; + top[FPSTR(_offNighttime)] = m_offNighttime; + top[FPSTR(_nightTime)] = m_nightTimeOnly; + top[FPSTR(_mqttOnly)] = m_mqttOnly; + top[FPSTR(_offOnly)] = m_offOnly; DEBUG_PRINTLN(F("PIR config saved.")); } @@ -336,9 +373,9 @@ public: bool oldEnabled = enabled; int8_t oldPin = PIRsensorPin; + DEBUG_PRINT(FPSTR(_name)); JsonObject top = root[FPSTR(_name)]; if (top.isNull()) { - DEBUG_PRINT(FPSTR(_name)); DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); return false; } @@ -351,15 +388,18 @@ public: m_onPreset = top[FPSTR(_onPreset)] | m_onPreset; m_onPreset = max(0,min(250,(int)m_onPreset)); - m_offPreset = top[FPSTR(_offPreset)] | m_offPreset; m_offPreset = max(0,min(250,(int)m_offPreset)); + m_onNighttime = top[FPSTR(_onNighttime)] | m_onNighttime; + m_onNighttime = max(0,min(250,(int)m_onNighttime)); + m_offNighttime = top[FPSTR(_offNighttime)] | m_offNighttime; + m_offNighttime = max(0,min(250,(int)m_offNighttime)); + m_nightTimeOnly = top[FPSTR(_nightTime)] | m_nightTimeOnly; m_mqttOnly = top[FPSTR(_mqttOnly)] | m_mqttOnly; m_offOnly = top[FPSTR(_offOnly)] | m_offOnly; - DEBUG_PRINT(FPSTR(_name)); if (!initDone) { // reading config prior to setup() DEBUG_PRINTLN(F(" config loaded.")); @@ -385,7 +425,7 @@ public: DEBUG_PRINTLN(F(" config (re)loaded.")); } // use "return !top["newestParameter"].isNull();" when updating Usermod with new features - return !top[FPSTR(_offOnly)].isNull(); + return !top[FPSTR(_onNighttime)].isNull(); } /** @@ -404,6 +444,8 @@ const char PIRsensorSwitch::_enabled[] PROGMEM = "PIRenabled"; const char PIRsensorSwitch::_switchOffDelay[] PROGMEM = "PIRoffSec"; const char PIRsensorSwitch::_onPreset[] PROGMEM = "on-preset"; const char PIRsensorSwitch::_offPreset[] PROGMEM = "off-preset"; +const char PIRsensorSwitch::_onNighttime[] PROGMEM = "on-nighttime"; +const char PIRsensorSwitch::_offNighttime[] PROGMEM = "off-nighttime"; const char PIRsensorSwitch::_nightTime[] PROGMEM = "nighttime-only"; const char PIRsensorSwitch::_mqttOnly[] PROGMEM = "mqtt-only"; const char PIRsensorSwitch::_offOnly[] PROGMEM = "off-only"; diff --git a/wled00/data/index.css b/wled00/data/index.css index 0902a9b5e..e58a5d95c 100644 --- a/wled00/data/index.css +++ b/wled00/data/index.css @@ -128,11 +128,6 @@ button { font-size: 42px; } -.infot { - table-layout: fixed; - width: 100%; -} - .segt, .plentry TABLE { table-layout: fixed; width: 100%; @@ -455,14 +450,24 @@ button { } #kv, #kn { - max-width: 490px; + /*max-width: 490px;*/ display: inline-block; } -#kv td { +#info table, #nodes table { + table-layout: fixed; + width: 490px; + margin: auto; +} + +#info td, #nodes td { padding-bottom: 8px; } +#info .btn, #nodes .btn { + margin: 0; +} + #lv { max-width: 600px; display: inline-block; @@ -1130,14 +1135,17 @@ input[type="text"].fnd:hover { @media all and (max-width: 335px) { .sliderbubble { - display: none; - } + display: none; + } } @media all and (max-width: 550px) and (min-width: 374px) { - .infobtn { + #info .btn, #nodes .btn { width: 155px; } + #info table, #nodes table { + width: 320px; + } } @media all and (max-width: 540px) { diff --git a/wled00/data/index.htm b/wled00/data/index.htm index 7a7973905..5a24c59dc 100644 --- a/wled00/data/index.htm +++ b/wled00/data/index.htm @@ -201,18 +201,28 @@
Loading...

- -
- -
+ + + + + + + + + +

Made with ❤︎ by Aircoookie and the WLED community