Advertisement
Guest User

GE Portable Smart Motion Sensor

a guest
Oct 20th, 2020
1,645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.47 KB | None | 0 0
  1. /**
  2. * GE Portable Smart Motion Sensor (Model 34193) DTH
  3. *
  4. * Copyright © 2018 Michael Struck
  5. * Original Author: Jeremy Williams (@jwillaz)
  6. *
  7. * Version 1.0.1 9/29/18
  8. *
  9. * Version 1.0.0 (11/17/17)- Original release by Jeremy Williams . Great Work!
  10. * Version 1.0.1 (9/29/18)- Updated by Michael Struck-Streamlined interface, added additional logging
  11. *
  12. * Uses code from SmartThings
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  15. * in compliance with the License. You may obtain a copy of the License at:
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  20. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  21. * for the specific language governing permissions and limitations under the License.
  22. *
  23. */
  24. metadata {
  25. definition (name: "GE Portable Smart Motion Sensor 34193", namespace: "MichaelStruck", author: "Michael Struck", ocfDeviceType: "x.com.st.d.sensor.motion") {
  26. capability "Motion Sensor"
  27. capability "Sensor"
  28. capability "Battery"
  29. capability "Health Check"
  30.  
  31. fingerprint mfr: "0063", prod: "4953", model: "3133", deviceJoinName: "GE Portable Smart Motion Sensor"
  32. }
  33. simulator {
  34. status "inactive": "command: 3003, payload: 00"
  35. status "active": "command: 3003, payload: FF"
  36. }
  37. preferences {
  38. input "parameterThirteen", "enum", title: "Motion Sensitivity (Default: 'High')", options: [1:"Low", 2:"Medium", 3:"High"], defaultValue: 3, required: false
  39. input "parameterEighteen", "number", title: "Motion Timeout Duration (1 to 60 minutes or 255 = 5 seconds) Default: 4 minutes", defaultValue: 4, required: false
  40. input "parameterTwentyEight", "bool", title: "Enable LED Flash Indicator", defaultValue: true
  41. }
  42. tiles(scale: 2) {
  43. multiAttributeTile(name:"motion", type: "generic", width: 6, height: 4){
  44. tileAttribute("device.motion", key: "PRIMARY_CONTROL") {
  45. attributeState("active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#00A0DC")
  46. attributeState("inactive", label:'no motion', icon:"st.motion.motion.inactive", backgroundColor:"#CCCCCC")
  47. }
  48. tileAttribute ("battery", key: "SECONDARY_CONTROL") {
  49. attributeState "battery", label:'Battery: ${currentValue}%'
  50. }
  51. }
  52. main "motion"
  53. details(["motion"])
  54. }
  55. }
  56. def installed() {
  57. // Device wakes up every 4 hours, this interval allows us to miss one wakeup notification before marking offline
  58. sendEvent(name: "checkInterval", value: 8 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
  59. }
  60. def updated() {
  61. //Device wakes up every 4 hours, this interval allows us to miss one wakeup notification before marking offline
  62. sendEvent(name: "checkInterval", value: 8 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
  63. response(configure())
  64. }
  65. private getCommandClassVersions() {
  66. [0x20: 1, 0x30: 1, 0x31: 5, 0x80: 1, 0x84: 1, 0x71: 3, 0x9C: 1]
  67. }
  68. def parse(String description) {
  69. def result = null
  70. if (description.startsWith("Err")) {
  71. result = createEvent(descriptionText:description)
  72. } else {
  73. def cmd = zwave.parse(description, commandClassVersions)
  74. if (cmd) {
  75. result = zwaveEvent(cmd)
  76. } else {
  77. result = createEvent(value: description, descriptionText: description, isStateChange: false)
  78. }
  79. }
  80. return result
  81. }
  82. def sensorValueEvent(value) {
  83. if (value) {
  84. createEvent(name: "motion", value: "active", descriptionText: "$device.displayName detected motion")
  85. } else {
  86. createEvent(name: "motion", value: "inactive", descriptionText: "$device.displayName motion has stopped")
  87. }
  88. }
  89. def zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd)
  90. {
  91. sensorValueEvent(cmd.value)
  92. }
  93. def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd)
  94. {
  95. sensorValueEvent(cmd.value)
  96. }
  97. def zwaveEvent(hubitat.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd)
  98. {
  99. sensorValueEvent(cmd.value)
  100. }
  101. def zwaveEvent(hubitat.zwave.commands.sensorbinaryv1.SensorBinaryReport cmd)
  102. {
  103. sensorValueEvent(cmd.sensorValue)
  104. }
  105. def zwaveEvent(hubitat.zwave.commands.sensoralarmv1.SensorAlarmReport cmd)
  106. {
  107. sensorValueEvent(cmd.sensorState)
  108. }
  109. def zwaveEvent(hubitat.zwave.commands.notificationv3.NotificationReport cmd)
  110. {
  111. def result = []
  112. if (cmd.notificationType == 0x07) {
  113. if (cmd.v1AlarmType == 0x07) { // special case for nonstandard messages from Monoprice ensors
  114. result << sensorValueEvent(cmd.v1AlarmLevel)
  115. } else if (cmd.event == 0x01 || cmd.event == 0x02 || cmd.event == 0x07 || cmd.event == 0x08) {
  116. result << sensorValueEvent(1)
  117. } else if (cmd.event == 0x00) {
  118. result << sensorValueEvent(0)
  119. } else if (cmd.event == 0x03) {
  120. result << createEvent(name: "tamper", value: "detected", descriptionText: "$device.displayName covering was removed", isStateChange: true)
  121. result << response(zwave.batteryV1.batteryGet())
  122. } else if (cmd.event == 0x05 || cmd.event == 0x06) {
  123. result << createEvent(descriptionText: "$device.displayName detected glass breakage", isStateChange: true)
  124. }
  125. } else if (cmd.notificationType) {
  126. def text = "Notification $cmd.notificationType: event ${([cmd.event] + cmd.eventParameter).join(", ")}"
  127. result << createEvent(name: "notification$cmd.notificationType", value: "$cmd.event", descriptionText: text, isStateChange: true, displayed: false)
  128. } else {
  129. def value = cmd.v1AlarmLevel == 255 ? "active" : cmd.v1AlarmLevel ?: "inactive"
  130. result << createEvent(name: "alarm $cmd.v1AlarmType", value: value, isStateChange: true, displayed: false)
  131. }
  132. result
  133. }
  134. def zwaveEvent(hubitat.zwave.commands.wakeupv1.WakeUpNotification cmd)
  135. {
  136. def result = [createEvent(descriptionText: "${device.displayName} woke up", isStateChange: false)]
  137.  
  138. if (state.MSR == "011A-0601-0901" && device.currentState('motion') == null) { // Enerwave motion doesn't always get the associationSet that the hub sends on join
  139. result << response(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
  140. }
  141. if (!state.lastbat || (new Date().time) - state.lastbat > 53*60*60*1000) {
  142. result << response(zwave.batteryV1.batteryGet())
  143. } else {
  144. result << response(zwave.wakeUpV1.wakeUpNoMoreInformation())
  145. }
  146. result
  147. }
  148. def zwaveEvent(hubitat.zwave.commands.batteryv1.BatteryReport cmd) {
  149. def map = [ name: "battery", unit: "%" ]
  150. if (cmd.batteryLevel == 0xFF) {
  151. map.value = 1
  152. map.descriptionText = "${device.displayName} has a low battery"
  153. map.isStateChange = true
  154. } else {
  155. map.value = cmd.batteryLevel
  156. }
  157. state.lastbat = new Date().time
  158. [createEvent(map), response(zwave.wakeUpV1.wakeUpNoMoreInformation())]
  159. }
  160. def zwaveEvent(hubitat.zwave.commands.sensormultilevelv5.SensorMultilevelReport cmd)
  161. {
  162. def map = [ displayed: true, value: cmd.scaledSensorValue.toString() ]
  163. switch (cmd.sensorType) {
  164. case 1:
  165. map.name = "temperature"
  166. map.unit = cmd.scale == 1 ? "F" : "C"
  167. break;
  168. case 3:
  169. map.name = "illuminance"
  170. map.value = cmd.scaledSensorValue.toInteger().toString()
  171. map.unit = "lux"
  172. break;
  173. case 5:
  174. map.name = "humidity"
  175. map.value = cmd.scaledSensorValue.toInteger().toString()
  176. map.unit = cmd.scale == 0 ? "%" : ""
  177. break;
  178. case 0x1E:
  179. map.name = "loudness"
  180. map.unit = cmd.scale == 1 ? "dBA" : "dB"
  181. break;
  182. }
  183. createEvent(map)
  184. }
  185. def zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
  186. def encapsulatedCommand = cmd.encapsulatedCommand(commandClassVersions)
  187. // log.debug "encapsulated: $encapsulatedCommand"
  188. if (encapsulatedCommand) {
  189. state.sec = 1
  190. zwaveEvent(encapsulatedCommand)
  191. }
  192. }
  193. def zwaveEvent(hubitat.zwave.commands.crc16encapv1.Crc16Encap cmd)
  194. {
  195. // def encapsulatedCommand = cmd.encapsulatedCommand(commandClassVersions)
  196. def version = commandClassVersions[cmd.commandClass as Integer]
  197. def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
  198. def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
  199. if (encapsulatedCommand) {
  200. return zwaveEvent(encapsulatedCommand)
  201. }
  202. }
  203. def zwaveEvent(hubitat.zwave.commands.multichannelv3.MultiChannelCmdEncap cmd) {
  204. def result = null
  205. def encapsulatedCommand = cmd.encapsulatedCommand(commandClassVersions)
  206. log.debug "Command from endpoint ${cmd.sourceEndPoint}: ${encapsulatedCommand}"
  207. if (encapsulatedCommand) {
  208. result = zwaveEvent(encapsulatedCommand)
  209. }
  210. result
  211. }
  212. def zwaveEvent(hubitat.zwave.commands.multicmdv1.MultiCmdEncap cmd) {
  213. log.debug "MultiCmd with $numberOfCommands inner commands"
  214. cmd.encapsulatedCommands(commandClassVersions).collect { encapsulatedCommand ->
  215. zwaveEvent(encapsulatedCommand)
  216. }.flatten()
  217. }
  218. def zwaveEvent(hubitat.zwave.Command cmd) {
  219. createEvent(descriptionText: "$device.displayName: $cmd", displayed: false)
  220. }
  221. def zwaveEvent(hubitat.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
  222. def result = []
  223. def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
  224. log.debug "msr: $msr"
  225. updateDataValue("MSR", msr)
  226. result << createEvent(descriptionText: "$device.displayName MSR: $msr", isStateChange: false)
  227. result
  228. }
  229. def configure() {
  230. def param13 = parameterThirteen ? parameterThirteen as int : 3
  231. def param18 = !parameterEighteen ? 4 : parameterEighteen as int
  232. def param28 = parameterTwentyEight ? 1 : 0
  233. log.info "Sending parameters to device..."
  234. log.info "Sending parameter 13, motion sensitivity: ${param13==1 ? "1=Low" : param13==2 ? "2=Medium" : "3=High"}"
  235. if (param18 < 1 || param18 >255 || (param18 > 60 && param18 != 255)) {
  236. param18 = 255
  237. log.warn "Invalid motion timeout. Using 255 (5 seconds)"
  238. }
  239. def timing = param18==1 ? "Minute" : "Minutes"
  240. log.info "Sending parameter 18, Motion timeout: ${param18==255 ? " 5 Seconds" : param18 + " ${timing}"}"
  241. log.info "Sending parameter 28, LED flash indicator: " + param28 + "${param28==1 ? "=On" : "=Off"}"
  242. delayBetween([
  243. zwave.configurationV1.configurationSet(configurationValue: [param13], parameterNumber: 13, size: 1).format(),
  244. zwave.configurationV1.configurationSet(configurationValue: [param18], parameterNumber: 18, size: 1).format(),
  245. zwave.configurationV1.configurationSet(configurationValue: [param28], parameterNumber: 28, size: 1).format()
  246. ], 500)
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement