Skip to content

Instantly share code, notes, and snippets.

@joshualyon
Created September 20, 2021 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshualyon/a3d4332d1e3b8663bb0c50a3b1766501 to your computer and use it in GitHub Desktop.
Save joshualyon/a3d4332d1e3b8663bb0c50a3b1766501 to your computer and use it in GitHub Desktop.
Virtual Humidity Switch for easier authorization
/*
Virtual Humidity Switch
Author: @josh (SharpTools.io)
Description: Basic Virtual Humidity device that comes with a Sensor capability for authorization.
*/
metadata {
definition (name: "Virtual Humidity Switch", namespace: "sharptools-io", author: "Josh Lyon") {
capability "Actuator"
capability "Sensor"
capability "Switch"
capability "RelativeHumidityMeasurement"
command "setHumidity", ["NUMBER"]
}
preferences {}
}
def parse(String description) {
}
def on() {
log.trace "Executing 'on'"
sendEvent(name: "switch", value: "on", isStateChange: true)
}
def off() {
log.trace "Executing 'off'"
sendEvent(name: "switch", value: "off", isStateChange: true)
}
def setHumidity(value){
log.trace "Executing setHumidity $value"
sendEvent(name: "humidity", value: value, isStateChange: true)
}
private Map buildEvent(name, value, unit=null) {
Map eventMap = [name: name, value: value, unit: unit, isStateChange: true]
return eventMap
}
def installed() {
on()
setHumidity(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment