Can I control subscribed device?


#1

I have a Z-Wave switch controlling multiple smart bulbs. i am trying to write a script that turns off the bulbs then turns the switch back on when it is toggled off. I keep getting null device errors.

Can i control the switch that I am subscribed to?

preferences {
section(“When this switch is toggled”) {
input “PSwitch”, “capability.switch”, title: “Which Switch?”, required: true
}
section(“Control these devices”) {
input “Devices”, “capability.switch”, title: “Which Devices?”, multiple: true, required: true
}
}

def installed() {
initialize()
}

def updated() {
unsubscribe()
initialize()
}

def initialize() {
def AutoOn = false
subscribe(PSwitch, “switch.on”, onHandler)
subscribe(PSwitch, “switch.off”, offHandler)
}

def onHandler(evt) {
If (AutoOn) {
Devices.on()
}
}

def offHandler(evt) {
Pswitch.on()
assert AutoOn == true
Devices.off()

}


(sidjohn1) #2

Does it work if you change multiple: true to multiple: false?

It wont help you with your code, but you can do this with rules machine.


(Kevin) #3

[quote=“peterg, post:1, topic:39435”]
Pswitch.on()
[/quote]The lowercase s could be causing the error. I’m also pretty sure that ST blocks assert statements.


#4

The uppercase/Lowercase was a problem

But Smartthings groovy doesn’t allow global variables, I had to use “state”.

evt.physical is another way to do this.

(I’m learning…)