Skip to content

Instantly share code, notes, and snippets.

@joshualyon
Last active July 10, 2019 16:26
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/22e7a959a15933ebf7c478139135e2da to your computer and use it in GitHub Desktop.
Save joshualyon/22e7a959a15933ebf7c478139135e2da to your computer and use it in GitHub Desktop.
/**
* Simulated Battery
*
* Copyright 2019 josh
*/
metadata {
definition (name: "Simulated Battery", namespace: "sharptools-io", author: "josh", cstHandler: true) {
capability "Battery"
capability "Sensor"
capability "Actuator"
command "setLevel", ["NUMBER"]
}
simulator {
// TODO: define status and reply messages here
}
tiles {
// TODO: define your main and details tiles here
}
}
def installed(){
setLevel(100)
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
// TODO: handle 'battery' attribute
}
def setLevel(level){
level = level as int
log.debug "setLevel ${level}"
level = Math.max(Math.min(level, 99), 0)
sendEvent(name: "battery", value: level)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment