Skip to content

Commit 1b2134d

Browse files
committed
Add old blinds usermod
1 parent f922268 commit 1b2134d

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

usermods/RelayBlinds/index.htm

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
4+
<meta charset="utf-8">
5+
<title>Blinds</title>
6+
<script>
7+
strA = "";
8+
function send()
9+
{
10+
nocache = "&nocache=" + Math.random() * 1000000;
11+
var request = new XMLHttpRequest();
12+
// send HTTP request
13+
request.open("GET", "win/" + strA +nocache, true);
14+
request.send(null);
15+
strA = "";
16+
}
17+
function up()
18+
{
19+
strA = "&U0=2";
20+
send();
21+
}
22+
function down()
23+
{
24+
strA = "&U0=1";
25+
send();
26+
}
27+
function OpenSettings()
28+
{
29+
window.open("/settings", "_self");
30+
}
31+
</script>
32+
<style>
33+
body {
34+
text-align: center;
35+
background: linear-gradient(45deg,#0ca,#0ac);
36+
height: 100%;
37+
margin: 0;
38+
background-repeat: no-repeat;
39+
background-attachment: fixed;
40+
}
41+
html {
42+
height: 100%;
43+
}
44+
svg {
45+
width: 30vw;
46+
padding: 2vh;
47+
}
48+
.tool_box {
49+
position: absolute;
50+
top: 50%;
51+
left: 50%;
52+
transform: translate(-50%, -50%);
53+
}
54+
</style>
55+
<style id="holderjs-style" type="text/css"></style></head>
56+
<body class=" __plain_text_READY__">
57+
<svg style="position: absolute; width: 0; height: 0; overflow: hidden;" version="1.1" xmlns="http://www.w3.org/2000/svg">
58+
<defs>
59+
<symbol id="icon-box-add" viewBox="0 0 32 32">
60+
<path d="M26 2h-20l-6 6v21c0 0.552 0.448 1 1 1h30c0.552 0 1-0.448 1-1v-21l-6-6zM16 26l-10-8h6v-6h8v6h6l-10 8zM4.828 6l2-2h18.343l2 2h-22.343z"></path>
61+
</symbol>
62+
<symbol id="icon-box-remove" viewBox="0 0 32 32">
63+
<path d="M26 2h-20l-6 6v21c0 0.552 0.448 1 1 1h30c0.552 0 1-0.448 1-1v-21l-6-6zM20 20v6h-8v-6h-6l10-8 10 8h-6zM4.828 6l2-2h18.343l2 2h-22.343z"></path>
64+
</symbol>
65+
<symbol id="icon-cog" viewBox="0 0 32 32">
66+
<path d="M29.181 19.070c-1.679-2.908-0.669-6.634 2.255-8.328l-3.145-5.447c-0.898 0.527-1.943 0.829-3.058 0.829-3.361 0-6.085-2.742-6.085-6.125h-6.289c0.008 1.044-0.252 2.103-0.811 3.070-1.679 2.908-5.411 3.897-8.339 2.211l-3.144 5.447c0.905 0.515 1.689 1.268 2.246 2.234 1.676 2.903 0.672 6.623-2.241 8.319l3.145 5.447c0.895-0.522 1.935-0.82 3.044-0.82 3.35 0 6.067 2.725 6.084 6.092h6.289c-0.003-1.034 0.259-2.080 0.811-3.038 1.676-2.903 5.399-3.894 8.325-2.219l3.145-5.447c-0.899-0.515-1.678-1.266-2.232-2.226zM16 22.479c-3.578 0-6.479-2.901-6.479-6.479s2.901-6.479 6.479-6.479c3.578 0 6.479 2.901 6.479 6.479s-2.901 6.479-6.479 6.479z"></path>
67+
</symbol>
68+
</defs>
69+
</svg>
70+
<div id="tbB" class="tool_box">
71+
<svg id="upb" onclick="up()"><use xlink:href="#icon-box-remove"></use></svg>
72+
<svg id="dnb" onclick="down()"><use xlink:href="#icon-box-add"></use></svg>
73+
<svg id="stb" onclick="OpenSettings()"><use xlink:href="#icon-cog"></use></svg>
74+
</div>
75+
</body>
76+
</html>

usermods/RelayBlinds/presets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"0":{},"2":{"n":"","win":"U0=2"},"1":{"n":"","win":"U0=1"}}

usermods/RelayBlinds/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RelayBlinds usermod
2+
3+
This simple usermod toggles two relay pins momentarily (default for 500ms) when `userVar0` is set.
4+
This can be used to e.g. "push" the buttons of a window blinds motor controller.
5+
6+
v1 usermod. Please replace usermod.cpp in the `wled00` directory with the one in this file.
7+
You may upload `index.htm` to `[WLED-IP]/edit` to replace the default lighting UI with a simple Up/Down button one.
8+
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.

usermods/RelayBlinds/usermod.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "wled.h"
2+
3+
//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t)
4+
5+
//gets called once at boot. Do all initialization that doesn't depend on network here
6+
void userSetup()
7+
{
8+
9+
}
10+
11+
//gets called every time WiFi is (re-)connected. Initialize own network interfaces here
12+
void userConnected()
13+
{
14+
15+
}
16+
17+
/*
18+
* Physical IO
19+
*/
20+
#define PIN_UP_RELAY 4
21+
#define PIN_DN_RELAY 5
22+
#define PIN_ON_TIME 500
23+
bool upActive = false, upActiveBefore = false, downActive = false, downActiveBefore = false;
24+
unsigned long upStartTime = 0, downStartTime = 0;
25+
26+
void handleRelay()
27+
{
28+
//up and down relays
29+
if (userVar0) {
30+
upActive = true;
31+
if (userVar0 == 1) {
32+
upActive = false;
33+
downActive = true;
34+
}
35+
userVar0 = 0;
36+
}
37+
38+
if (upActive)
39+
{
40+
if(!upActiveBefore)
41+
{
42+
pinMode(PIN_UP_RELAY, OUTPUT);
43+
digitalWrite(PIN_UP_RELAY, LOW);
44+
upActiveBefore = true;
45+
upStartTime = millis();
46+
DEBUG_PRINTLN("UPA");
47+
}
48+
if (millis()- upStartTime > PIN_ON_TIME)
49+
{
50+
upActive = false;
51+
DEBUG_PRINTLN("UPN");
52+
}
53+
} else if (upActiveBefore)
54+
{
55+
pinMode(PIN_UP_RELAY, INPUT);
56+
upActiveBefore = false;
57+
}
58+
59+
if (downActive)
60+
{
61+
if(!downActiveBefore)
62+
{
63+
pinMode(PIN_DN_RELAY, OUTPUT);
64+
digitalWrite(PIN_DN_RELAY, LOW);
65+
downActiveBefore = true;
66+
downStartTime = millis();
67+
}
68+
if (millis()- downStartTime > PIN_ON_TIME)
69+
{
70+
downActive = false;
71+
}
72+
} else if (downActiveBefore)
73+
{
74+
pinMode(PIN_DN_RELAY, INPUT);
75+
downActiveBefore = false;
76+
}
77+
}
78+
79+
//loop. You can use "if (WLED_CONNECTED)" to check for successful connection
80+
void userLoop()
81+
{
82+
handleRelay();
83+
}

0 commit comments

Comments
 (0)