Is my Light On or Off?

I want to check the current state of my light. Reviewing the documentation, I think this should return “on” or “off”:
log.debug theswitch.currentState(“switch”)

However, I get this instead

Could someone please help me figure out if my light is on or off?


log.debug theswitch.switchState

Thanks for the suggestion, I had tried that as well

 log.debug theswitch.switchState 

the output:

  1. Which DTH is your Switch using?
  2. Does it show values in the IDE under My Devices?
  3. Also try: log.debug "state: ${theswitch.switchState}"
  4. Please share the entire code of your SmartApp so someone can paste into their own IDE and replicate.
1 Like

I got this to work with both a virtual switch, and my actual OSRAM light. The trick was referencing the value property:

def switchState = theswitch.currentState(“switch”)
log.debug “switchState.value $switchState.value”

Now if I can just figure out how to subscribe to the button pushed of the Ring Doorbell, I’ll be on my way!

Thanks for your help.

1 Like

You’re welcome… Thanks for persistently exploring the various possibilities.

I suspected some sub-object dereferencing was required, but it’s hard to guess that many levels without an example handy. Congrats!

subscribe() is pretty easy. The key is confidently parsing the Event object that you get back in your callback function.

For those trying to solve the same problem… note that the quotation marks around switch need to be single quotes. I thought groovy was pretty friendly about this, but not in my case. Here’s the working version. Look at the second line for the quotation mark update.

def contactOffHandler(evt) {
   def switchState = theSwitch.currentState('switch')
   log.debug "switchState.value ${switchState.value}"
   if (switchState.value !="off") {