/
RM Virtual Dimmer
74 lines (63 loc) · 2.12 KB
/
RM Virtual Dimmer
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
64
65
66
67
68
69
70
71
72
73
74
metadata {
definition (name: "RM Virtual Dimmer", namespace: "itsamti", author: "itsamti") {
capability "Switch"
capability "Refresh"
capability "Switch Level"
}
// simulator metadata
simulator {
}
// UI tile definitions
tiles {
standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: 'Off', action: "switch.on", icon: "st.Kids.kid10", backgroundColor: "#ffffff", nextState: "on"
state "on", label: 'On', action: "switch.off", icon: "st.Kids.kid10", backgroundColor: "#79b821", nextState: "off"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, backgroundColor:"#ffe71e") {
state "level", action:"switch level.setLevel"
}
valueTile("lValue", "device.level", inactiveLabel: true, height:1, width:1, decoration: "flat") {
state "levelValue", label:'${currentValue}%', unit:"", backgroundColor: "#53a7c0"
}
main(["button"])
details(["button", "refresh","levelSliderControl","lValue"])
}
}
def parse(String description) {
}
def on() {
sendEvent(name: "switch", value: "on")
log.info "Dimmer On"
}
def off() {
sendEvent(name: "switch", value: "off")
log.info "Dimmer Off"
}
def setLevel(val){
log.info "setLevel $val"
// make sure we don't drive switches past allowed values (command will hang device waiting for it to
// execute. Never commes back)
if (val < 0){
val = 0
}
if( val > 100){
val = 100
}
if (val == 0){ // I liked that 0 = off
sendEvent(name:"level",value:val)
off()
}
else
{
on()
sendEvent(name:"level",value:val)
sendEvent(name:"switch.setLevel",value:val) // had to add this to work if apps subscribed to
// setLevel event. "Dim With Me" was one.
}
}
def refresh() {
log.info "refresh"
}