Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 10.62 KB | None | 0 0
  1. /**
  2.  *  Copyright 2015 SmartThings
  3.  *
  4.  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5.  *  in compliance with the License. You may obtain a copy of the License at:
  6.  *
  7.  *      http://www.apache.org/licenses/LICENSE-2.0
  8.  *
  9.  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  10.  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  11.  *  for the specific language governing permissions and limitations under the License.
  12.  *
  13.  */
  14. metadata {
  15.     definition (name: "My Dimmer Switch", namespace: "proyash56", author: "proyash", ocfDeviceType: "oic.d.light", runLocally: false, minHubCoreVersion: '000.017.0012', executeCommandsLocally: false) {
  16.         capability "Switch Level"
  17.         capability "Actuator"
  18.         capability "Indicator"
  19.         capability "Switch"
  20.         capability "Refresh"
  21.         capability "Sensor"
  22.         capability "Health Check"
  23.         capability "Light"
  24.  
  25.         fingerprint mfr:"0063", prod:"4457", deviceJoinName: "GE In-Wall Smart Dimmer"
  26.         fingerprint mfr:"0063", prod:"4944", deviceJoinName: "GE In-Wall Smart Dimmer"
  27.         fingerprint mfr:"0063", prod:"5044", deviceJoinName: "GE Plug-In Smart Dimmer"
  28.     }
  29.  
  30.     simulator {
  31.         status "on":  "command: 2003, payload: FF"
  32.         status "off": "command: 2003, payload: 00"
  33.         status "09%": "command: 2003, payload: 09"
  34.         status "10%": "command: 2003, payload: 0A"
  35.         status "33%": "command: 2003, payload: 21"
  36.         status "66%": "command: 2003, payload: 42"
  37.         status "99%": "command: 2003, payload: 63"
  38.  
  39.         // reply messages
  40.         reply "2001FF,delay 5000,2602": "command: 2603, payload: FF"
  41.         reply "200100,delay 5000,2602": "command: 2603, payload: 00"
  42.         reply "200119,delay 5000,2602": "command: 2603, payload: 19"
  43.         reply "200132,delay 5000,2602": "command: 2603, payload: 32"
  44.         reply "20014B,delay 5000,2602": "command: 2603, payload: 4B"
  45.         reply "200163,delay 5000,2602": "command: 2603, payload: 63"
  46.     }
  47.  
  48.     preferences {
  49.         input "ledIndicator", "enum", title: "LED Indicator", description: "Turn LED indicator... ", required: false, options:["on": "When On", "off": "When Off", "never": "Never"], defaultValue: "off"
  50.     }
  51.  
  52.     tiles(scale: 2) {
  53.         multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
  54.             tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
  55.                 attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  56.                 attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
  57.                 attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#00a0dc", nextState:"turningOff"
  58.                 attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
  59.             }
  60.             tileAttribute ("device.level", key: "SLIDER_CONTROL") {
  61.                 attributeState "level", action:"switch level.setLevel"
  62.             }
  63.         }
  64.  
  65.         standardTile("indicator", "device.indicatorStatus", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
  66.             state "when off", action:"indicator.indicatorWhenOn", icon:"st.indicators.lit-when-off"
  67.             state "when on", action:"indicator.indicatorNever", icon:"st.indicators.lit-when-on"
  68.             state "never", action:"indicator.indicatorWhenOff", icon:"st.indicators.never-lit"
  69.         }
  70.  
  71.         standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
  72.             state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
  73.         }
  74.  
  75.         valueTile("level", "device.level", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
  76.             state "level", label:'${currentValue} %', unit:"%", backgroundColor:"#ffffff"
  77.         }
  78.  
  79.         main(["switch"])
  80.         details(["switch", "level", "refresh"])
  81.  
  82.     }
  83. }
  84.  
  85. def installed() {
  86.     // Device-Watch simply pings if no device events received for 32min(checkInterval)
  87.     sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
  88.  
  89.     response(refresh())
  90. }
  91.  
  92. def updated(){
  93.     // Device-Watch simply pings if no device events received for 32min(checkInterval)
  94.     sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
  95.   switch (ledIndicator) {
  96.         case "on":
  97.             indicatorWhenOn()
  98.             break
  99.         case "off":
  100.             indicatorWhenOff()
  101.             break
  102.         case "never":
  103.             indicatorNever()
  104.             break
  105.         default:
  106.             indicatorWhenOn()
  107.             break
  108.     }
  109. }
  110.  
  111. def getCommandClassVersions() {
  112.     [
  113.         0x20: 1,  // Basic
  114.         0x26: 1,  // SwitchMultilevel
  115.         0x56: 1,  // Crc16Encap
  116.         0x70: 1,  // Configuration
  117.     ]
  118. }
  119.  
  120. def parse(String description) {
  121.     def result = null
  122.     if (description != "updated") {
  123.         log.debug "parse() >> zwave.parse($description)"
  124.         def cmd = zwave.parse(description, commandClassVersions)
  125.         if (cmd) {
  126.             result = zwaveEvent(cmd)
  127.         }
  128.     }
  129.     if (result?.name == 'hail' && hubFirmwareLessThan("000.011.00602")) {
  130.         result = [result, response(zwave.basicV1.basicGet())]
  131.         log.debug "Was hailed: requesting state update"
  132.     } else {
  133.         log.debug "Parse returned ${result?.descriptionText}"
  134.     }
  135.     return result
  136. }
  137.  
  138. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
  139.     dimmerEvents(cmd)
  140. }
  141.  
  142. def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
  143.     dimmerEvents(cmd)
  144. }
  145.  
  146. def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelReport cmd) {
  147.     dimmerEvents(cmd)
  148. }
  149.  
  150. def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelSet cmd) {
  151.     dimmerEvents(cmd)
  152. }
  153.  
  154. private dimmerEvents(physicalgraph.zwave.Command cmd) {
  155.     def value = (cmd.value ? "on" : "off")
  156.     def result = [createEvent(name: "switch", value: value)]
  157.     if (cmd.value && cmd.value <= 100) {
  158.         result << createEvent(name: "level", value: cmd.value == 99 ? 100 : cmd.value)
  159.     }
  160.     return result
  161. }
  162.  
  163.  
  164. def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
  165.     log.debug "ConfigurationReport $cmd"
  166.     def value = "when off"
  167.     if (cmd.configurationValue[0] == 1) {value = "when on"}
  168.     if (cmd.configurationValue[0] == 2) {value = "never"}
  169.     createEvent([name: "indicatorStatus", value: value])
  170. }
  171.  
  172. def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
  173.     createEvent([name: "hail", value: "hail", descriptionText: "Switch button was pressed", displayed: false])
  174. }
  175.  
  176. def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
  177.     log.debug "manufacturerId:   ${cmd.manufacturerId}"
  178.     log.debug "manufacturerName: ${cmd.manufacturerName}"
  179.     log.debug "productId:        ${cmd.productId}"
  180.     log.debug "productTypeId:    ${cmd.productTypeId}"
  181.     def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
  182.     updateDataValue("MSR", msr)
  183.     updateDataValue("manufacturer", cmd.manufacturerName)
  184.     createEvent([descriptionText: "$device.displayName MSR: $msr", isStateChange: false])
  185. }
  186.  
  187. def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelStopLevelChange cmd) {
  188.     [createEvent(name:"switch", value:"on"), response(zwave.switchMultilevelV1.switchMultilevelGet().format())]
  189. }
  190.  
  191. def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
  192.     def versions = commandClassVersions
  193.     def version = versions[cmd.commandClass as Integer]
  194.     def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
  195.     def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
  196.     if (encapsulatedCommand) {
  197.         zwaveEvent(encapsulatedCommand)
  198.     }
  199. }
  200.  
  201. def zwaveEvent(physicalgraph.zwave.Command cmd) {
  202.     // Handles all Z-Wave commands we aren't interested in
  203.     [:]
  204. }
  205.  
  206. def on() {
  207.     delayBetween([
  208.             zwave.basicV1.basicSet(value: 0xFF).format(),
  209.             zwave.switchMultilevelV1.switchMultilevelGet().format()
  210.     ],5000)
  211. }
  212.  
  213. def off() {
  214.     delayBetween([
  215.             zwave.basicV1.basicSet(value: 0x00).format(),
  216.             zwave.switchMultilevelV1.switchMultilevelGet().format()
  217.     ],5000)
  218. }
  219.  
  220. def setLevel(value) {
  221.     log.debug "setLevel >> value: $value"
  222.     def valueaux = value as Integer
  223.     def level = Math.max(Math.min(valueaux, 99), 0)
  224.     if (level > 0) {
  225.         sendEvent(name: "switch", value: "on")
  226.     } else {
  227.         sendEvent(name: "switch", value: "off")
  228.     }
  229.     delayBetween ([zwave.basicV1.basicSet(value: level).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 5000)
  230. }
  231.  
  232. def setLevel(value, duration) {
  233.     log.debug "setLevel >> value: $value, duration: $duration"
  234.     def valueaux = value as Integer
  235.     def level = Math.max(Math.min(valueaux, 99), 0)
  236.     def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
  237.     def getStatusDelay = duration < 128 ? (duration*1000)+2000 : (Math.round(duration / 60)*60*1000)+2000
  238.     delayBetween ([zwave.switchMultilevelV2.switchMultilevelSet(value: level, dimmingDuration: dimmingDuration).format(),
  239.                    zwave.switchMultilevelV1.switchMultilevelGet().format()], getStatusDelay)
  240. }
  241.  
  242. /**
  243.  * PING is used by Device-Watch in attempt to reach the Device
  244.  * */
  245. def ping() {
  246.     refresh()
  247. }
  248.  
  249. def refresh() {
  250.     log.debug "refresh() is called"
  251.     def commands = []
  252.     commands << zwave.switchMultilevelV1.switchMultilevelGet().format()
  253.     if (getDataValue("MSR") == null) {
  254.         commands << zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
  255.     }
  256.     delayBetween(commands,100)
  257. }
  258.  
  259. void indicatorWhenOn() {
  260.     sendEvent(name: "indicatorStatus", value: "when on", displayed: false)
  261.     sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()))
  262. }
  263.  
  264. void indicatorWhenOff() {
  265.     sendEvent(name: "indicatorStatus", value: "when off", displayed: false)
  266.     sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()))
  267. }
  268.  
  269. void indicatorNever() {
  270.     sendEvent(name: "indicatorStatus", value: "never", displayed: false)
  271.     sendHubCommand(new physicalgraph.device.HubAction(zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()))
  272. }
  273.  
  274. def invertSwitch(invert=true) {
  275.     if (invert) {
  276.         zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()
  277.     }
  278.     else {
  279.         zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()
  280.     }
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement