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: RequirementsHigh-Level Approach- Add a 'Task' widget to the Android homescreen
- Configure the action to perform when the widget is tapped
- Subscribe to an attribute of the Thing
- Change the icon displayed on the widget when the Thing state changes
InstructionsCreate the Widget + Action- 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. - Select the 'Task' widget
- Select the 'New Task' option
- 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. - Tap the '+' icon at the bottom of the screen to add a new Action
- Select Plugin > SharpTools > A Thing
- Click the pencil icon on the Configuration line
- 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.
- Tap apply to save the 'A Thing' settings
- Press the back button of your Android device to save the Action
- In the bottom-right corner of the Widget configuration, select the 'icon-grid' button to select an icon to be displayed on the widget.
- Select 'Built-In Icon' and select the Panda Bear.
- 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- Launch SharpTools
- Scroll down to your desired 'Thing'
Note: In this example, we are using the Upstairs Hall light. - Long press on the Thing name and a Subscription menu should pop up
- 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. - The Thing should now show a star in the top-right corner of the card
Create the State-change Context- Launch Tasker
- From the Profiles tab, click the '+' icon at the bottom of the screen
- Select Event > Plugin > SharpTools > Thing State
- In the Thing Name field, enter the name of the subscribed Thing
- In the Attribute Name field, enter the name of the subscribed attribute
- 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. - Press the back button on your Android device to save the event
- Select the 'New Task' option when prompted
- Optionally provide a Task name and tap the checkmark to continue
- Tap the '+' icon at the bottom of the screen to add a new action
- Select Tasker > Set Widget Icon
- Tap the search icon (magnifying glass) and the select the widget 'Light Toggle' that we created earlier
- 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. - Tap the '+' button in the If section to add a conditional
- 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. - Press the back button on your Android device to save the Action
- Tap the '+' icon at the bottom of the screen to add another action
- Select Tasker > Set Widget Icon
- Tap the search icon (magnifying glass) and the select the widget 'Light Toggle' that we created earlier
- 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. - Tap the '+' button in the If section to add a conditional
- Set the conditional to:
%st_attr_value ~ off
- Press the back button on your Android device to save the Action
- Press the back button on your Android device again to save the Task
- Press back one more time to exit Tasker and activate the profile
Closing CommentsIn 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.
|
|