Advertisement
Guest User

Untitled

a guest
Jan 15th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.57 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
  7. *
  8. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  9. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  10. * for the specific language governing permissions and limitations under the License.
  11. *
  12. * Based on on original by Lazcad / RaveTam
  13. * Mods for Hui 3 Gang Switch by Netsheriff
  14. */
  15.  
  16. metadata {
  17. definition (name: "HUI ZigBee Wall Switch 3 Gang V.3.0", namespace: "", author: "smartthings") {
  18. capability "Actuator"
  19. capability "Configuration"
  20. capability "Refresh"
  21. capability "Switch"
  22. capability "Health Check"
  23.  
  24.  
  25. fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006"
  26. fingerprint profileId: "0104", inClusters: "0000, 0003, 0006", outClusters: "0003, 0006, 0019, 0406", manufacturer: "Leviton", model: "ZSS-10", deviceJoinName: "Leviton Switch"
  27. fingerprint profileId: "0104", inClusters: "0000, 0003, 0006", outClusters: "000A", manufacturer: "HAI", model: "65A21-1", deviceJoinName: "Leviton Wireless Load Control Module-30amp"
  28. fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006", outClusters: "0003, 0006, 0008, 0019, 0406", manufacturer: "Leviton", model: "DL15A", deviceJoinName: "Leviton Lumina RF Plug-In Appliance Module"
  29. fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006", outClusters: "0003, 0006, 0008, 0019, 0406", manufacturer: "Leviton", model: "DL15S", deviceJoinName: "Leviton Lumina RF Switch"
  30.  
  31.  
  32.  
  33. attribute "lastCheckin", "string"
  34. attribute "switch", "string"
  35. attribute "switch1", "string"
  36. attribute "switch2", "string"
  37. attribute "switch3", "string"
  38. command "on0"
  39. command "off0"
  40. command "on"
  41. command "off"
  42. command "on2"
  43. command "off2"
  44. command "on3"
  45. command "off3"
  46.  
  47.  
  48.  
  49. attribute "switch1","ENUM",["on","off"]
  50. attribute "switch2","ENUM",["on","off"]
  51. attribute "switch3","ENUM",["on","off"]
  52. attribute "switchstate","ENUM",["on","off"]
  53.  
  54. }
  55.  
  56. // simulator metadata
  57. simulator {
  58. // status messages
  59. status "on": "on/off: 1"
  60. status "off": "on/off: 0"
  61.  
  62.  
  63. status "switch1 on": "on/off: 1"
  64. status "switch1 off": "on/off: 0"
  65. status "switch2 on": "on/off: 1"
  66. status "switch2 off": "on/off: 0"
  67. status "switch3 on": "on/off: 1"
  68. status "switch3 off": "on/off: 0"
  69.  
  70. // reply messages
  71. reply "zcl on-off on": "on/off: 1"
  72. reply "zcl on-off off": "on/off: 0"
  73.  
  74.  
  75. }
  76.  
  77. tiles(scale: 1) {
  78. multiAttributeTile(name:"switch", type: "device.switch", width: 1, height: 1, canChangeIcon: true){
  79. tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
  80. attributeState "on", label:'${name}', action:"off0", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  81. attributeState "off", label:'${name}', action:"on0", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  82. attributeState "turningOn", label:'${name}', action:"off0", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  83. attributeState "turningOff", label:'${name}', action:"on0", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  84. }
  85. tileAttribute("device.lastCheckin", key: "SECONDARY_CONTROL") {
  86. attributeState("default", label:'Last Update: ${currentValue}',icon: "st.Health & Wellness.health9")
  87. }
  88. }
  89. multiAttributeTile(name:"switch1", type: "device.switch", width: 1, height: 1, canChangeIcon: true){
  90. tileAttribute ("device.switch1", key: "PRIMARY_CONTROL") {
  91. attributeState "on", label:'SW1 On', action:"off", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  92. attributeState "off", label:'SW1 Off', action:"on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  93. attributeState "turningOn", label:'Turning On', action:"off", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  94. attributeState "turningOff", label:'Turning Off', action:"on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  95. }
  96. tileAttribute("device.lastCheckin", key: "SECONDARY_CONTROL") {
  97. attributeState("default", label:'Last Update: ${currentValue}',icon: "st.Health & Wellness.health9")
  98. }
  99. }
  100.  
  101.  
  102. multiAttributeTile(name:"switch2", type: "device.switch", width: 1, height: 1, canChangeIcon: true){
  103. tileAttribute ("device.switch2", key: "PRIMARY_CONTROL") {
  104. attributeState "on", label:'SW2 On', action:"off2", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  105. attributeState "off", label:'SW2 Off', action:"on2", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  106. attributeState "turningOn", label:'Turning On', action:"off2", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  107. attributeState "turningOff", label:'Turning Off', action:"on2", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  108. }
  109. tileAttribute("device.lastCheckin", key: "SECONDARY_CONTROL") {
  110. attributeState("default", label:'Last Update: ${currentValue}',icon: "st.Health & Wellness.health9")
  111. }
  112. }
  113. //
  114. multiAttributeTile(name:"switch3", type: "device.switch", width: 1, height: 1, canChangeIcon: true){
  115. tileAttribute ("device.switch3", key: "PRIMARY_CONTROL") {
  116. attributeState "on", label:'SW3 On', action:"off3", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  117. attributeState "off", label:'SW3 Off', action:"on3", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  118. attributeState "turningOn", label:'Turning On', action:"off3", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  119. attributeState "turningOff", label:'Turning Off', action:"on3", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
  120. }
  121. tileAttribute("device.lastCheckin", key: "SECONDARY_CONTROL") {
  122. attributeState("default", label:'Last Update: ${currentValue}',icon: "st.Health & Wellness.health9")
  123. }
  124. }
  125.  
  126. //
  127. standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 1, height: 1) {
  128. state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
  129. }
  130. main(["switch"])
  131. details(["switch1","switch2","switch3", "refresh"])
  132. }
  133. }
  134.  
  135. // Parse incoming device messages to generate events
  136.  
  137. def parse(String description) {
  138. log.debug "Parsing '${description}'"
  139.  
  140. def value = zigbee.parse(description)?.text
  141. log.debug "Parse: $value"
  142. Map map = [:]
  143.  
  144. if (description?.startsWith('catchall:')) {
  145. map = parseCatchAllMessage(description)
  146. }
  147. else if (description?.startsWith('read attr -')) {
  148. map = parseReportAttributeMessage(description)
  149. }
  150. else if (description?.startsWith('on/off: ')){
  151. log.debug "onoff"
  152. def refreshCmds = zigbee.readAttribute(0x0006, 0x0000, [destEndpoint: 0x10]) +
  153. zigbee.readAttribute(0x0006, 0x0000, [destEndpoint: 0x11]) +
  154.  
  155. zigbee.readAttribute(0x0006, 0x0000, [destEndpoint: 0x12])
  156.  
  157. return refreshCmds.collect { new physicalgraph.device.HubAction(it) }
  158. //def resultMap = zigbee.getKnownDescription(description)
  159. //log.debug "${resultMap}"
  160.  
  161. //map = parseCustomMessage(description)
  162. }
  163.  
  164. log.debug "Parse returned $map"
  165. // send event for heartbeat
  166. def now = new Date()
  167.  
  168. sendEvent(name: "lastCheckin", value: now)
  169.  
  170. def results = map ? createEvent(map) : null
  171. return results;
  172. }
  173.  
  174. private Map parseCatchAllMessage(String description) {
  175. Map resultMap = [:]
  176. def cluster = zigbee.parse(description)
  177. log.debug cluster
  178.  
  179. if (cluster.clusterId == 0x0006 && cluster.command == 0x01){
  180. if (cluster.sourceEndpoint == 0x10)
  181. {
  182. log.debug "Its Switch one"
  183. def onoff = cluster.data[-1]
  184. if (onoff == 1)
  185. resultMap = createEvent(name: "switch", value: "on")
  186. else if (onoff == 0)
  187. resultMap = createEvent(name: "switch", value: "off")
  188. }
  189. else if (cluster.sourceEndpoint == 0x11)
  190. {
  191. log.debug "Its Switch two"
  192. def onoff = cluster.data[-1]
  193. if (onoff == 1)
  194. resultMap = createEvent(name: "switch2", value: "on")
  195. else if (onoff == 0)
  196. resultMap = createEvent(name: "switch2", value: "off")
  197. }
  198.  
  199. //
  200.  
  201. else if (cluster.sourceEndpoint == 0x12)
  202. {
  203. log.debug "Its Switch three"
  204. def onoff = cluster.data[-1]
  205. if (onoff == 1)
  206. resultMap = createEvent(name: "switch3", value: "on")
  207. else if (onoff == 0)
  208. resultMap = createEvent(name: "switch3", value: "off")
  209. }
  210. //
  211. }
  212.  
  213. return resultMap
  214. }
  215.  
  216. def off() {
  217. log.debug "off()"
  218. sendEvent(name: "switch1", value: "off")
  219. "st cmd 0x${device.deviceNetworkId} 0x10 0x0006 0x0 {}"
  220. }
  221.  
  222. def on() {
  223. log.debug "on()"
  224. sendEvent(name: "switch1", value: "on")
  225. "st cmd 0x${device.deviceNetworkId} 0x10 0x0006 0x1 {}"
  226. }
  227. def off2() {
  228. log.debug "off2()"
  229. sendEvent(name: "switch2", value: "off")
  230. "st cmd 0x${device.deviceNetworkId} 0x11 0x0006 0x0 {}"
  231. }
  232.  
  233. def on2() {
  234. log.debug "on2()"
  235. sendEvent(name: "switch2", value: "on")
  236. "st cmd 0x${device.deviceNetworkId} 0x11 0x0006 0x1 {}"
  237. }
  238.  
  239. //
  240. def off3() {
  241. log.debug "off3()"
  242. sendEvent(name: "switch3", value: "off")
  243. "st cmd 0x${device.deviceNetworkId} 0x12 0x0006 0x0 {}"
  244. }
  245.  
  246. def on3() {
  247. log.debug "on3()"
  248. sendEvent(name: "switch3", value: "on")
  249. "st cmd 0x${device.deviceNetworkId} 0x12 0x0006 0x1 {}"
  250. }
  251.  
  252. //
  253.  
  254. def off0() {
  255. log.debug "off0()"
  256. sendEvent(name: "switch", value: "off")
  257. "st cmd 0x${device.deviceNetworkId} 0xFF 0x0006 0x0 {}"
  258.  
  259. }
  260.  
  261. def on0() {
  262. log.debug "on0()"
  263. sendEvent(name: "switch", value: "on")
  264. "st cmd 0x${device.deviceNetworkId} 0xFF 0x0006 0x1 {}"
  265.  
  266. }
  267. def refresh() {
  268. log.debug "refreshing"
  269. [
  270. "st rattr 0x${device.deviceNetworkId} 0x10 0x0006 0x0", "delay 1000",
  271.  
  272. "st rattr 0x${device.deviceNetworkId} 0x11 0x0006 0x0", "delay 1000",
  273.  
  274. "st rattr 0x${device.deviceNetworkId} 0x12 0x0006 0x0", "delay 1000",
  275.  
  276. ]
  277. }
  278.  
  279. private Map parseCustomMessage(String description) {
  280. def result
  281. if (description?.startsWith('on/off: ')) {
  282. if (description == 'on/off: 0')
  283. result = createEvent(name: "switch", value: "off")
  284. else if (description == 'on/off: 1')
  285. result = createEvent(name: "switch", value: "on")
  286. }
  287.  
  288. return result
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement