Examples‎ > ‎

Custom SmartThings Widgets

posted Feb 15, 2015, 2:20 PM by Joshua Lyon   [ updated Feb 15, 2015, 2:20 PM ]
In this tutorial, we will show how to use SharpTools and Tasker to create a custom widget that displays Thing state in Android. If you are looking for a quick and easy way to control your Things without Tasker and without showing the current state, the built-in widget 'A Thing' is ready-to-go right out of the box.

You might also be interested in the following SharpTools articles:

Requirements

High-Level Approach

  1. Add a 'Task' widget to the Android homescreen
  2. Configure the action to perform when the widget is tapped
  3. Subscribe to an attribute of the Thing
  4. Change the icon displayed on the widget when the Thing state changes

Instructions

Create the Widget + Action

  1. Follow the steps for your launcher to pick a Widget to be added to your homescreen
    Note: Many launchers display the list of widgets after a long press of the homescreen or within the app drawer. Consult the manual for your homescreen or install the Google Now Launcher.
  2. Select the 'Task' widget
  3. Select the 'New Task' option
  4. Enter the name 'Light Toggle' for the Task and click OK to continue.
    Note: You must enter a name here as we will use it later to change the Widget icon based on the Thing state changing.
  5. Tap the '+' icon at the bottom of the screen to add a new Action
  6. Select Plugin > SharpTools > A Thing
  7. Click the pencil icon on the Configuration line
  8. Select the device type, device, and command you would like to perform when the widget is tapped. For this example, we are going to use the 'toggle' command of a light.
  9. Tap apply to save the 'A Thing' settings
  10. Press the back button of your Android device to save the Action
  11. In the bottom-right corner of the Widget configuration, select the 'icon-grid' button to select an icon to be displayed on the widget.
  12. Select 'Built-In Icon' and select the Panda Bear.
  13. Press the back button of your Android device to save the Widget
At this point, you should now see a Panda Bear widget on your homescreen and if you tap this icon, the selected light should toggle on and off.

Subscribe to an Attribute

  1. Launch SharpTools
  2. Scroll down to your desired 'Thing'
    Note: In this example, we are using the Upstairs Hall light.
  3. Long press on the Thing name and a Subscription menu should pop up
  4. Subscribe to the desired attribute by tapping it
    Note: In this example, we are interested in when the light turns on and off, so we will use the 'Subscribe to switch' option.
  5. The Thing should now show a star in the top-right corner of the card

Create the State-change Context

  1. Launch Tasker
  2. From the Profiles tab, click the '+' icon at the bottom of the screen
  3. Select Event > Plugin > SharpTools > Thing State
  4. In the Thing Name field, enter the name of the subscribed Thing
  5. In the Attribute Name field, enter the name of the subscribed attribute
  6. Click Apply to save the Thing State settings
    Note: several variables are saved in Tasker whenever the Thing State event is triggered. We will use these variables in the following steps to determine how to change the widget icon.
  7. Press the back button on your Android device to save the event
  8. Select the 'New Task' option when prompted
  9. Optionally provide a Task name and tap the checkmark to continue
  10. Tap the '+' icon at the bottom of the screen to add a new action
  11. Select Tasker > Set Widget Icon
  12. Tap the search icon (magnifying glass) and the select the widget 'Light Toggle' that we created earlier
  13. Tap the 'icon-grid' button to select an icon to be used for the 'on' condition
    For demonstration purposes, we used the colored Tasker icon from the bottom of the 'Built-in Icons' list.
  14. Tap the '+' button in the If section to add a conditional
  15. Set the conditional to: %st_attr_value  ~ on
    Note: The left hand side of the conditional if the variable which we will evaluate. This is the 'Attribute Value' variable from step 6. The '~' indicates we will be performing a 'Matches' condition. And the 'on' indicates we will look for the word 'on' in the attribute value - make sure this is all lowercase.
  16. Press the back button on your Android device to save the Action
  17. Tap the '+' icon at the bottom of the screen to add another action
  18. Select Tasker > Set Widget Icon
  19. Tap the search icon (magnifying glass) and the select the widget 'Light Toggle' that we created earlier
  20. Tap the 'icon-grid' button to select an icon to be used for the 'off' condition
    For demonstration purposes, we used the grayed out Tasker icon from the bottom of the 'Built-in Icons' list.
  21. Tap the '+' button in the If section to add a conditional
  22. Set the conditional to: %st_attr_value  ~ off
  23. Press the back button on your Android device to save the Action
  24. Press the back button on your Android device again to save the Task
  25. Press back one more time to exit Tasker and activate the profile

Closing Comments

In this article, we demonstrated how to setup a 'Task' widget to toggle a light then how to subscribe to an attribute in SharpTools and react to that change in Tasker. Putting all this together, we now have a widget that toggles a light and displays the current state of the device. 

In the example, we used a somewhat boring built-in Tasker icons, but I implore everyone to get creative with your use of widgets. Perhaps you want to have an actual picture of the light showing the status of the device; Or perhaps you might use a custom graphic or icon pack; Or perhaps even use Zooper Widget to create a completely custom Widget. 

Troubleshooting

  • Make sure you have subscribed to the appropriate attribute of the right device inside the main SharpTools app. You can tell if you are subscribed to a device as a star will show up in the top-right corner of the card.
  • Double check the data and spelling in the 'Thing State' event.
    • For troubleshooting purposes, try clearing the Thing Name and Attribute Name fields which will make the plugin match all subscribed attribute events.
  • If you receive the message "Error: The disclaimer has not been accepted" when trying to add a Task widget, launch the Tasker app and accept the disclaimer that is shown.
Comments