-
Notifications
You must be signed in to change notification settings - Fork 81
/
philio_psm01.device.groovy
180 lines (152 loc) · 5.81 KB
/
philio_psm01.device.groovy
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* Philio PSM01 3-in-1 Multi Sensor Device Type
* based on SmartThings' Aeon Multi Sensor Reference Device Type
*/
metadata {
definition (name: "My PSM01 Sensor - Kitchen Refrigerator", namespace: "jscgs350", author: "SmartThings/Paul Spee") {
capability "Contact Sensor"
capability "Temperature Measurement"
capability "Illuminance Measurement"
capability "Configuration"
capability "Sensor"
capability "Battery"
capability "Refresh"
capability "Polling"
fingerprint deviceId: "0x2001", inClusters: "0x30,0x31,0x80,0x84,0x70,0x85,0x72,0x86"
}
tiles {
// standardTile("contact", "device.contact", width: 2, height: 2) {
// state "close", label:'closed', icon:"st.contact.contact.closed", backgroundColor:"#79b821"
// state "open", label:'open', icon:"st.contact.contact.open", backgroundColor:"#ffa81e"
// }
standardTile("contact", "device.contact", width: 2, height: 2) {
state "close", label: 'Frig Closed', icon: "st.fridge.fridge-closed", backgroundColor: "#ffffff"
state "open", label: 'Frig Open', icon: "st.fridge.fridge-open", backgroundColor: "#ffa81e"
}
valueTile("temperature", "device.temperature", inactiveLabel: false) {
state "temperature", label:'${currentValue}°',
backgroundColors:[
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
}
valueTile("illuminance", "device.illuminance", inactiveLabel: false) {
state "luminosity", label:'${currentValue} ${unit}', unit:"lux"
}
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat") {
state "battery", label:'${currentValue}% battery', unit:""
}
standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat") {
state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
}
standardTile("refresh", "device.thermostatMode", inactiveLabel: false, decoration: "flat") {
state "default", action:"polling.poll", icon:"st.secondary.refresh"
}
main(["contact", "temperature", "illuminance"])
details(["contact", "temperature", "illuminance", "battery", "configure", "refresh"])
}
}
preferences {
}
def installed() {
log.debug "PSM01: Installed with settings: ${settings}"
configure()
}
def updated() {
log.debug "PSM01: Updated with settings: ${settings}"
configure()
}
// parse() with a Map argument is called after a sendEvent(device)
// In this case, we are receiving an event from the PSM01 Helper App to generate a "inactive" event
def parse(Map evt){
log.debug "Parse(Map) called with map ${evt}"
def result = [];
if (evt)
result << evt;
log.debug "Parse(Map) returned ${result}"
return result
}
// Parse incoming device messages to generate events
def parse(String description)
{
log.debug "Parse called with ${description}"
def result = []
def cmd = zwave.parse(description, [0x20: 1, 0x31: 2, 0x30: 2, 0x80: 1, 0x84: 2, 0x85: 2])
if (cmd) {
if( cmd.CMD == "8407" ) { result << new physicalgraph.device.HubAction(zwave.wakeUpV1.wakeUpNoMoreInformation().format()) }
def evt = zwaveEvent(cmd)
result << createEvent(evt)
}
log.debug "Parse returned ${result}"
return result
}
// Event Generation
def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd)
{
[descriptionText: "${device.displayName} woke up", isStateChange: false]
}
def zwaveEvent(physicalgraph.zwave.commands.sensormultilevelv2.SensorMultilevelReport cmd)
{
def map = [:]
switch (cmd.sensorType) {
case 1:
// temperature
def cmdScale = cmd.scale == 1 ? "F" : "C"
map.value = convertTemperatureIfNeeded(cmd.scaledSensorValue, cmdScale, cmd.precision)
map.unit = getTemperatureScale()
map.name = "temperature"
break;
case 3:
// luminance
map.value = cmd.scaledSensorValue.toInteger().toString()
map.unit = "lux"
map.name = "illuminance"
break;
}
map
}
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def map = [:]
map.name = "battery"
map.value = cmd.batteryLevel > 0 ? cmd.batteryLevel.toString() : 1
map.unit = "%"
map.displayed = false
map
}
def zwaveEvent(physicalgraph.zwave.commands.sensorbinaryv2.SensorBinaryReport cmd) {
log.debug "PSM01: SensorBinaryReport ${cmd.toString()}}"
def map = [:]
switch (cmd.sensorType) {
case 10: // contact sensor
map.name = "contact"
if (cmd.sensorValue) {
map.value = "open"
map.descriptionText = "$device.displayName is open"
} else {
map.value = "close"
map.descriptionText = "$device.displayName is closed"
}
break;
}
map
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
log.debug "PSM01: Catchall reached for cmd: ${cmd.toString()}}"
[:]
}
def configure() {
log.debug "PSM01: configure() called"
delayBetween([
//1 tick = 30 minutes
zwave.configurationV1.configurationSet(parameterNumber: 10, size: 1, scaledConfigurationValue: 4).format(), // Auto report Battery time 1-127, default 12
zwave.configurationV1.configurationSet(parameterNumber: 11, size: 1, scaledConfigurationValue: 2).format(), // Auto report Door/Window state time 1-127, default 12
zwave.configurationV1.configurationSet(parameterNumber: 12, size: 1, scaledConfigurationValue: 2).format(), // Auto report Illumination time 1-127, default 12
zwave.configurationV1.configurationSet(parameterNumber: 13, size: 1, scaledConfigurationValue: 2).format(), // Auto report Temperature time 1-127, default 12
zwave.wakeUpV1.wakeUpIntervalSet(seconds: 1 * 3600, nodeid:zwaveHubNodeId).format(), // Wake up every hour
])
}