diff --git a/usermods/RelayBlinds/index.htm b/usermods/RelayBlinds/index.htm new file mode 100644 index 00000000..048cff01 --- /dev/null +++ b/usermods/RelayBlinds/index.htm @@ -0,0 +1,76 @@ + + + + + Blinds + + + + + + + + + + + + + + + + + +
+ + + +
+ + \ No newline at end of file diff --git a/usermods/RelayBlinds/presets.json b/usermods/RelayBlinds/presets.json new file mode 100644 index 00000000..95b58715 --- /dev/null +++ b/usermods/RelayBlinds/presets.json @@ -0,0 +1 @@ +{"0":{},"2":{"n":"▲","win":"U0=2"},"1":{"n":"▼","win":"U0=1"}} \ No newline at end of file diff --git a/usermods/RelayBlinds/readme.md b/usermods/RelayBlinds/readme.md new file mode 100644 index 00000000..0c3d2a0b --- /dev/null +++ b/usermods/RelayBlinds/readme.md @@ -0,0 +1,8 @@ +# RelayBlinds usermod + +This simple usermod toggles two relay pins momentarily (default for 500ms) when `userVar0` is set. +This can be used to e.g. "push" the buttons of a window blinds motor controller. + +v1 usermod. Please replace usermod.cpp in the `wled00` directory with the one in this file. +You may upload `index.htm` to `[WLED-IP]/edit` to replace the default lighting UI with a simple Up/Down button one. +Also, a simple `presets.json` file is available, this makes the relay actions controllable via two presets to facilitate control e.g. via the default UI or Alexa. \ No newline at end of file diff --git a/usermods/RelayBlinds/usermod.cpp b/usermods/RelayBlinds/usermod.cpp new file mode 100644 index 00000000..ee61b0cc --- /dev/null +++ b/usermods/RelayBlinds/usermod.cpp @@ -0,0 +1,83 @@ +#include "wled.h" + +//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t) + +//gets called once at boot. Do all initialization that doesn't depend on network here +void userSetup() +{ + +} + +//gets called every time WiFi is (re-)connected. Initialize own network interfaces here +void userConnected() +{ + +} + +/* + * Physical IO + */ +#define PIN_UP_RELAY 4 +#define PIN_DN_RELAY 5 +#define PIN_ON_TIME 500 +bool upActive = false, upActiveBefore = false, downActive = false, downActiveBefore = false; +unsigned long upStartTime = 0, downStartTime = 0; + +void handleRelay() +{ + //up and down relays + if (userVar0) { + upActive = true; + if (userVar0 == 1) { + upActive = false; + downActive = true; + } + userVar0 = 0; + } + + if (upActive) + { + if(!upActiveBefore) + { + pinMode(PIN_UP_RELAY, OUTPUT); + digitalWrite(PIN_UP_RELAY, LOW); + upActiveBefore = true; + upStartTime = millis(); + DEBUG_PRINTLN("UPA"); + } + if (millis()- upStartTime > PIN_ON_TIME) + { + upActive = false; + DEBUG_PRINTLN("UPN"); + } + } else if (upActiveBefore) + { + pinMode(PIN_UP_RELAY, INPUT); + upActiveBefore = false; + } + + if (downActive) + { + if(!downActiveBefore) + { + pinMode(PIN_DN_RELAY, OUTPUT); + digitalWrite(PIN_DN_RELAY, LOW); + downActiveBefore = true; + downStartTime = millis(); + } + if (millis()- downStartTime > PIN_ON_TIME) + { + downActive = false; + } + } else if (downActiveBefore) + { + pinMode(PIN_DN_RELAY, INPUT); + downActiveBefore = false; + } +} + +//loop. You can use "if (WLED_CONNECTED)" to check for successful connection +void userLoop() +{ + handleRelay(); +} \ No newline at end of file