diff --git a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h
index 421528bf..98150753 100644
--- a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h
+++ b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h
@@ -2,6 +2,15 @@
#include "wled.h"
+#ifndef PIR_SENSOR_PIN
+ // compatible with QuinLED-Dig-Uno
+ #ifdef ARDUINO_ARCH_ESP32
+ #define PIR_SENSOR_PIN 23 // Q4
+ #else //ESP8266 boards
+ #define PIR_SENSOR_PIN 13 // Q4 (D7 on D1 mini)
+ #endif
+#endif
+
/*
* This usermod handles PIR sensor states.
* The strip will be switched on and the off timer will be resetted when the sensor goes HIGH.
@@ -24,6 +33,9 @@
* 2. Register the usermod by adding #include "usermod_filename.h" in the top and registerUsermod(new MyUsermodClass()) in the bottom of usermods_list.cpp
*/
+// MQTT topic for sensor values
+const char MQTT_TOPIC[] = "/motion";
+
class PIRsensorSwitch : public Usermod
{
public:
@@ -60,7 +72,7 @@ public:
private:
// PIR sensor pin
- const uint8_t PIRsensorPin = 13; // D7 on D1 mini
+ int8_t PIRsensorPin = PIR_SENSOR_PIN;
// notification mode for colorUpdated()
const byte NotifyUpdateMode = NOTIFIER_CALL_MODE_NO_NOTIFY; // NOTIFIER_CALL_MODE_DIRECT_CHANGE
// delay before switch off after the sensor state goes LOW
@@ -107,6 +119,17 @@ private:
}
}
+ void publishMqtt(const char* state)
+ {
+ //Check if MQTT Connected, otherwise it will crash the 8266
+ if (mqtt != nullptr){
+ char subuf[64];
+ strcpy(subuf, mqttDeviceTopic);
+ strcat(subuf, MQTT_TOPIC);
+ mqtt->publish(subuf, 0, true, state);
+ }
+ }
+
/**
* Read and update PIR sensor state.
* Initilize/reset switch off timer
@@ -121,6 +144,7 @@ private:
{
m_offTimerStart = 0;
switchStrip(true);
+ publishMqtt("on");
}
else if (bri != 0)
{
@@ -143,6 +167,7 @@ private:
if (m_PIRenabled == true)
{
switchStrip(false);
+ publishMqtt("off");
}
m_offTimerStart = 0;
return true;
@@ -159,12 +184,19 @@ public:
*/
void setup()
{
- // PIR Sensor mode INPUT_PULLUP
- pinMode(PIRsensorPin, INPUT_PULLUP);
- if (m_PIRenabled)
- {
- // assign interrupt function and set CHANGE mode
- attachInterrupt(digitalPinToInterrupt(PIRsensorPin), ISR_PIRstateChange, CHANGE);
+ // pin retrieved from cfg.json (readFromConfig()) prior to running setup()
+ if (!pinManager.allocatePin(PIRsensorPin,false)) {
+ PIRsensorPin = -1; // allocation failed
+ m_PIRenabled = false;
+ DEBUG_PRINTLN(F("PIRSensorSwitch pin allocation failed."));
+ } else {
+ // PIR Sensor mode INPUT_PULLUP
+ pinMode(PIRsensorPin, INPUT_PULLUP);
+ if (m_PIRenabled)
+ {
+ // assign interrupt function and set CHANGE mode
+ attachInterrupt(digitalPinToInterrupt(PIRsensorPin), ISR_PIRstateChange, CHANGE);
+ }
}
}
@@ -273,8 +305,8 @@ after ())));
+ m_switchOffDelay = (1000 * max(60UL, min(43200UL, root[F("PIRoffSec")].as())));
m_updateConfig = true;
}
- if (root["PIRenabled"] != nullptr)
+ if (root[F("pin")] != nullptr)
{
- if (root["PIRenabled"] && !m_PIRenabled)
+ int8_t pin = (int)root[F("pin")];
+ // check if pin is OK
+ if (pin != PIRsensorPin && pin>=0 && pinManager.allocatePin(pin,false)) {
+ // deallocate old pin
+ pinManager.deallocatePin(PIRsensorPin);
+ // PIR Sensor mode INPUT_PULLUP
+ pinMode(pin, INPUT_PULLUP);
+ if (m_PIRenabled)
+ {
+ // remove old ISR
+ detachInterrupt(PIRsensorPin);
+ // assign interrupt function and set CHANGE mode
+ attachInterrupt(digitalPinToInterrupt(pin), ISR_PIRstateChange, CHANGE);
+ newPIRsensorState(true, true);
+ }
+ PIRsensorPin = pin;
+ m_updateConfig = true;
+ }
+ }
+
+ if (root[F("PIRenabled")] != nullptr)
+ {
+ if (root[F("PIRenabled")] && !m_PIRenabled)
{
attachInterrupt(digitalPinToInterrupt(PIRsensorPin), ISR_PIRstateChange, CHANGE);
newPIRsensorState(true, true);
@@ -302,7 +356,7 @@ after | | | | ";
+ ih+=" | | | | ";
for (j=1;j<8;j++) ih+=" | ";
}
- ih+="
| Sunrise | | | ";
+ ih+="
| Sunrise | | | ";
for (j=1;j<8;j++) ih+=" | ";
- ih+="
| Sunset | | | ";
+ ih+="
| Sunset | | | ";
for (j=1;j<8;j++) ih+=" | ";
gId("TMT").innerHTML=ih;
}
@@ -142,8 +142,8 @@
Countdown Mode:
Countdown Goal:
- Year: 20 Month: Day:
- Hour: Minute: Second:
+ Year: 20 Month: Day:
+ Hour: Minute: Second:
Macro presets
Macros have moved!
Presets now also can be used as macros to save both JSON and HTTP API commands.
diff --git a/wled00/data/style.css b/wled00/data/style.css
index 0fc3fa21..423b3097 100644
--- a/wled00/data/style.css
+++ b/wled00/data/style.css
@@ -43,6 +43,12 @@ input[type="number"] {
font-size: medium;
margin: 2px;
}
+input[type="number"].big {
+ width: 80px;
+}
+input[type="number"].small {
+ width: 40px;
+}
select {
margin: 2px;
font-size: medium;
diff --git a/wled00/html_settings.h b/wled00/html_settings.h
index 6c602b35..f9149fb1 100644
--- a/wled00/html_settings.h
+++ b/wled00/html_settings.h
@@ -6,7 +6,7 @@
*/
// Autogenerated from wled00/data/style.css, do not edit!!
-const char PAGE_settingsCss[] PROGMEM = R"=====()=====";
+const char PAGE_settingsCss[] PROGMEM = R"=====()=====";
// Autogenerated from wled00/data/settings.htm, do not edit!!
@@ -297,7 +297,7 @@ type="submit">Save