Rather than reinvent the wheel…you might want to just install and use webCoRE. I thought about building my own SmartApps for a while too…but there’s really nothing I’ve wanted to do that webCoRE couldn’t handle. You should check it out.
Many ways to do this. Here’s how I toggle lights in my Advanced Button Controller smartApp. Code was taken from the default Button Controller template. You don’t need the siren portion of the code but you can customize as you see fit. Hope it points you in the right direction.
def toggle(devices) {
log.debug "Toggling: $devices"
if (devices*.currentValue('switch').contains('on')) {
devices.off()
}
else if (devices*.currentValue('switch').contains('off')) {
devices.on()
}
else if (devices*.currentValue('alarm').contains('off')) {
devices.siren()
}
else {
devices.on()
}
}
I don’t really understand what you are doing with the above code. I assume you are subscribing to the switch events.
Shouldn’t your code be…
Def switchState=evt.value
Then you can compare the value and execute accordingly…
If(switchState==‘on’)
In my example in the previous post, I am passing the switches (devices) and comparing their states. In your case you seem to be passing the on/off event itself. If I’m wrong provide more details.
Please post your entire code, not easy to help otherwise.
The
MissingMethodException: No signature of method
is a generic error saying you are calling a method on an object that doesn’t support it.
So you have to make sure you are referencing the right object before getting its state and make sure this method works on the class of object you are using.
I am not fan of Piston things, but something very true about “avoid reinventing the wheel”. When I have difficulties coding something in ST, I check in the forum if someone coded it previously and I also check the ST public GitHub. There might be a lot of example of getting an object state from a smartapp, I am thinking about NotifyMeWhen as a very basic one.