Hi - I am trying to trigger an event on another device from within my SmartApp using when a virtual (simulated) switch is triggered. The virtual switch gets triggered fine (as it happens by an IFTTT rule) and then the associated event fires with :-
This version tells sendEvent first what device youâre triggering. Then the event map which includes name of the capability attribute that is changing and the value itâs changing to. If this event doesnât change the state of âmotionâ on the device, it wonât show in Recently unless you force it an additional map parameter isStateChange: true
Be aware if the motion sensor is a real device you could get very odd behavior depending on how often it reports its status.
Yes, itâs a property of the device object. ST automatically assigns them when a device pairs, but for simulated devices, you might have needed to input one yourself. Check the My Devices tab of the IDE and you will see a column for Device Network Id to see if itâs populated for this simulated device. Iâm betting itâs blank and you can manually update it by clicking the device, then Edit at the bottom of the device screen.
I had considered that and already checked, unfortunately it does have a network device id.
Just in case it was linked to the simulated motion sensor I published the code to my device and it doesnât work as hoped either for a physical motion sensor or the simulated version.
I was trying to follow this part of the docs for using sendEvent from a SmartApp. When I took out the .deviceNetworkId I got a different error that seems to imply you can only do this for Child Devices of the SmartApp. (By the way, I am using this format of sendEvent using a child device with the .deviceNetworkId part in a SmartApp. And I believe you can see it in the Hue Connect SmartApp if you want an example.)
Since itâs a simulated motion sensor, you could use a custom device handler with a new command that just sends the âActiveâ event for the device, then call that custom command from your SmartApp.
Thanks for your input again, still trying to work my way through the samples/docs as I have only had SmartThings for a few days.
I am happy to try and trigger the physical motion sensor instead of the simulated (virtual) one if that makes life easier - would you have any guidance to enable this approach instead?
That was silly of me! I thought you would need a custom device type, but it looks like the Simulated Motion Sensor already has extra commands. You should be able to just do:
themotion.active()
That should trigger the active() command in the simulated motion sensor. The physical motion sensor wonât have that custom command, so youâll want to use the simulated one.
Where did you find the details for the methods the simulated motion sensor object supports? (it should have been something I would have found if I had known where to look).
Mikeâs app is a really cool way to check devices you donât have the code for. You can find the code for most stock ST devices including the simulated motion sensor on their public github. Sometimes the version on github isnât the same as the one in production.
Thanks for the help given here - itâs a great community!
With the help from here, I have completed the app to my requirements now and here is a link should anyone else be remotely interested in this functionality - itâs very simple (not a bad thing sometimes with code!) and does the job well.