Update Switches.groovy
[smartapps.git] / third-party / AeonMinimote.groovy
1 metadata {
2         definition (name: "Aeon Minimote", namespace: "smartthings", author: "SmartThings") {
3                 capability "Actuator"
4                 capability "Button"
5                 capability "Configuration"
6                 capability "Sensor"
7                 attribute "numButtons", "STRING"
8
9                 fingerprint deviceId: "0x0101", inClusters: "0x86,0x72,0x70,0x9B", outClusters: "0x26,0x2B"
10                 fingerprint deviceId: "0x0101", inClusters: "0x86,0x72,0x70,0x9B,0x85,0x84", outClusters: "0x26" // old style with numbered buttons
11         }
12
13         simulator {
14                 status "button 1 pushed":  "command: 2001, payload: 01"
15                 status "button 1 held":  "command: 2001, payload: 15"
16                 status "button 2 pushed":  "command: 2001, payload: 29"
17                 status "button 2 held":  "command: 2001, payload: 3D"
18                 status "button 3 pushed":  "command: 2001, payload: 51"
19                 status "button 3 held":  "command: 2001, payload: 65"
20                 status "button 4 pushed":  "command: 2001, payload: 79"
21                 status "button 4 held":  "command: 2001, payload: 8D"
22                 status "wakeup":  "command: 8407, payload: "
23         }
24         tiles {
25                 standardTile("button", "device.button", width: 2, height: 2) {
26                         state "default", label: "", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#ffffff"
27                 }
28                 // Configure button.  Syncronize the device capabilities that the UI provides
29     standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat") {
30       state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
31     }
32                 main "button"
33                 details(["button", "configure"])
34         }
35 }
36
37 def parse(String description) {
38         def results = []
39         if (description.startsWith("Err")) {
40             results = createEvent(descriptionText:description, displayed:true)
41         } else {
42                 def cmd = zwave.parse(description, [0x2B: 1, 0x80: 1, 0x84: 1])
43                 if(cmd) results += zwaveEvent(cmd)
44                 if(!results) results = [ descriptionText: cmd, displayed: false ]
45         }
46         // log.debug("Parsed '$description' to $results")
47         return results
48 }
49
50 def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd) {
51         def results = [createEvent(descriptionText: "$device.displayName woke up", isStateChange: false)]
52
53     results += configurationCmds().collect{ response(it) }
54         results << response(zwave.wakeUpV1.wakeUpNoMoreInformation().format())
55
56         return results
57 }
58
59 def buttonEvent(button, held) {
60         button = button as Integer
61         if (held) {
62                 createEvent(name: "button", value: "held", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was held", isStateChange: true)
63         } else {
64                 createEvent(name: "button", value: "pushed", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pushed", isStateChange: true)
65         }
66 }
67
68 def zwaveEvent(physicalgraph.zwave.commands.sceneactivationv1.SceneActivationSet cmd) {
69         Integer button = ((cmd.sceneId + 1) / 2) as Integer
70         Boolean held = !(cmd.sceneId % 2)
71         buttonEvent(button, held)
72 }
73
74 def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
75         Integer button = (cmd.value / 40 + 1) as Integer
76         Boolean held = (button * 40 - cmd.value) <= 20
77         buttonEvent(button, held)
78 }
79
80 def zwaveEvent(physicalgraph.zwave.Command cmd) {
81         [ descriptionText: "$device.displayName: $cmd", linkText:device.displayName, displayed: false ]
82 }
83
84 def configurationCmds() {
85         def cmds = []
86         def hubId = zwaveHubNodeId
87         (1..4).each { button ->
88                 cmds << zwave.configurationV1.configurationSet(parameterNumber: 240+button, scaledConfigurationValue: 1).format()
89         }
90         (1..4).each { button ->
91                 cmds << zwave.configurationV1.configurationSet(parameterNumber: (button-1)*40, configurationValue: [hubId, (button-1)*40 + 1, 0, 0]).format()
92                 cmds << zwave.configurationV1.configurationSet(parameterNumber: (button-1)*40 + 20, configurationValue: [hubId, (button-1)*40 + 21, 0, 0]).format()
93         }
94         cmds
95 }
96
97 def configure() {
98         // Set the number of buttons to 4
99         sendEvent(name: "numButtons", value: "4", displayed: false)
100
101         def cmds = configurationCmds()
102         log.debug("Sending configuration: $cmds")
103         return cmds
104 }