Keypad Subscribe Question

Yes, you need the attribute. It can be general, like "switch" for all switch events, or specific, like "switch.on".

1 Like

Thanks Bruce

Is there any other way to subscribe to all of a devices attribute?

Sorry to resurrect an old thread but I am doing something wrong and for the life of me I can't figure out what. I'm trying to subscribe to all device events, I boiled it down to this very simple app:

preferences {
    page(name: "pageConfig")
}

def installed() {
    log.debug "Installed"
}

def updated() {
    log.debug "Updated"
    unsubscribe()
	subscribe(myDevices,eventHandler)
}


def pageConfig() {
    dynamicPage(name: "pageConfig", title: "Test App", nextPage: null, install: true, uninstall: true, refreshInterval:0) {		
	section() {
		input "myDevices", "capability.*", title: "Select Devices", submitOnChange: true, hideWhenEmpty: false, required: true, multiple: true
	}
    section({label title: "Enter a name for this app", required: false})
}
}


def eventHandler(event){
    log.debug "${event.device}  ${event.deviceId} ${event.name} ${event.value}"
}

But after installing and updating the app, there are no device subscriptions.

What am I doing wrong in subscribe to get it to work correctly?I can't figure this one out for the life of me. If I define an attribute, everything works perfectly. But I know I shouldn't have to define an attribute in order to subscribe to everything. Thanks!

Not sure. Try

myDevices.each { subscribe(it, eventHandler) }

I'll look around and see if there is another way to do it.

Nope...that didn't end up with any subscriptions either. I tried doing it like this:

def updated() {
    log.debug "Updated"
    unsubscribe()
    myDevices.each{
        subscribe(it, eventHandler)
    }
}

image

Just to try it out, I tried defining a capability to filter the device list for, that didn't work either. It seems the only way is to subscribe to specific attributes. Not a huge deal, just makes my job a lot harder on the front end. That's all. I assume that if I subscribe to a specific attribute for a device that doesn't have it, that's not a problem, right? Because, even if I have a device list of contact and motion sensors, this does work:

def updated() {
    log.debug "Updated"
    unsubscribe()
    subscribe(myDevices,"contact",eventHandler)
    subscribe(myDevices,"motion",eventHandler)
}

Gives me this:

image

Now, it will never get a contact event from Office Motion 2 but I assume that won't hurt anything, right? If not, then I really won't have to do too much extra on the front end.