Skip to content

Instantly share code, notes, and snippets.

@joshualyon
Created April 18, 2020 23:57
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/e77ff61c3937521ee2f2e8a6d7c22007 to your computer and use it in GitHub Desktop.
Save joshualyon/e77ff61c3937521ee2f2e8a6d7c22007 to your computer and use it in GitHub Desktop.
Simulated Illuminance (with Switch Mappings)
metadata {
definition (name: "Simulated Illuminance Sensor", namespace: "sharptools-io", author: "Josh") {
capability "Illuminance Measurement"
capability "Switch"
capability "Switch Level"
capability "Sensor"
command "setLux"
}
preferences(){
input "minLux", "number", title: "Min Lux", description: "Minimum setLevel Lux Value"
input "maxLux", "number", title: "Max Lux", description: "Maximum setLevel Lux Value"
}
}
def installed() {
log.trace "Executing 'installed'"
initialize()
}
def updated() {
log.trace "Executing 'updated'"
initialize()
}
private initialize() {
log.trace "Executing 'initialize'"
sendEvent(name: 'switch', value: 'off')
sendEvent(name: 'level', value: 0)
sendEvent(name: 'illuminance', value: 0)
}
def setLux(luxLevel){
log.trace "setLux()"
sendEvent(name: "illuminance", value: luxLevel, unit: 'lux')
}
def setLevel(level){
//map the level values to rough lux values
def min = minLux ?: 0;
def max = maxLux ?: 110000;
def range = max - min;
def step = range / 100;
setLux(level * step);
sendEvent(name: "level", value: level)
}
def on(){
log.debug "Max lux value is ${maxLux}"
def val = maxLux ?: 110000
setLux(val)
sendEvent(name: "switch", value: 'on')
}
def off(){
log.debug "Min lux value is ${minLux}"
def val = minLux ?: 0
setLux(val);
sendEvent(name: "switch", value: 'off')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment