Hi all,
I’ve been lurking on the community for a while but I’m a bit lost about what’s going on.
So I have a very small device handler that takes the button switch and goes to a URL based on the switch being off/on. When I use the switches manually it works just fine, but if I throw them in an automation they are backwards. So if the automation says to turn things off, it actually turns them on. That wasn’t too big of a deal, but now that I have Alexa hooked up I have to tell “her” off when I mean on. Here is the code.
import java.security.MessageDigest
preferences {
input(“deviceID”, “text”, title: “Device ID”, description: “The device id”)
}
metadata {
definition (name: “RF Lights”, namespace: “CD85233”, author: “NAME”) {
capability “Switch”
}
simulator {}
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "on", label:'on', action:"on", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"off"
state "off", label:'off', action:"off", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"on"
}
main "switch"
details (["switch"])
}
}
// handle commands
def on() {
sendEvent(name: “switch”, value: ‘off’)
log.debug "Executing ‘off’"
sendCommand(settings.deviceID, ‘off’)
}
def off() {
sendEvent(name: “switch”, value: ‘on’)
log.debug "Executing ‘on’"
sendCommand(settings.deviceID, ‘on’)
}
def sendCommand(device, status) {
def commandParams = [
uri: 'http://#####.####.##/###?###&###
]
try {
httpPost(commandParams) {commandResponse ->
log.debug commandResponse.data
}
} catch(Exception ex) {
log.debug "Expected HTTP ERROR'"
}
}