Last active
September 18, 2020 00:08
-
-
Save imnotbob/0990cf11097ebdcf9dcdc7418601e640 to your computer and use it in GitHub Desktop.
HE virtual device to set string attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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