Advertisement
Guest User

Untitled

a guest
May 27th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. /**
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  4. * in compliance with the License. You may obtain a copy of the License at:
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License * for the specific language governing permissions and limitations under the License. * 2017 */
  7.  
  8. metadata {
  9. definition(name:"Curtains", namespace:"SmartHomeDB", author:"SmartHomeDB: Ray Zheng") {
  10. capability "Actuator"
  11. capability "Configuration"
  12. capability "Refresh"
  13. //capability "Switch Level"
  14. capability "WindowShade"
  15. capability "Switch"
  16.  
  17. fingerprint deviceId:"0104", inClusters:"0000, 0001, 0005, 0004, 0102", outClusters:"0019", manufacturer:"SmartHomeDB", model:"093199ff04984948b4c78167c8e7f47e"
  18. }
  19. }
  20.  
  21. command "levelOpenClose"
  22.  
  23. preferences {
  24. input name:"mode", type:"bool", title:"Set SmartHomeDB Curtain Direction", description:"Reverse Mode ON", required:true, displayDuringSetup:true
  25. input name: "debugOutput", type: "bool", title: "<b>Enable debug logging?</b>", description: "<br>", defaultValue: true
  26. }
  27.  
  28. def configure() {
  29. if (debugOutput) log.debug "Configure"
  30. }
  31.  
  32.  
  33. def updated() {
  34. if (debugOutput) runIn(1800,logsOff)
  35. }
  36.  
  37.  
  38. /* Parse incoming device messages to generate events
  39. specification: windowShade - ENUM ["opening", "partially open", "closed", "open", "closing", "unknown"] <-- these are the only
  40. values that attribute "windowShade" may contain
  41. */
  42.  
  43.  
  44. def parse(String description) {
  45.  
  46. def parseMap = zigbee.parseDescriptionAsMap(description)
  47.  
  48. def event = zigbee.getEvent(description)
  49.  
  50. if (debugOutput) log.debug(parseMap)
  51.  
  52. try {
  53.  
  54. if (parseMap.raw.startsWith("0104")) {
  55.  
  56. if (debugOutput) log.debug "Curtain"
  57.  
  58. }else if (parseMap.raw.endsWith("0007")) {
  59.  
  60. if (debugOutput) log.debug "running…"
  61.  
  62. }else if (parseMap.endpoint.endsWith("01")) {
  63.  
  64. if (parseMap["cluster"] == "0102" && parseMap["attrId"] == "0008") {
  65.  
  66.  
  67.  
  68. long theValue = Long.parseLong(parseMap["value"], 16)
  69.  
  70. def eventStack = []
  71.  
  72. if (debugOutput) log.debug(theValue)
  73. if (debugOutput) log.debug(mode)
  74. if (mode == true) {
  75.  
  76. if (theValue > 95) {
  77. if (debugOutput) log.debug "Just Closed"
  78.  
  79. eventStack.push(createEvent(name:"windowShade", value:"closed"))
  80.  
  81. }else if (theValue < 5) {
  82.  
  83. if (debugOutput) log.debug "Just Fully Open"
  84.  
  85. eventStack.push(createEvent(name:"windowShade", value:"open"))
  86.  
  87. }else {
  88. if (debugOutput) log.debug "Motion"
  89. eventStack.push(createEvent(name:"windowShade", value:"unknown"))
  90.  
  91. }
  92.  
  93. }
  94.  
  95. else {
  96.  
  97. if (theValue < 5) {
  98.  
  99. if (debugOutput) log.debug "Just Fully Open mode null"
  100.  
  101. eventStack.push(createEvent(name:"windowShade", value:"open"))
  102.  
  103. }else if (theValue > 95) {
  104.  
  105. if (debugOutput) log.debug "Just Closed mode null"
  106.  
  107. eventStack.push(createEvent(name:"windowShade", value:"closed"))
  108.  
  109.  
  110. }else {
  111.  
  112. if (debugOutput) log.debug "In Motion"
  113. eventStack.push(createEvent(name:"windowShade", value:"unknown"))
  114.  
  115. }
  116.  
  117. }
  118.  
  119. return eventStack
  120.  
  121. }
  122.  
  123. }else {
  124.  
  125. if (debugOutput) log.debug "Unhandled Event - description:${description}, parseMap:${parseMap}, event:${event}"
  126.  
  127. }
  128.  
  129.  
  130.  
  131. if (event["name"] == "switch") {
  132.  
  133. if (debugOutput) log.debug("add event: ${event}")
  134.  
  135. return createEvent(name:"switch", value:event["value"])
  136.  
  137. }
  138.  
  139. }catch (Exception e) {
  140.  
  141. log.warn e
  142.  
  143. }
  144.  
  145. }
  146.  
  147.  
  148.  
  149. def off() { close() }
  150. def close() {
  151.  
  152. if (debugOutput) log.debug "Set Close"
  153.  
  154. if (mode == true) {
  155.  
  156. zigbee.command(0x0102, 0x00)
  157.  
  158. }else {
  159.  
  160. zigbee.command(0x0102, 0x01)
  161.  
  162. }
  163.  
  164. }
  165.  
  166.  
  167.  
  168. def on() { open() }
  169. def open() {
  170.  
  171. if (debugOutput) log.debug "Set Open"
  172.  
  173. if (mode == true) {
  174.  
  175. zigbee.command(0x0102, 0x01)
  176.  
  177. }else {
  178.  
  179. zigbee.command(0x0102, 0x00)
  180.  
  181. }
  182.  
  183. }
  184.  
  185.  
  186. def setPosition(val) {
  187. if (debugOutput) log.debug "unImplemented: Set Position $val %"
  188. }
  189.  
  190. def levelOpenClose(val) {
  191. if (debugOutput) log.debug "unImplemented: Set Level Open/Close"
  192. }
  193.  
  194. def refresh() {
  195.  
  196. if (debugOutput) log.debug "refresh()"
  197.  
  198. zigbee.command(0x0102, 0x02)
  199. }
  200.  
  201.  
  202. def logsOff(){
  203. log.warn "debug logging disabled..."
  204. device.updateSetting("debugOutput",[value:"false",type:"bool"])
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement