Hey all,
I just joined the ST club with the starter pack and some hue lights. Not being scared to code, I read through the documentation and started playing around with things. I’m not overly familiar with the language, and the last time I did any serious coding was with Java ~10years ago.
I’ve hit a brick wall with these lights, and I was hoping someone could help me out with the syntax or point me in the right direction. I don’t understand where to go to learn the exact abilities of each device and what I can do with each one. For example, light.on() is fairly obvious. Setting color was an hour long struggle, but I solved it. But, how can I poll the device to get the current state of color, hue, level, etc?
My first app is to monitor the garage and front door sensors (both samsung multipurpose sensors). If either of them open, then two lights are supposed to turn on for 5 minutes. One light is a white hue, and the other is a colored hue. The last step is that I want the app to revert the lights to whatever they were set prior to the action being triggered at the end of the 5 minutes(on/off/color/level/etc).
Any suggestions or advice?
Thanks in advance.
Current code below:
preferences {
section("Sensor to be used for the Front Door:") {
input "door", "capability.contactSensor", multiple: true, required: true
}
section("Sensor to be used for Garage Door:") {
input "garage", "capability.contactSensor", multiple: true, required: true
}
section("White lights to be triggered on:") {
input "whitelight", "capability.light", multiple: true, required: true
}
section("Green lights to be triggered on:") {
input "colorlight", "capability.light", multiple: true, required: true
}
section("Return to previous state after:") {
input "minutes", "number", required: true, title: "Minutes?"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(garage, "contact.open", contactOpenHandler)
subscribe(door, "contact.open", contactOpenHandler)
}
def contactOpenHandler(evt) {
whitelight.on()
colorlight.on()
colorlight.setColor(hue: 36, saturation: 87, level: 100, color: "#21FF44")
def del = minutes * 60
runIn(del, turnitoff)
}
def turnitoff(){
whitelight.off()
colorlight.off()
}