I’m trying to get the event source in a smart app to see if it’s made by a user manually triggering something, or from the smart app.
I’m subscribing as follows:
subscribe(s, "switch", manualSwitchHandler)
I’m then trying to figure out from info held in the evt object. The old SmartThings doco indicates evt.source should do the trick, but it only ever contains DEVICE.
That is because the events you are subscribing to are DEVICE events. There are plenty of other types events around, some of which used to appear in the event history, like APP_COMMAND, though I suspect they might not appear any more as there have been a lot of changes lately.
The sort of thing you are after sounds like the evt.isPhysical() v evt.isDigital(). I’m not sure of the state of play with these, be they withdrawn, unsupported, deprecated or what. The bottom line was that they could not be relied upon in general.
They stopped including digital versus physical information about three years ago, at least for Z wave devices, because if the message went through a repeater it was not always reported correctly.
It’s not just that feature - it’s a compound of things. At this point I’m surprised that there is switch.on and switch.off capability remaining.
The route I’m going down is to create a map in atomicState and stick the deviceId in there each time the app triggers an event. Then, in the method handling the event I’ll check if the triggering deviceId is in the map and remove it if it is. This will indicate that the app triggered the event. If the deviceId isn’t in the map then it indicates the event has been triggered by something outside of the app.
It’s annoying, and I’d expect that it won’t be 100% perfect (you can’t do any locking, for example, to make sure timings are correct and that events don’t slip in at the wrong time) but I’m hoping it will be good enough.