Is my Light On or Off?


(Rjison) #1

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
"physicalgraph.device.cassandra.DeviceState@238bc586"

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


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

Try:

log.debug theswitch.switchState

http://docs.smartthings.com/en/latest/ref-docs/device-ref.html#attribute-name-state


(Rjison) #3

Thanks for the suggestion, I had tried that as well

 log.debug theswitch.switchState 

the output:
physicalgraph.device.cassandra.DeviceState@bbd53b8


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #4
  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.

(Rjison) #5

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.


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #6

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.


(Paul Mullen) #7

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}"
   log.debug("-------------------------------")
   if (switchState.value !="off") {
  theSwitch.stateOff()
   }
}