Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.33 KB | None | 0 0
  1. /**
  2. * Aqara Wireless Smart Light Switch models WXKG02LM / WXKG03LM (2016 & 2018 revisions)
  3. * Device Handler for SmartThings
  4. * Version 0.9.2
  5. *
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  8. * in compliance with the License. You may obtain a copy of the License at:
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  13. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing permissions and limitations under the License.
  15. *
  16. * Based on original device handler code by a4refillpad, adapted by bspranger, then rewritten and updated for changes in firmware 25.20 by veeceeoh
  17. * Additional contributions to code by alecm, alixjg, bspranger, gn0st1c, foz333, jmagnuson, rinkek, ronvandegraaf, snalee, tmleafs, twonk, veeceeoh, & xtianpaiva
  18. *
  19. * Notes on capabilities of the different models:
  20. * Model WXKG03LM (1 button) - 2016 Revision (lumi.sensor_86sw1lu):
  21. * - Single press results in "button 1 pushed" event
  22. * Model WXKG03LM (1 button) - 2018 Revision (lumi.remote.b186acn01):
  23. * - Single press results in "button 1 pushed" event
  24. * - Double click results in "button 2 pushed" event
  25. * - Hold for longer than 400ms results in "button 1 held" event
  26. * Model WXKG02LM (2 button) - 2016 Revision (lumi.sensor_86sw2Un):
  27. * + If using firmware version 24.x or older:
  28. * - Press of left, right, or both all result in "button 1 pushed" event
  29. * + If using firmware version 25.20 or newer:
  30. * - Press of left button results in "button 1 pushed" event
  31. * - Press of right button results in "button 2 pushed" event
  32. * - Press of both buttons results in "button 3 pushed" event
  33. * Model WXKG02LM (2 button) - 2018 Revision (lumi.remote.b286acn01):
  34. * - Single press of left/right/both button(s) results in button 1/2/3 "pushed" event
  35. * - Double click of left/right/both button(s) results in button 3/4/5 "pushed" event
  36. * - Hold of left/right/both button(s) for longer than 400ms results in button 1/2/3 "held" event
  37. * Details of 2018 revision button press ZigBee messages:
  38. * Cluster 0012 (Multistate Input), Attribute 0055
  39. * Endpoint 1 = left, 2 = right, 3 = both
  40. * Value 0 = hold, 1 = single, 2 = double
  41. *
  42. * Known issues:
  43. * - As of March 2019, the SmartThings Samsung Connect mobile app does NOT support custom device handlers such as this one
  44. * - The SmartThings Classic mobile app UI text/graphics is rendered differently on iOS vs Android devices - This is due to SmartThings, not this device handler
  45. * - Pairing Xiaomi/Aqara devices can be difficult as they were not designed to use with a SmartThings hub.
  46. * - The battery level is not reported at pairing. Wait for the first status report, 50-60 minutes after pairing.
  47. * - Xiaomi devices do not respond to refresh requests
  48. * - Most ZigBee repeater devices (generally mains-powered ZigBee devices) are NOT compatible with Xiaomi/Aqara devices, causing them to drop off the network.
  49. * Only XBee ZigBee modules, the IKEA Tradfri Outlet / Tradfri Bulb, and ST user @iharyadi's custom multi-sensor ZigBee repeater device are confirmed to be compatible.
  50. *
  51. */
  52.  
  53. import groovy.json.JsonOutput
  54. import physicalgraph.zigbee.zcl.DataType
  55.  
  56. metadata {
  57. definition (name: "Xiaomi Aqara Wireless Switch", namespace: "bspranger", author: "bspranger", minHubCoreVersion: "000.022.0002", ocfDeviceType: "x.com.st.d.remotecontroller") {
  58. capability "Battery"
  59. capability "Sensor"
  60. capability "Button"
  61. capability "Holdable Button"
  62. capability "Actuator"
  63. capability "Momentary"
  64. capability "Configuration"
  65. capability "Health Check"
  66.  
  67. attribute "lastCheckin", "string"
  68. attribute "lastCheckinCoRE", "string"
  69. attribute "lastHeld", "string"
  70. attribute "lastHeldCoRE", "string"
  71. attribute "lastPressed", "string"
  72. attribute "lastPressedCoRE", "string"
  73. attribute "lastReleased", "string"
  74. attribute "lastReleasedCoRE", "string"
  75. attribute "batteryRuntime", "string"
  76. attribute "buttonStatus", "enum", ["pushed", "held", "single-clicked", "double-clicked", "shaken", "released"]
  77.  
  78. // Aqara Smart Light Switch - single button - model WXKG03LM (2016 revision)
  79. fingerprint deviceId: "5F01", inClusters: "0000,0003,0019,0012,FFFF", outClusters: "0000,0003,0004,0005,0019,0012,FFFF", manufacturer: "LUMI", model: "lumi.sensor_86sw1lu", deviceJoinName: "Aqara Switch WXKG03LM (2016)"
  80. fingerprint deviceId: "5F01", inClusters: "0000,0003,0019,0012,FFFF", outClusters: "0000,0003,0004,0005,0019,0012,FFFF", manufacturer: "LUMI", model: "lumi.sensor_86sw1", deviceJoinName: "Aqara Switch WXKG03LM (2016)"
  81. // Aqara Smart Light Switch - single button - model WXKG03LM (2018 revision)
  82. fingerprint deviceId: "5F01", inClusters: "0000,0003,0019,0012,FFFF", outClusters: "0000,0003,0004,0005,0019,0012,FFFF", manufacturer: "LUMI", model: "lumi.remote.b186acn01", deviceJoinName: "Aqara Switch WXKG03LM (2018)"
  83. // Aqara Smart Light Switch - dual button - model WXKG02LM (2016 revision)
  84. fingerprint deviceId: "5F01", inClusters: "0000,0003,0019,0012,FFFF", outClusters: "0000,0003,0004,0005,0019,0012,FFFF", manufacturer: "LUMI", model: "lumi.sensor_86sw2Un", deviceJoinName: "Aqara Switch WXKG02LM (2016)"
  85. fingerprint deviceId: "5F01", inClusters: "0000,0003,0019,0012,FFFF", outClusters: "0000,0003,0004,0005,0019,0012,FFFF", manufacturer: "LUMI", model: "lumi.sensor_86sw2", deviceJoinName: "Aqara Switch WXKG02LM (2016)"
  86. // Aqara Smart Light Switch - dual button - model WXKG02LM (2018 revision)
  87. fingerprint deviceId: "5F01", inClusters: "0000,0003,0019,0012,FFFF", outClusters: "0000,0003,0004,0005,0019,0012,FFFF", manufacturer: "LUMI", model: "lumi.remote.b286acn01", deviceJoinName: "Aqara Switch WXKG02LM (2018)"
  88.  
  89. command "resetBatteryRuntime"
  90. }
  91.  
  92. simulator {
  93. status "Press button": "on/off: 0"
  94. status "Release button": "on/off: 1"
  95. }
  96.  
  97. tiles(scale: 2) {
  98. multiAttributeTile(name:"buttonStatus", type: "lighting", width: 6, height: 4, canChangeIcon: false) {
  99. tileAttribute ("device.buttonStatus", key: "PRIMARY_CONTROL") {
  100. attributeState("default", label:'Pushed', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  101. attributeState("pushed", label:'Pushed', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  102. attributeState("held", label:'Held', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  103. attributeState("double-clicked", label:'Double-clicked', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  104. attributeState("leftpushed", label:'Left Pushed', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  105. attributeState("rightpushed", label:'Right Pushed', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  106. attributeState("bothpushed", label:'Both Pushed', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  107. attributeState("leftdouble-clicked", label:'Left Dbl-clicked', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  108. attributeState("rightdouble-clicked", label:'Right Dbl-clicked', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  109. attributeState("bothdouble-clicked", label:'Both Dbl-clicked', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  110. attributeState("leftheld", label:'Left Held', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  111. attributeState("rightheld", label:'Right Held', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  112. attributeState("bothheld", label:'Both Held', backgroundColor:"#00a0dc", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonPushed.png")
  113. attributeState("released", label:'Released', action: "momentary.push", backgroundColor:"#ffffff", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/ButtonReleased.png")
  114. }
  115. tileAttribute("device.lastPressed", key: "SECONDARY_CONTROL") {
  116. attributeState "lastPressed", label:'Last Pressed: ${currentValue}'
  117. }
  118. }
  119. valueTile("battery", "device.battery", decoration: "flat", inactiveLabel: false, width: 2, height: 2) {
  120. state "battery", label:'${currentValue}%', unit:"%", icon:"https://raw.githubusercontent.com/bspranger/Xiaomi/master/images/XiaomiBattery.png",
  121. backgroundColors:[
  122. [value: 10, color: "#bc2323"],
  123. [value: 26, color: "#f1d801"],
  124. [value: 51, color: "#44b621"]
  125. ]
  126. }
  127. valueTile("lastCheckin", "device.lastCheckin", decoration: "flat", inactiveLabel: false, width: 4, height: 1) {
  128. state "lastCheckin", label:'Last Event:\n${currentValue}'
  129. }
  130. valueTile("batteryRuntime", "device.batteryRuntime", inactiveLabel: false, decoration: "flat", width: 4, height: 1) {
  131. state "batteryRuntime", label:'Battery Changed: ${currentValue}'
  132. }
  133. main (["buttonStatus"])
  134. details(["buttonStatus","battery","lastCheckin","batteryRuntime"])
  135. }
  136.  
  137. preferences {
  138. //Date & Time Config
  139. input description: "", type: "paragraph", element: "paragraph", title: "DATE & CLOCK"
  140. input name: "dateformat", type: "enum", title: "Set Date Format\nUS (MDY) - UK (DMY) - Other (YMD)", description: "Date Format", options:["US","UK","Other"]
  141. input name: "clockformat", type: "bool", title: "Use 24 hour clock?"
  142. //Battery Reset Config
  143. input description: "If you have installed a new battery, the toggle below will reset the Changed Battery date to help remember when it was changed.", type: "paragraph", element: "paragraph", title: "CHANGED BATTERY DATE RESET"
  144. input name: "battReset", type: "bool", title: "Battery Changed?"
  145. //Advanced Settings
  146. input description: "Only change the settings below if you know what you're doing.", type: "paragraph", element: "paragraph", title: "ADVANCED SETTINGS"
  147. //Battery Voltage Range
  148. input description: "", type: "paragraph", element: "paragraph", title: "BATTERY VOLTAGE RANGE"
  149. input name: "voltsmax", type: "decimal", title: "Max Volts\nA battery is at 100% at __ volts\nRange 2.8 to 3.4", range: "2.8..3.4", defaultValue: 3
  150. input name: "voltsmin", type: "decimal", title: "Min Volts\nA battery is at 0% (needs replacing) at __ volts\nRange 2.0 to 2.7", range: "2..2.7", defaultValue: 2.5
  151. //Live Logging Message Display Config
  152. input description: "These settings affect the display of messages in the Live Logging tab of the SmartThings IDE.", type: "paragraph", element: "paragraph", title: "LIVE LOGGING"
  153. input name: "infoLogging", type: "bool", title: "Display info log messages?", defaultValue: true
  154. input name: "debugLogging", type: "bool", title: "Display debug log messages?"
  155. }
  156. }
  157.  
  158. //adds functionality to press the center tile as a virtualApp Button
  159. def push() {
  160. def result = mapButtonEvent(0, 1)
  161. displayDebugLog(": Sending event $result")
  162. sendEvent(result)
  163. }
  164.  
  165. // Parse incoming device messages to generate events
  166. def parse(description) {
  167. displayDebugLog(": Parsing '$description'")
  168. def result = [:]
  169.  
  170. // Any report - button press & Battery - results in a lastCheckin event and update to Last Checkin tile
  171. sendEvent(name: "lastCheckin", value: formatDate(), displayed: false)
  172. sendEvent(name: "lastCheckinCoRE", value: now(), displayed: false)
  173.  
  174. // Send message data to appropriate parsing function based on the type of report
  175. if (description?.startsWith('on/off: ')) {
  176. // Hub FW prior to 25.x - Models WXKG02LM/WXKG03LM (original revision) - any press generates button 1 pushed event
  177. state.numButtons = 1
  178. result = mapButtonEvent(1, 1)
  179. } else if (description?.startsWith("read attr")) {
  180. // Parse button messages of other models, or messages on short-press of reset button
  181. result = parseReadAttrMessage(description - "read attr - ")
  182. } else if (description?.startsWith("catchall")) {
  183. // Parse battery level from regular hourly announcement messages
  184. result = parseCatchAllMessage(description)
  185. }
  186. if (result != [:]) {
  187. displayDebugLog(": Creating event $result")
  188. return createEvent(result)
  189. } else
  190. return [:]
  191. }
  192.  
  193. private Map parseReadAttrMessage(String description) {
  194. Map descMap = (description).split(",").inject([:]) {
  195. map, param ->
  196. def nameAndValue = param.split(":")
  197. map += [(nameAndValue[0].trim()):nameAndValue[1].trim()]
  198. }
  199. Map resultMap = [:]
  200. if (descMap.cluster == "0006") {
  201. // Process model WXKG02LM / WXKG03LM (2016 revision) button messages
  202. resultMap = mapButtonEvent(Integer.parseInt(descMap.endpoint,16), 1)
  203. } else if (descMap.cluster == "0012") {
  204. // Process model WXKG02LM / WXKG03LM (2018 revision) button messages
  205. resultMap = mapButtonEvent(Integer.parseInt(descMap.endpoint,16), Integer.parseInt(descMap.value[2..3],16))
  206. } else if (descMap.cluster == "0000" && descMap.attrId == "0005") {
  207. // Process message containing model name and/or battery voltage report
  208. def data = ""
  209. def modelName = ""
  210. def model = descMap.value
  211. if (descMap.value.length() > 45) {
  212. model = descMap.value.split("01FF")[0]
  213. data = descMap.value.split("01FF")[1]
  214. if (data[4..7] == "0121") {
  215. def BatteryVoltage = (Integer.parseInt((data[10..11] + data[8..9]),16))
  216. resultMap = getBatteryResult(BatteryVoltage)
  217. }
  218. }
  219. // Parsing the model name
  220. for (int i = 0; i < model.length(); i+=2) {
  221. def str = model.substring(i, i+2);
  222. def NextChar = (char)Integer.parseInt(str, 16);
  223. modelName = modelName + NextChar
  224. }
  225. displayDebugLog(" reported ZigBee model: $modelName")
  226. }
  227. return resultMap
  228. }
  229.  
  230. // Create map of values to be used for button events
  231. private mapButtonEvent(buttonValue, actionValue) {
  232. // buttonValue (message endpoint) 1 = left, 2 = right, 3 = both (and 0 = virtual app button)
  233. // actionValue (message value) 0 = hold, 1 = push, 2 = double-click (hold & double-click on 2018 revision only)
  234. def whichButtonText = ["Virtual button was", ((state.numButtons < 3) ? "Button was" : "Left button was"), "Right button was", "Both buttons were"]
  235. def statusButton = ["", ((state.numButtons < 3) ? "" : "left"), "right", "both"]
  236. def pressType = ["held", "pushed", "double-clicked"]
  237. def eventType = (actionValue == 0) ? "held" : "pushed"
  238. def lastPressType = (actionValue == 0) ? "Held" : "Pressed"
  239. def buttonNum = (buttonValue == 0 ? 1 : buttonValue) + (actionValue == 2 ? 3 : 0)
  240. def descText = "${whichButtonText[buttonValue]} ${pressType[actionValue]} (Button $buttonNum $eventType)"
  241. sendEvent(name: "buttonStatus", value: "${statusButton[buttonValue]}${pressType[actionValue]}", isStateChange: true, displayed: false)
  242. updateLastPressed(lastPressType)
  243. displayInfoLog(": $descText")
  244. runIn(1, clearButtonStatus)
  245. return [
  246. name: 'button',
  247. value: eventType,
  248. data: [buttonNumber: buttonNum],
  249. descriptionText: descText,
  250. isStateChange: true
  251. ]
  252. }
  253.  
  254. // on any type of button pressed update lastHeld(CoRE), lastPressed(CoRE), or lastReleased(CoRE) to current date/time
  255. def updateLastPressed(pressType) {
  256. displayDebugLog(": Setting Last $pressType to current date/time")
  257. sendEvent(name: "last${pressType}", value: formatDate(), displayed: false)
  258. sendEvent(name: "last${pressType}CoRE", value: now(), displayed: false)
  259. }
  260.  
  261. def clearButtonStatus() {
  262. sendEvent(name: "buttonStatus", value: "released", isStateChange: true, displayed: false)
  263. }
  264.  
  265. // Check catchall for battery voltage data to pass to getBatteryResult for conversion to percentage report
  266. private Map parseCatchAllMessage(String description) {
  267. Map resultMap = [:]
  268. def catchall = zigbee.parse(description)
  269. if (catchall.clusterId == 0x0000) {
  270. def MsgLength = catchall.data.size()
  271. // Xiaomi CatchAll does not have identifiers, first UINT16 is Battery
  272. if ((catchall.data.get(0) == 0x01 || catchall.data.get(0) == 0x02) && (catchall.data.get(1) == 0xFF)) {
  273. for (int i = 4; i < (MsgLength-3); i++) {
  274. if (catchall.data.get(i) == 0x21) { // check the data ID and data type
  275. // next two bytes are the battery voltage
  276. resultMap = getBatteryResult((catchall.data.get(i+2)<<8) + catchall.data.get(i+1))
  277. break
  278. }
  279. }
  280. }
  281. }
  282. return resultMap
  283. }
  284.  
  285. // Convert raw 4 digit integer voltage value into percentage based on minVolts/maxVolts range
  286. private Map getBatteryResult(rawValue) {
  287. // raw voltage is normally supplied as a 4 digit integer that needs to be divided by 1000
  288. // but in the case the final zero is dropped then divide by 100 to get actual voltage value
  289. def rawVolts = rawValue / 1000
  290. def minVolts = voltsmin ? voltsmin : 2.5
  291. def maxVolts = voltsmax ? voltsmax : 3.0
  292. def pct = (rawVolts - minVolts) / (maxVolts - minVolts)
  293. def roundedPct = Math.min(100, Math.round(pct * 100))
  294. def descText = "Battery at ${roundedPct}% (${rawVolts} Volts)"
  295. displayInfoLog(": $descText")
  296. return [
  297. name: 'battery',
  298. value: roundedPct,
  299. unit: "%",
  300. isStateChange:true,
  301. descriptionText : "$device.displayName $descText"
  302. ]
  303. }
  304.  
  305. private def displayDebugLog(message) {
  306. if (debugLogging)
  307. log.debug "${device.displayName}${message}"
  308. }
  309.  
  310. private def displayInfoLog(message) {
  311. if (infoLogging || state.prefsSetCount < 3)
  312. log.info "${device.displayName}${message}"
  313. }
  314.  
  315. //Reset the date displayed in Battery Changed tile to current date
  316. def resetBatteryRuntime(paired) {
  317. def newlyPaired = paired ? " for newly paired sensor" : ""
  318. sendEvent(name: "batteryRuntime", value: formatDate(true))
  319. displayInfoLog(": Setting Battery Changed to current date${newlyPaired}")
  320. }
  321.  
  322. // installed() runs just after a sensor is paired using the "Add a Thing" method in the SmartThings mobile app
  323. def installed() {
  324. state.prefsSetCount = 0
  325. displayInfoLog(": Installing")
  326. checkIntervalEvent("")
  327. }
  328.  
  329. // configure() runs after installed() when a sensor is paired
  330. def configure() {
  331. displayInfoLog(": Configuring")
  332. initialize(true)
  333. checkIntervalEvent("configured")
  334. return
  335. }
  336.  
  337. // updated() will run twice every time user presses save in preference settings page
  338. def updated() {
  339. displayInfoLog(": Updating preference settings")
  340. if (!state.prefsSetCount)
  341. state.prefsSetCount = 1
  342. else if (state.prefsSetCount < 3)
  343. state.prefsSetCount = state.prefsSetCount + 1
  344. initialize(false)
  345. if (battReset){
  346. resetBatteryRuntime()
  347. device.updateSetting("battReset", false)
  348. }
  349. checkIntervalEvent("preferences updated")
  350. displayInfoLog(": Info message logging enabled")
  351. displayDebugLog(": Debug message logging enabled")
  352. }
  353.  
  354. def initialize(newlyPaired) {
  355. sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zigbee", scheme:"untracked"]), displayed: false)
  356. clearButtonStatus()
  357. if (!device.currentState('batteryRuntime')?.value)
  358. resetBatteryRuntime(newlyPaired)
  359. setNumButtons()
  360. }
  361.  
  362. def setNumButtons() {
  363. if (device.getDataValue("model")) {
  364. def modelName = device.getDataValue("model")
  365. def modelText = ""
  366. if (!state.numButtons || state.numButtons == 7) {
  367. if (modelName.startsWith("lumi.sensor_86sw2")) {
  368. modelText = "Wireless Smart Light Switch WXKG02LM - dual button (2016 revision)"
  369. state.numButtons = 3
  370. }
  371. else if (modelName.startsWith("lumi.sensor_86sw1")) {
  372. modelText = "Wireless Smart Light Switch WXKG03LM - single button (2016 revision)"
  373. state.numButtons = 1
  374. }
  375. else if (modelName.startsWith("lumi.remote.b186acn01")) {
  376. modelText = "Wireless Smart Light Switch WXKG03LM - single button (2018 revision)"
  377. state.numButtons = 2
  378. }
  379. else if (modelName.startsWith("lumi.remote.b286acn01")) {
  380. modelText = "Wireless Smart Light Switch WXKG02LM - dual button (2018 revision)"
  381. state.numButtons = 6
  382. }
  383. else {
  384. state.numButtons = 3
  385. }
  386. displayInfoLog(": Model is Aqara $modelText.")
  387. displayInfoLog(": Number of buttons set to ${state.numButtons}.")
  388. sendEvent(name: "numberOfButtons", value: state.numButtons, displayed: false)
  389. device.currentValue("numberOfButtons")?.times {
  390. sendEvent(name: "button", value: "pushed", data: [buttonNumber: it+1], displayed: false)
  391. }
  392. }
  393. }
  394. else {
  395. if (!state.numButtons) {
  396. displayInfoLog(": Model is unknown, so number of buttons is set to default of 6.")
  397. sendEvent(name: "numberOfButtons", value: 6, displayed: false)
  398. state.numButtons = 7
  399. }
  400. }
  401. }
  402.  
  403. private checkIntervalEvent(text) {
  404. // Device wakes up every 1 hours, this interval allows us to miss one wakeup notification before marking offline
  405. if (text)
  406. displayInfoLog(": Set health checkInterval when ${text}")
  407. sendEvent(name: "checkInterval", value: 2 * 60 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
  408. }
  409.  
  410. def formatDate(batteryReset) {
  411. def correctedTimezone = ""
  412. def timeString = clockformat ? "HH:mm:ss" : "h:mm:ss aa"
  413.  
  414. // If user's hub timezone is not set, display error messages in log and events log, and set timezone to GMT to avoid errors
  415. if (!(location.timeZone)) {
  416. correctedTimezone = TimeZone.getTimeZone("GMT")
  417. log.error "${device.displayName}: Time Zone not set, so GMT was used. Please set up your location in the SmartThings mobile app."
  418. sendEvent(name: "error", value: "", descriptionText: "ERROR: Time Zone not set, so GMT was used. Please set up your location in the SmartThings mobile app.")
  419. }
  420. else {
  421. correctedTimezone = location.timeZone
  422. }
  423. if (dateformat == "US" || dateformat == "" || dateformat == null) {
  424. if (batteryReset)
  425. return new Date().format("MMM dd yyyy", correctedTimezone)
  426. else
  427. return new Date().format("EEE MMM dd yyyy ${timeString}", correctedTimezone)
  428. }
  429. else if (dateformat == "UK") {
  430. if (batteryReset)
  431. return new Date().format("dd MMM yyyy", correctedTimezone)
  432. else
  433. return new Date().format("EEE dd MMM yyyy ${timeString}", correctedTimezone)
  434. }
  435. else {
  436. if (batteryReset)
  437. return new Date().format("yyyy MMM dd", correctedTimezone)
  438. else
  439. return new Date().format("EEE yyyy MMM dd ${timeString}", correctedTimezone)
  440. }
  441. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement