Advertisement
Guest User

statusbits x10 switch

a guest
Nov 5th, 2015
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. /**
  2. * X10 Switch.
  3. *
  4. * SmartDevice type for X10 switches and dimmers.
  5. * Visit https://github.com/statusbits/smartthings/blob/master/X10Bridge for
  6. * more information.
  7. *
  8. * Copyright (c) 2014 geko@statusbits.com
  9. *
  10. * This program is free software: you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation, either version 3 of the License, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. * for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * The latest version of this file can be found at:
  24. * https://github.com/statusbits/smartthings/blob/master/X10Bridge/X10_Switch.device.groovy
  25. *
  26. * Revision History
  27. * ----------------
  28. * 2014-09-05 V1.0.0 Released into SmartThings community.
  29. * 2014-08-30 V0.9.0 Initial check-in.
  30. */
  31. metadata {
  32. definition (name:"X10 Switch", namespace:"statusbits", author:"geko@statusbits.com") {
  33. capability "Actuator"
  34. capability "Switch"
  35. capability "Refresh"
  36. // custom attributes
  37. attribute "networkId", "string"
  38. // custom commands
  39. command "parse" // (String "<attribute>:<value>[,<attribute>:<value>]")
  40. command "dim" // Sends X10 Dim command
  41. command "bright" // Sends X10 Bright command
  42. }
  43. tiles {
  44. standardTile("switch", "device.switch", width:2, height:2, canChangeIcon:true) {
  45. state "off", label:'Off', icon:"st.switches.switch.off", backgroundColor:"#ffffff",
  46. action:"switch.on" //, nextState:"on"
  47. state "on", label:'On', icon:"st.switches.switch.on", backgroundColor:"#79b821",
  48. action:"switch.off" //, nextState:"off"
  49. }
  50. standardTile("bright", "device.switch", inactiveLabel:false, decoration:"flat") {
  51. state "default", label:'Bright', icon:"st.custom.buttons.add-icon",
  52. action:"bright"
  53. }
  54. standardTile("dim", "device.switch", inactiveLabel:false, decoration:"flat") {
  55. state "default", label:'Dim', icon:"st.custom.buttons.subtract-icon",
  56. action:"dim"
  57. }
  58. valueTile("networkId", "device.networkId", decoration:"flat", inactiveLabel:false) {
  59. state "default", label:'${currentValue}', inactiveLabel:false
  60. }
  61. standardTile("debug", "device.motion", inactiveLabel: false, decoration: "flat") {
  62. state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
  63. }
  64. main(["switch"])
  65. details(["switch", "bright", "dim", "networkId", "debug"])
  66. simulator {
  67. // status messages
  68. status "Switch On": "switch:1"
  69. status "Switch Off": "switch:0"
  70. }
  71. }
  72. }
  73. def parse(String message) {
  74. TRACE("parse(${message})")
  75. Map msg = stringToMap(message)
  76. if (msg?.size() == 0) {
  77. log.error "Invalid message: ${message}"
  78. return null
  79. }
  80. if (msg.containsKey("switch")) {
  81. def value = msg.switch.toInteger()
  82. switch (value) {
  83. case 0: off(); break
  84. case 1: on(); break
  85. }
  86. }
  87. STATE()
  88. return null
  89. }
  90. // switch.on() command handler
  91. def on() {
  92. TRACE("on()")
  93. if (parent) {
  94. parent.x10_on(device.deviceNetworkId)
  95. sendEvent(name:"switch", value:"on")
  96. }
  97. }
  98. // switch.off() command handler
  99. def off() {
  100. TRACE("off()")
  101. if (parent) {
  102. parent.x10_off(device.deviceNetworkId)
  103. sendEvent(name:"switch", value:"off")
  104. }
  105. }
  106. // Custom dim() command handler
  107. def dim() {
  108. TRACE("dim()")
  109. if (parent) {
  110. parent.x10_dim(device.deviceNetworkId)
  111. }
  112. }
  113. // Custom bright() command handler
  114. def bright() {
  115. TRACE("bright()")
  116. if (parent) {
  117. parent.x10_bright(device.deviceNetworkId)
  118. }
  119. }
  120. // refresh.refresh() command handler
  121. def refresh() {
  122. TRACE("refresh()")
  123. // update device network ID
  124. sendEvent(name:"networkId", value:device.deviceNetworkId)
  125. STATE()
  126. }
  127. private def TRACE(message) {
  128. //log.debug message
  129. }
  130. private def STATE() {
  131. //log.debug "switch is ${device.currentValue("switch")}"
  132. //log.debug "deviceNetworkId: ${device.deviceNetworkId}"
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement