Can I control subscribed device?


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() {

def updated() {

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

def onHandler(evt) {
If (AutoOn) {

def offHandler(evt) {
assert AutoOn == true


(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”]
[/quote]The lowercase s could be causing the error. I’m also pretty sure that ST blocks assert statements.


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…)