Skip to content

Commit 84ced77

Browse files
author
Enis Hocha
committed
dimming support and heyu support
1 parent cdaa9a0 commit 84ced77

File tree

6 files changed

+824
-293
lines changed

6 files changed

+824
-293
lines changed

devicetypes/enishoca/x-10-node-red-device.src/x-10-node-red-device.groovy

+56-22
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,36 @@
1717
*/
1818

1919
metadata {
20-
definition(name: "X-10 Node Red Device", namespace: "enishoca", author: "Enis Hoca") {
21-
capability "Switch"
22-
capability "Actuator"
23-
}
24-
simulator {
25-
}
26-
tiles {
27-
28-
standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) {
29-
state "on",
30-
label: '${name}',
31-
action: "switch.off",
32-
icon: "st.switches.switch.on",
33-
backgroundColor: "#79b821"
34-
state "off",
35-
label: '${name}',
36-
action: "switch.on",
37-
icon: "st.switches.switch.off",
38-
backgroundColor: "#ffffff"
20+
definition(name: "X-10 Node Red Device", namespace: "enishoca", author: "Enis Hoca") {
21+
capability "Switch"
22+
capability "Switch Level"
3923
}
4024

41-
main "switch"
42-
details(["switch"])
43-
}
25+
// simulator metadata
26+
simulator {
27+
}
28+
29+
// UI tile definitions
30+
tiles(scale: 2) {
31+
multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true, canChangeBackground: true) {
32+
tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
33+
attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.light.off", backgroundColor: "#ffffff", nextState: "turningOn"
34+
attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.light.on", backgroundColor: "#79b821", nextState: "turningOff"
35+
attributeState "turningOff", label: '${name}', action: "switch.on", icon: "st.switches.light.off", backgroundColor: "#ffffff", nextState: "turningOn"
36+
attributeState "turningOn", label: '${name}', action: "switch.off", icon: "st.switches.light.on", backgroundColor: "#79b821", nextState: "turningOff"
37+
}
38+
tileAttribute("level", key: "SECONDARY_CONTROL") {
39+
attributeState "level", label: 'Light dimmed to ${currentValue}' //%'
40+
}
41+
}
42+
43+
controlTile("dimmerSliderControl", "device.level", "slider", height: 2, width: 2, range: "0..100", inactiveLabel: false) {
44+
state "default", action:"setLevel"
45+
}
46+
main "switch"
47+
details(["switch",
48+
"dimmerSliderControl"])
49+
}
4450
}
4551

4652
// parse events into attributes
@@ -56,3 +62,31 @@ def off() {
5662
sendEvent(name : "switch", value : "off");
5763
}
5864

65+
def setLevel(val){
66+
def prev = device.currentValue("level")
67+
log.info "setLevel $val : prev ${prev}"
68+
log.debug "current switch value: ${device.currentValue('level')}"
69+
log.debug "latest switch value: ${device.latestValue('level')}"
70+
71+
// make sure we don't drive switches past allowed values (command will hang device waiting for it to
72+
// execute. Never commes back)
73+
if (val < 0){
74+
val = 0
75+
}
76+
77+
if( val > 100){
78+
val = 100
79+
}
80+
81+
if (val == 0){
82+
sendEvent(name:"level",value:val)
83+
off()
84+
85+
}
86+
else
87+
{
88+
on()
89+
sendEvent(name:"level",value:val)
90+
sendEvent(name:"switch.setLevel",value:val)
91+
}
92+
}

0 commit comments

Comments
 (0)