Trigger for SmartThings states

I have a design that allows for buttons on the left to display device object tiles on the right. What I would like to be able to do is change the color of the button on the left if the state of one of the tiles on the right is ‘On’, ‘Active’ ‘Wet’, ‘Smoke’ or ‘Motion’. I tried creating a script but it won’t update the foreground color of the button. I tried a Multi-data trigger but no luck there either. There seem to be an issue with SmartThings correctly reporting the status of the underlying events in a trigger or script. If I create a label control and bind the .Text to [MyButton].Switch, it reports the status right away. If I try to determine the state in a script or trigger I do not get a response. Is what I am doing even possible? Thanks for the help.

Add a DataTrigger to your button that monitors your device states. Then add a Setter to it that updates your Background or Foreground color. You can use either a StaticResource you have defined or a hex color string (for example #FFFF0000).

In general, most things should be handled by triggers on your pages, not scripts. You will, for the most part, only use scripting in plugins. There may be an occasional need for a script in a page, but this here is not one of those cases.

Most of the default tiles are already using DataTriggers to update the Background & Foreground. You can always look at the files in that folder to see how they are doing it. For example, here’s a screenshot of what SwitchTile.xaml is using to update its Background.

Bill, that sort of worked. The ‘Light’ button the left would only turn ‘on’ when I pressed the ‘Light’ button. I then tried moving the Trigger up the tree to the Grid and that works as soon as the project is ‘Run’. I have about 100 device in all, do I need to add 100 triggers or their an easier way.?

It should turn on whenever the Light itself turns on. It shouldn’t matter whether you’ve click the Button. DataTriggers are only watching the device status. You don’t have to click them to activate them. There’s no limit to the number of DataTriggers you can have. That list supports copy-paste so you can CTRL-C / CTRL-V a bunch of times to help speed up the process.

There has been some discussion before about adding device controls to Groups. Basically you could turn all of the devices in a Group folder On or Off with a single command. When that feature is added there will probably be status support as well. Something like that could help do this a little cleaner.

You could also write a SmartThings Smart App that does this for you. Use it to create a virtual device that groups all of these status values into a single object. That can probably be done. If you don’t want to create 100 DataTriggers that could be a better solution for you.

Great, thanks for the quick response and helpful tips. Home Remote rocks!

1 Like