Advertisement
erocm123

Monoprice 11990 Dual Relay Module

Dec 18th, 2018
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. /**
  2. *
  3. * Monoprice 11990 Dual Relay Module
  4. *
  5. * Copyright 2015 Justin Ellison
  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. * Device Type supporting all the feautres of the Monoprice device including both switches, with real-time status
  17. * of both switch 1 and 2.
  18. *
  19. * Special thanks to Eric Maycock for doing the bulk of the work with the Philio PAN04 module, without his work
  20. * this device type wouldn't exist.
  21. *
  22. */
  23.  
  24.  
  25. preferences {
  26. input ("delayMillis", "number", title: "Command delay in ms",
  27. description: "Time in milliseconds to delay sending multiple commands.", defaultValue: 0,
  28. required: false, range: "0..5000")
  29. }
  30.  
  31. metadata {
  32. definition (name: "Monoprice 11990 Dual Relay Module", namespace: "justintime", author: "Justin Ellison") {
  33. capability "Polling"
  34. capability "Refresh"
  35. capability "Switch"
  36.  
  37. attribute "switch1", "string"
  38. attribute "switch2", "string"
  39.  
  40. command "on1"
  41. command "off1"
  42. command "on2"
  43. command "off2"
  44.  
  45. fingerprint deviceId: "0x1001", inClusters: "0x5E, 0x86, 0x72, 0x5A, 0x85, 0x59, 0x73, 0x25, 0x20, 0x27, 0x71, 0x2B, 0x2C, 0x75, 0x7A, 0x60, 0x32, 0x70"
  46. }
  47.  
  48. simulator {
  49. status "on": "command: 2003, payload: FF"
  50. status "off": "command: 2003, payload: 00"
  51.  
  52. reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
  53. reply "200100,delay 100,2502": "command: 2503, payload: 00"
  54. }
  55.  
  56. tiles {
  57. standardTile("switch1", "device.switch1",canChangeIcon: true) {
  58. state "on", label: "switch1", action: "off1", icon: "st.switches.switch.on", backgroundColor: "#79b821"
  59. state "off", label: "switch1", action: "on1", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
  60. }
  61. standardTile("switch2", "device.switch2",canChangeIcon: true) {
  62. state "on", label: "switch2", action: "off2", icon: "st.switches.switch.on", backgroundColor: "#79b821"
  63. state "off", label: "switch2", action: "on2", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
  64. }
  65. standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
  66. state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
  67. }
  68.  
  69. main(["switch1", "switch2"])
  70. details(["switch1","switch2","refresh"])
  71. }
  72. }
  73.  
  74. def parse(String description) {
  75. log.debug "Parsing '${description}'"
  76. def result = []
  77. def cmd = zwave.parse(description)
  78. if (cmd) {
  79. result += zwaveEvent(cmd)
  80. log.debug "Parsed ${cmd} to ${result.inspect()}"
  81. } else {
  82. log.debug "Non-parsed event: ${description}"
  83. }
  84. return result
  85. }
  86.  
  87. def zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd) {
  88. def result
  89. if (cmd.value == 0) {
  90. result = createEvent(name: "switch", value: "off")
  91. } else {
  92. result = createEvent(name: "switch", value: "on")
  93. }
  94. return result
  95. }
  96.  
  97. def zwaveEvent(hubitat.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
  98. sendEvent(name: "switch", value: cmd.value ? "on" : "off", type: "digital")
  99. def result = []
  100. result << zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:1, commandClass:37, command:2).format()
  101. result << zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:2, commandClass:37, command:2).format()
  102. response(delayBetween(result, settings.delayMillis)) // returns the result of reponse()
  103. }
  104.  
  105. def zwaveEvent(hubitat.zwave.commands.multichannelv3.MultiChannelCapabilityReport cmd) {
  106. log.debug "multichannelv3.MultiChannelCapabilityReport $cmd"
  107. if (cmd.endPoint == 2 ) {
  108. def currstate = device.currentState("switch2").getValue()
  109. if (currstate == "on")
  110. sendEvent(name: "switch2", value: "off", isStateChange: true, display: false)
  111. else if (currstate == "off")
  112. sendEvent(name: "switch2", value: "on", isStateChange: true, display: false)
  113. }
  114. else if (cmd.endPoint == 1 ) {
  115. def currstate = device.currentState("switch1").getValue()
  116. if (currstate == "on")
  117. sendEvent(name: "switch1", value: "off", isStateChange: true, display: false)
  118. else if (currstate == "off")
  119. sendEvent(name: "switch1", value: "on", isStateChange: true, display: false)
  120. }
  121. }
  122.  
  123. def zwaveEvent(hubitat.zwave.commands.multichannelv3.MultiChannelCmdEncap cmd) {
  124. def map = [ name: "switch$cmd.sourceEndPoint" ]
  125.  
  126. if (cmd.commandClass == 37){
  127. if (cmd.parameter == [0]) {
  128. map.value = "off"
  129. }
  130. if (cmd.parameter == [255]) {
  131. map.value = "on"
  132. }
  133. createEvent(map)
  134. }
  135. }
  136.  
  137. def zwaveEvent(hubitat.zwave.Command cmd) {
  138. // This will capture any commands not handled by other instances of zwaveEvent
  139. // and is recommended for development so you can see every command the device sends
  140. return createEvent(descriptionText: "${device.displayName}: ${cmd}")
  141. }
  142.  
  143. def refresh() {
  144. log.debug "Executing 'refresh'"
  145. def cmds = []
  146. cmds << zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:1, commandClass:37, command:2).format()
  147. cmds << zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:2, commandClass:37, command:2).format()
  148. delayBetween(cmds, settings.delayMillis)
  149. }
  150.  
  151. def poll() {
  152. log.debug "Executing 'poll'"
  153. delayBetween([
  154. zwave.switchBinaryV1.switchBinaryGet().format(),
  155. zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
  156. ], settings.delayMillis)
  157. }
  158.  
  159. def on1() {
  160. log.debug "Executing 'on1' with delay of ${settings.delayMillis}"
  161. delayBetween([
  162. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:1, commandClass:37, command:1, parameter:[255]).format(),
  163. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:1, commandClass:37, command:2).format()
  164. ], settings.delayMillis)
  165. }
  166.  
  167. def off1() {
  168. log.debug "Executing 'off1'"
  169. delayBetween([
  170. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:1, commandClass:37, command:1, parameter:[0]).format(),
  171. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:1, destinationEndPoint:1, commandClass:37, command:2).format()
  172. ], settings.delayMillis)
  173. }
  174.  
  175. def on2() {
  176. log.debug "Executing 'on2'"
  177. delayBetween([
  178. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:2, destinationEndPoint:2, commandClass:37, command:1, parameter:[255]).format(),
  179. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:2, destinationEndPoint:2, commandClass:37, command:2).format()
  180. ], settings.delayMillis)
  181. }
  182.  
  183. def off2() {
  184. log.debug "Executing 'off2'"
  185. delayBetween([
  186. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:2, destinationEndPoint:2, commandClass:37, command:1, parameter:[0]).format(),
  187. zwave.multiChannelV3.multiChannelCmdEncap(sourceEndPoint:2, destinationEndPoint:2, commandClass:37, command:2).format()
  188. ], settings.delayMillis)
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement