Skip to content

Instantly share code, notes, and snippets.

@imnotbob

imnotbob/vattr.groovy

Last active Sep 18, 2020
Embed
What would you like to do?
HE virtual device to set string attributes
/*
* Virtual attribute
*
* Licensed Virtual 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.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2020-09-17 nh.schottfam Original
*
*/
metadata {
definition (name: "Virtual Attribute set", namespace: "nh.schottfam", author: "imnot_bob") {
capability "Actuator"
attribute "var1", "string"
attribute "var2", "string"
command "setVar", ["string", "string"]
command "clrVar", ["string"]
}
}
preferences {
input("debugEnable", "bool", title: "Enable debug logging?")
}
def setVar(var, val) {
if(var in ['var1', 'var2']){
sendEvent(name: var, value: val)
if(debugEnable) log.debug "set variable $var"
} else log.warn "improper arg $var $val, variable should be var1 or var2"
}
def clrVar(var) {
setVar(var,'')
}
def installed() {
log.trace "installed()"
for (v in ['var1', 'var2']){
setVar(v,'')
}
}
def updated(){
log.trace "updated()"
if(debugEnable) runIn(1800,logsOff)
}
void logsOff() {
log.debug "debug logging disabled..."
device.updateSetting("debugEnable",[value:"false",type:"bool"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment