-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdimmer-limit.js
More file actions
63 lines (53 loc) · 1.36 KB
/
dimmer-limit.js
File metadata and controls
63 lines (53 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// This script allows you to set upper and lower limits on the brightness of your Shelly Plus Wall Dimmer.
// Commissioned by Yandi Noa at Ikatu, created by clendinning1 and homeautomaton
// CONFIG (add your limits here):
lower_limit = 20
upper_limit = 80
// CODE (do not alter):
function def( o ) {
return typeof o !== "undefined";
}
// Set brightness
function setBrightness(brightness){
Shelly.call(
"Light.Set",
{"id":0, "brightness":brightness},
null
);
}
// Set bounds/limits
function ApplyBounds(brightness) {
if (brightness < lower_limit){
setBrightness(lower_limit)
} else if (brightness > upper_limit){
setBrightness(upper_limit)
}
}
// Check brightness
function AddHandler() {
Shelly.addStatusHandler(
function (event, userData) {
if (def(event) && def(event.delta) && def(event.delta.brightness)) {
ApplyBounds(event.delta.brightness)
print("Brightness:",event.delta.brightness)
}
}
);
}
function GetCurrentBrightness() {
let on = Shelly.getComponentStatus("light",0);
return(on.brightness)
}
function CheckInitialConditions() {
brightness = GetCurrentBrightness()
ApplyBounds(brightness)
}
function main() {
if (lower_limit >= upper_limit) {
print("Cannot set lower limit higher than upper limit.")
return
}
CheckInitialConditions()
AddHandler()
}
main()