RBoy
(www.rboyapps.com - Making SmartThings Easy!)
1
I have an app in which I select multiple motion sensors and subscribe to events.
The issue is once I the event handler is called I’m trying to find out which device generated the event then call a custom handler on the device.
so according to the docs
event.device
should return the device object, hence I should call
event.device.customHandler()
to call my handler. When I’m debugging it, I can see $event.device shows the name of the device, however when it does event.device.customHandler() I’m getting a null object exception.
What am I missing here? Isn’t the event.device a device object on which I can call the handler?
The work around is to get the event.deviceId and then match that with the list of devices selected, which is kinda roundabout.
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
2
Your syntax looks right to me, but some SmartApps are convoluted, so it’s hard to find a live example.
If you have the patience, take a guess as to any SmartApps which may do something like this and see if how they are doing it.
For example, Button Controller looks up the Device List from the preference Map, and then has no problem calling device.command. … But I guess that’s pretty much the “roundabout” solution you mention in the last line of your post. Hmmm.
I’m just wondering if there is an object reference error (Device vs. Device ID), so lots of debugging output might be necessary to confirm the behavior.
I’m also assuming you’ve tested a simple case of “device.customHandler()” so that you know that Device Type Command is working fine for a direct reference?
Thanks. I see that error too… I have a question out to engineering, will follow up when I hear something.
RBoy
(www.rboyapps.com - Making SmartThings Easy!)
10
Great, that’ll solve another issue, tracking the devices in a map array object. That also doesn’t seem to work.
when tracking active devices, I want to store the device objects that I want to track but again it doesn’t work so I need to resort to storing device Id’s.
e.g.
state.deviceList = [] // Reset the list
for (dev in selectedDevices) {
state.deviceList.add(dev) // add device to be monitored
}
This doesn’t work for probably the same reason. Later when I get an event, I try to compare evt.device to the list of objects in the state.deviceList it doesn’t match it. I have to resort to matching device id’s. i.e this won’t work
We’ve verified the reported behavior, and have created a ticket to make sure that the device instance returned from an event behaves the same as a device in any other context.
I’ll follow up here when the ticket is resolved; until then, you’ll need to use the workaround found here.
Thanks for point this out; apologies for the confusing behavior.
RBoy
(www.rboyapps.com - Making SmartThings Easy!)
12