Can you subscribe to ALL events of a device in an app

So I have an app where use 8 or so events from a device type (thermostat). In the past I just subscribed at all of the events individually.

Based on this documentation (see link - void subscribe(Object thing, handlerMethod)), though, I think I should be able to not specify an attribute in the subscribe and subscribe to ALL events on the device in one subscribe entry.

https://docs.hubitat.com/index.php?title=App_Object#subscribe

I tried it, though, and it does nothing. No error, but the app also does not show the subscriptions (and the corresponding handler method never fires either).

In my app this subscribes to apparently nothing:

subscribe(tStat, tStatUpdate)

This subscribes to the specified attributeName:

subscribe(tStat, "coolingSetpoint", tStatUpdate)

What gives?

Yeah, I agree. I've seen the same thing.

That's the weirdest part. No errors or anything.

I had asked @bravenel the same question a month or so ago but nothing he came up with worked for me either. I'd love to have an answer to this one as well. If you need refreshing Bruce, this is the thread I was talking about:

i've also tried
subscribe(myDevices.each,eventHandler)
and that didn't throw errors or subscribe to any events.

It's not the end of the world in my case, I can do it the multi-subscribe way...

But what does "void subscribe(Object thing, handlerMethod)" do, if not subscribe to all events?

Yeah, that's what I ended up doing as well. But I had the same question. Bruce never came back with something else to try. Maybe it was never implemented from a platform level. Glad I'm not the only one...at least I know it's not just something that I screwed up.

This is my understanding of how it works.

You subscribe to the events of an attribute.
You can subscribe to a specific event ie an attribute becoming a specific value OR you can subscribe to all events related to that attribute.

For example you can subscribe to a specific event of the switch attribute (switch.on) or all the possible values of the switch attribute (switch). The latter will subscribe to switch.on and switch.off

I dont believe you can subscribe to all events of a device..you have to specify the attribute to monitor changes in. I have never built a thermostat driver so I dont know the syntax for that one in particular but you would just need to look at the documentation to find the attribute events you want to subscribe to.

Regardless I believe you need to have
subscribe(device, "attribute", handler).

Yeah, but there is a method where you don't have to specify the attribute that is in the documentation.

image

And according to Bruce, it should work.

I believe you always need 3 parameter. The device, the attribute and the handler. The only "option" you have is to subscribe to a particular value of an attribute or all attributes. I "believe" being the key word :slight_smile:

No, according to the developer docs, you should be able to subscribe to all events from a device.
image

Ah..ok. I guess this may be specific to Hubitat. I dont think that was an option in ST.

You may be right....it might be listed incorrectly as a device wrapper because in ST dev docs.

image

That's used to subscribe to another app!

Or location events.
image

My guess based on the smartthings subscribe command documentation, is that you can subscribe to SOME things (like location) with only 2 parameters, but not device attributes.

For instance, this is valid in smartthings:

// shortcut for mode change handler
subscribe(location, modeChangeHandler)

But a 2 parameter call isn't valid for device events.

1 Like

What I find odd....no errors were thrown. That makes me wonder what else i'm doing wrong that I'm not getting errors for.

I think that's because location is a system event and not a device attribute. The device could have many attributes, each with many values.

I do agree that it would be "nicer" if the system would error out to let you know that call isn't going to do anything.

1 Like

Probably. That would make sense.

I just tried with (location,handler) and it still subscribed to nothing.

:man_shrugging:
Your guess is as good as mine.
We'll have to wait for the all knowing @chuck.schwer to lay down the truth...I guess.

2 Likes

LOL That is even weirder. I believe that works in ST... Oh well. I guess we need Bruce, Chuck, or Mike to chime in and demystify this.

Scratch that...my apologies. It helps when you spell your handler method correctly in your subscribe. hehe :upside_down_face:

2 Likes

There is currently no way to subscribe to all events of a device. We discovered this recently and have a ticket open to get it added.

1 Like