/** * Virtual Dimmer * * Copyright 2017 Michael Struck * Version 1.1.1a 3/26/17 * * Version 1.0.0 - Initial release * Version 1.1.0 - Updated the interface to better match SmartThings dimmers (thanks to @BoruGee) * Version 1.1.1a - Added sensor/actuator capability, changed copyright date * * Uses code from SmartThings * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at: * * 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. * */ metadata { definition (name: "Virtual Dimmer", namespace: "MichaelStruck", author: "SmartThings") { capability "Switch" capability "Refresh" capability "Switch Level" capability "Actuator" //included to give compatibility with ActionTiles capability "Sensor" //included to give compatibility with ActionTiles } // simulator metadata simulator { } // UI tile definitions tiles(scale: 2) { multiAttributeTile(name: "switch", type: "lighting", width: 6, height: 4, canChangeIcon: true, canChangeBackground: true) { tileAttribute("device.switch", key: "PRIMARY_CONTROL") { attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.light.off", backgroundColor: "#ffffff", nextState: "turningOn" attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.light.on", backgroundColor: "#79b821", nextState: "turningOff" attributeState "turningOff", label: '${name}', action: "switch.on", icon: "st.switches.light.off", backgroundColor: "#ffffff", nextState: "turningOn" attributeState "turningOn", label: '${name}', action: "switch.off", icon: "st.switches.light.on", backgroundColor: "#79b821", nextState: "turningOff" } tileAttribute("device.level", key: "SLIDER_CONTROL") { attributeState "level", action:"switch level.setLevel" } tileAttribute("level", key: "SECONDARY_CONTROL") { attributeState "level", label: 'Light dimmed to ${currentValue}%' } } valueTile("lValue", "device.level", inactiveLabel: true, height:2, width:2, decoration: "flat") { state "levelValue", label:'${currentValue}%', unit:"", backgroundColor: "#53a7c0" } standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" } main "switch" details(["switch","lValue","refresh"]) } } def parse(String description) { } def on() { sendEvent(name: "switch", value: "on") log.info "Dimmer On" } def off() { sendEvent(name: "switch", value: "off") log.info "Dimmer Off" } def setLevel(val){ log.info "setLevel $val" // make sure we don't drive switches past allowed values (command will hang device waiting for it to // execute. Never commes back) if (val < 0){ val = 0 } if( val > 100){ val = 100 } if (val == 0){ sendEvent(name:"level",value:val) off() } else { on() sendEvent(name:"level",value:val) sendEvent(name:"switch.setLevel",value:val) } } def refresh() { log.info "refresh" }