Device types Getting the current state of a switch or the button tile On Off state

Ok I am sure I am missing some newbie element here but I have a device with two physical switches. When a switch is toggled by hand the following event is triggered:

def zwaveEvent(physicalgraph.zwave.commands.multichannelv3.MultiChannelCapabilityReport cmd) 

{}

In the data sent from the switch I can see which of the two physical switches were toggled but not the current state of the light.

How can I ask Smartthings the current state of the switch on the hub?

Thanks so much!

http://docs.smartthings.com/en/latest/capabilities-reference.html?highlight=currentswitch#switch

I’ve looked at that a couple times but so far haven’t got it to work. Theres clearly a bunch I dont understand about Groovy and variable scope.

Here is what gets passed back to my event handler when I toggle a physical switch

multichannelv3.MultiChannelCapabilityReport MultiChannelCapabilityReport(commandClass: [32, 37], dynamic: false, endPoint: 1, genericDeviceClass: 16, specificDeviceClass: 1)

I’m not sure what

“dynamic: false” tells me and I think the two device classes arent useful for what I am trying to do. The end point is useful though!

Ive been reading through the user guide tonight (and im going to read the WHOLE thing through) but I from what it says about command classes that is also confusing to me.

Any idea what this means in the event?
commandClass: [32, 37],

hold on are you building a device or a smartapp?

This is a device. I am trying to improve the dual relay device type thats floating around because currently when you toggle the physical switch, there is no code to update the hub to let it know the state has changed.

http://docs.smartthings.com/en/latest/ref-docs/device-handler-ref.html?highlight=sendevent#sendevent

So that works kinda if I use it like this:

 if (cmd.endPoint == 1 ) 

{
sendEvent(name: “switch1”, value: “on”, isStateChange: true, display: false)
}

Only I need to know if it is on or off before so I can send the proper value :

Im not sure I understand isStateChange but I was hoping that might be part of it.

Just solved this!

def zwaveEvent(physicalgraph.zwave.commands.multichannelv3.MultiChannelCapabilityReport cmd) 

{
log.debug "multichannelv3.MultiChannelCapabilityReport $cmd"
if (cmd.endPoint == 2 )
{
def currstate = device.currentState(“switch2”).getValue()
// log.debug “$currstate”;
if (currstate == “on”)
sendEvent(name: “switch2”, value: “off”, isStateChange: true, display: false)
else if (currstate == “off”)
sendEvent(name: “switch2”, value: “on”, isStateChange: true, display: false)
}
else if (cmd.endPoint == 1 )
{
def currstate = device.currentState(“switch1”).getValue()
// log.debug “$currstate”;
if (currstate == “on”)
sendEvent(name: “switch1”, value: “off”, isStateChange: true, display: false)
else if (currstate == “off”)
sendEvent(name: “switch1”, value: “on”, isStateChange: true, display: false)
}

}

Thanks for the nudge in the right direction!

1 Like