Examples

This page displays the full list of examples in article format. If you are looking for a summarized list of examples, you may prefer the condensed view.

Troubleshoot Push Events

posted Jul 10, 2016, 1:16 PM by Joshua Lyon   [ updated Dec 29, 2016, 9:25 AM ]

SharpTools uses push events for two main features -- the `Thing State` Tasker plugin and Widgets that display state. This article explains how push events work with Widgets and Tasker and how to troubleshoot various features.

Widgets

SharpTools includes a widget called "A Thing (Widget)" which can change color to reflect the current state of a device. For example, you might create a widget for a lamp and the widget would show a lit-up yellow color when the lamp is off and a gray color when the lamp is turned off. When you first create this widget, SharpTools automatically sets up an event subscription which is used to keep the widget status up-to-date. This uses the SmartThings event subscription capabilities and then pushes the data for Firebase Cloud Messaging (FCM) by Google. FCM is Google's push event and push notification service that powers millions of Android apps that you like use today.

The process is something like the following:
Thing → SmartThings → SmartApp (SharpTools) → Firebase → SharpTools → Widget

It may seem like a long process, but all this happens in milliseconds when things are working properly! 

In addition to the push events, SharpTools also refreshes the widget data anytime the main SharpTools app is open and the Thing data is refreshed. By default, the Thing data is automatically refreshed when you first open the app. Additionally, you can change the SharpTools Settings to periodically refresh data while the app is open or you can manually refresh the data by tapping the refresh icon in the action bar. 

Widget-specific troubleshooting: The first step in troubleshooting widgets is to try deleting the widget and then setting it back up again. After deleting the widget, check to see if there are any subscriptions for the Thing/Attribute that was used for the widget by opening the Subscriptions pane from the SharpTools left navigation and tapping the refresh icon in the action bar. Remove any remaining subscriptions by long-pressing on the subscription and selecting Unsubscribe. Try setting up the widget again and verify if the push events are working as expected.

Tasker

The 'Thing State' event plugin in Tasker uses many of the same principles as the SharpTools widgets -- the main difference being that you must manually subscribe to your desired attribute and setup the 'Thing State' plugin in Tasker. Check out the Event: Thing State tutorial for more information on how to set up a Tasker profile that reacts to SmartThings events.

The summarized version of setting up the profile is as follows: First, subscribe to the desired attribute by long pressing on the Thing in SharpTools and selecting the appropriate "Subscribe to..."  option. A small star icon will show up in the top-right corner of the Thing card when you are subscribed to at least one attribute. Then open up Tasker and create a new 'Thing State' event profile and make sure you configure the Thing and Attribute fields to match your subscribed thing/attribute. 

The process of an event being triggered is very similar to widgets -- a SmartApp running in the SmartThings cloud watches for the subscribed Thing events and then pushes the data to your device using Firebase Cloud Messaging by Google (FCM). 

The process is something like the following:
Thing → SmartThings → SmartApp (SharpTools) → Firebase → SharpTools → Tasker*

Again, this may seem like a long process, but it all happens in milliseconds when things are working properly! 

*Within Tasker, the 'Thing State' profile has to be configured correctly to trigger the task and the task must be configured properly to take a desired action. One way to test this is to completely clear out the 'Thing' and 'Attribute' fields in the 'Thing State' event plugin configuration -- this will cause the Tasker plugin to match ANY thing and attribute that changes. Additionally, try creating the most basic profile you can with ONLY the 'Thing State' plugin as a context and ONLY an Alert → Notify action with "TEST" as the title. If the simple profile and task are being triggered successfully, build from there adding 'Thing' and/or 'Attribute' filters to the Thing State plugin and adding additional logic and actions to the task.

Subscriptions

SharpTools has a Subscriptions screen which displays all the currently subscribed Device/Attribute pairs for the current Android device. To access this feature, open the left navigation in SharpTools and select Subscriptions. Once the subscriptions screen is open, tap the refresh icon in the action bar to download the latest set of subscriptions from SmartThings. 

Note that the subscriptions list shows two different icons -- the first icon is a square/cube which indicates that a subscription is in place and is being used for widgets. The second icon is a star icon which indicates that a subscription is in place and is being used for Tasker. 

A subscription can also have both a widget and Tasker subscription -- in this case, if you long-press and try to remove the subcription, SharpTools will only remove the Tasker subscription leaving the widget subscription in tact. Similarly, if you have both a widget and tasker subscription and then remove the widget, SharpTools will remove the widget subscription but leave the Tasker subscription in tact. To completely remove the subscription, you may have to manully unsubscribe from the thing/attribute and then delete the widget from your homescreen.

Troubleshooting

Now that we have a basic understanding of how the Widgets and Tasker push event features work, let's dig into troubleshooting a bit. As of SharpTools 2.3, there is now a "Manage Push Events" feature at the bottom of the SharpTools Settings screen. This is a great place to start for troubleshooting. 

Verify Cloud Messaging ID

At the top of the screen, you should see your Firebase Cloud Messaging ID (FCM ID). If you don't see an ID, this likely means that something went wrong when trying to register your device with Google. This registration process is all handled automatically by Google, but if you aren't seeing a FCM ID for some reason, you can try tapping the 'Force Reset FCM ID' option which will forcefully clear the local registration ID and manually ask Google for an ID.

Send Test Message

Once you have confirmed that you have a FCM ID, another helpful feature is the Send Test Message button. This will send a push message to your device using the SharpTools.io cloud servers. This is a great diagnostic feature as it completely takes the SmartThings servers out of the loop and directly communicates with SharpTools.io which is running on Google's Cloud Platform. After pressing the 'Send Test Message' button, you should see a message indicating whether or not the message was successfully posted to SharpTools.io and the Google servers -- when successful, this message will also include a receipt ID which is helpful for diagnostics (more on this in a bit). After a successful post, the next message you should see is a receipt of the push event. If all three messages are shown (FCM ID, Post Successful, Ping Response Received), then the core push event functionality is working on your device. 

Push Event Debug Notifications

If the Send Test Message feature works as expected, the next step is to troubleshoot events from SmartThings. Before we get started with that, it may be helpful to enable Push Event Debug Notifications. Once this feature is enabled, SharpTools will display a notification anytime ANY push event is received. This is particularly helpful in troubleshooting Tasker profiles where the profile might need some additional adjustments to work properly. Using the 'Send Test Message' feature will give you an idea how this works -- a notification will be displayed which when expanded displays the content of the received push event. 

Verify Subscriptions

Note: The instructions in this section only apply to Tasker subscriptions as the `Things` view only shows a star icon for Tasker subscriptions. If you want to see all of the subscriptions for your device, open the Subscriptions pane instead. See the Subscriptions section for more details.

After Push Event Debug Notifications are enabled, check that the desired attribute is subscribed as expected. To do this, open the Things screen in SharpTools and scroll down to your desired device. You should see a star icon in the top-right corner of the Thing card indicating that at least one attribute is subscribed. Further to that, if you long press on the device, you should see a menu of items you can subscribe to and unsubscribe from. You should see an "Unsubscribe from..." option on the attribute you are trying to receive push events from. If you don't see this option, select the "Subscribe to..." option for your desired option to make sure you are subscribed to push events. Another helpful troubleshooting step is to manually unsubscribe from and then resubscribe to your desired attribute - this forces the SmartApp to clear out the subscription and then re-add it. Additionally, you can try opening the 'Subscriptions' pane from the SharpTools left navigation and then manually tap the refresh icon in the action bar to refresh the list of subscriptions. Once you've refreshed the list of subscriptions, open the Things screen again and check to see if your subscription is setup as expected.

Test a Subscription

After you have confirmed that Push Event Debug Notifications are enabled and your desired attribute is subscribed, try triggering the event. For example, if you are subscribed to the 'switch' attribute of a light, turn the light off and on a few times. If you are subscribed to the 'level' attribute, try dimming the light down and then back up again a few times. If the push events are working as expected, you should receive a push event debug notification at that top of your screen.

Review SmartThings IDE Live Logs

If you still haven't received a push event as expected, try reviewing the SmartThings IDE Live Logs. To do this, open the SmartThings IDE Live Logs, then manually trigger your event (eg. turning the light on/off). To make it easier to sort through the logs, tap the "SharpTools" option in the top filter bar. When the subscribed attribute is changed, we expect to see a message that starts with "event triggered for [attribute] on [device_id]" -- this message indicates that SmartThings internally received the event from the Thing. If you aren't receiving this event, it means that SmartThings isn't seeing the change from your device -- the first troubleshooting step would be to manually unsubscribe and resubscribe to the attribute in SharpTools. The next message you should see is "Event data successfully posted" and then "RegIDs triggered" showing the FCM ID(s) that the push event was sent to. These last two messages indicate that SmartThings has successfully handed the messages off to Firebase Cloud Messaging and it is up to Google to deliver the message now.

Note: some IP devices like the Belkin Wemo are notorious for having slow status updates on the SmartThings platform. Submit a support ticket to SmartThings to show that you want this improved on the platform! Try testing with a Zigbee or Z-wave device as these tend to have the fastest update times on the SmartThings platform.

Complete Reset

If the push events still aren't working as expected, one option is to completely reset your environment. To do this, first open the SmartThings mobile application and remove the SharpTools SmartApp. As of writing this document, you can remove a SmartApp by opening the right-hand navigation menu, select SmartApps, scroll down and select SharpTools, then scroll down and select 'Remove'.

After the SharpTools SmartApp is removed, clear the data from the SharpTools. While many devices should not require clearing the data from the app (as an uninstall and reinstall process should clear the data), experience has shown that some device manufacturers cache app data longer than they should. To work around this, manually clear the data from the SharpTools app before removing and reinstalling it. The instructions on how to do this vary from device to device, but in general the process includes navigating to your main Android Settings screen, then selecting Applications, select "All Applications" or "Installed Applications", then scroll down and find SharpTools, then select "Clear Data". Again, the process may vary from manufacturer to manufacturer, so refer to manufacturer instructions as needed. 

After the app data has been cleared, uninstall and then reinstall the SharpTools Android app. Open Google Play and search for SharpTools -- select SharpTools and then select the 'Remove' option. Once the application is removed, restart your Android device. After your device has restarted, open Google Play and search for 'SharpTools' and select Install.

After installing SharpTools, complete the Authorization of your Things from the SharpTools Settings screen and setup the subscription again. Once the subscription is setup, try the troubleshooting steps again.

Run SmartThings Routine with Voice

posted Jan 23, 2016, 9:33 AM by Joshua Lyon   [ updated Jan 23, 2016, 10:02 AM ]

In this tutorial, we will demonstrate how to use Tasker, AutoVoice, and SharpTools to run a SmartThings routine using your voice. At the end of this tutorial, you will be able to say "Okay Google, run the routine Good Morning" and have the "Good Morning!" routine/phrase run.

This tutorial uses the SmartThings Voice Control with Tasker tutorial as a baseline. If you are unfamiliar with using AutoVoice or Tasker, I would strongly recommend reviewing the SmartThings Voice Control with Tasker tutorial.

  1. Create a new Event Profile in Tasker
  2. Choose AutoVoice → Recognized
  3. For the command filter, enter:
    Run the routine (?<routine>.+)
    Note: Make sure "Use Regex" is checked
  4. Proceed to creating your task (optionally providing a name for the task)

    At this point, we will create several actions for each desired phrase and will make these actions trigger conditional upon our desired phrase being spoken.
    (More details on conditional actions)

  5. In the task, create an action using Plugin → SharpTools → A Phrase
    Note: A Phrase is the legacy name for A Routine
  6. Use the pencil icon in Tasker to edit the "A Phrase" plugin and select your desired phrase.
  7. In the Action Edit screen for "A Phrase", scroll down to the If section and enter the %routine variable on the left and the phrase on the right that you would like to trigger the action.
    Example: If %routine ~ goodnight

  8. Repeat steps 5-7 for each desired phrase. When you are finished adding Phrases, press back multiple times to fully exit Tasker and enable the profile.

In the end, your task will have several actions like:
A Phrase: "Good Night!"
  If %routine ~ "goodnight"

A Phrase: "Good Morning!"
  If %routine ~ "good morning"

A Phrase: "Special Phrase!"
  If %routine ~ "custom spoken trigger"

AutoVoice Recognized - Event Profile Configuration Tasker Profile Configuration Conditional Phrase Action Conditional Phrases Task Overview
Note: For debugging purposes, you may want to include a simple Notify or Flash action to show the contents of the variable captured with AutoVoice. Sometimes the words captured by AutoVoice/Google are slightly different than you expected and you will want to adjust your conditional actions accordingly (eg. "good night" → "goodnight",  "10" → "ten")

For additional troubleshooting steps, see the troubleshooting section of the SmartThings Voice Control with Tasker tutorial.



React to Specific Mode Changes

posted Oct 26, 2015, 2:07 PM by Joshua Lyon   [ updated Oct 26, 2015, 2:11 PM ]

In this tutorial, we'll show how to react to specific mode changes. By default, when you subscribe to mode changes in SharpTools, the 'Mode Change' event plugin will be triggered anytime ANY mode change occurs. If you want to trigger mode changes only for specific modes, you will need to use a conditional action (IF).

In this example, we will explain how to setup a task that only runs if the mode is changed to `Night`.

  1. Open SharpTools
  2. Open the left navigation and select Modes
  3. Long press on any mode and select 'Subscribe to all mode changes'
    Note: If you are presented with the option 'Unsubscribe from all mode changes', you are already subscribed and no action is needed.
  4. Open Tasker
  5. Create a new Profile > Event > Plugins > SharpTools: Mode Change
  6. Click the pencil icon to edit the plugin
  7. No configuration is needed, so simply click the Apply button
  8. Press back to exit the profile configuration
  9. When you are prompted to enter a name for the task, leave the task blank and tap the checkmark to continue
  10. Add a new action using the + icon
  11. Select your desired action (for example, Alert > Flash)
  12. Configure your desired example (for example Text: "This is the mode we want")
  13. While you are still in the Task, press the + icon in the IF section
  14. Configure the conditional action: IF %st_mode ~ night
    Note: See the conditional action article for more information.
  15. Back out of the action
  16. Back out of the profile
  17. Back out of Tasker to enable the new profile
Here's a video showing this feature in action:

Save Status from Thing State Events

posted Aug 4, 2015, 2:07 PM by Joshua Lyon   [ updated Aug 4, 2015, 2:11 PM ]

This example shows how to save the state of a device for later use in Tasker. If you are subscribed to multiple devices, you might find that you want to have a Tasker profile react to the current state of many devices at once. In order to do this, you can save the device status off to a global Tasker variable, so it is available for use in other profiles and tasks.

Note: This same approach can be used with the action "Thing: Get Attribute" within a profile. Immediately after triggering the Thing: Get Attribute action, you would setup a Variable Set action to copy data into a global variable.

When the 'Thing State' event triggers in Tasker, there are four variables that are set. Using a Porch Light as an example:

%st_attr_name = "switch"
%st_attr_value = "on"
%st_thing_name = "Porch Light"
%st_thing_id = "xxxx-xxxxx-xxxx-xxxxx" (some long ID)


In order to make this data available in other profiles, you need to copy the data from the %st_attr_value to your desired permanent variable. For example:

  Set Variable %PORCHLIGHT to %st_attr_value

There are a couple of options on how to do this conditionally:

Option 1: One option is to setup several "Thing State" events each with the configuration filters set to react to each individual thing and then have each Task set the desired variable (eg. %PORCHSTATUS) to the value from %st_attr_value. At the end of running through your variable copying tasks, you could then trigger the main tasks which would evaluate all the global variables you have set. 

Option 2: Another option is to have one main "Thing State" event that does not have any filters applied to the plugin so it catches everything... then use conditional actions to transfer the data from the %st_attr_value to the appropriate variable. So like in the above scenario, you would use Tasker's "Variable Set%PORCHSTATUS to %st_attr_value but only IF the %st_thing_name matched "porch light". You would setup an action for each thing that you want to transfer the variable for (eg. IF %st_thing_name matched "hall light" then set %HALLSTATUS to %st_attr_value, then at the end of the task, you would trigger the main tasks which would evaluate all the global variables you have set. 

Keep in mind that local variables are only available during the execution of a task, so you should global variables so the data will be retained. From the Tasker variable guide:

Variables which have an all-lower-case name (e.g. %fruit_bar) are local, meaning that their value is specific to the task or scene in which they are used.

Variables which have one or more capital letters in their name (e.g. %Car, %WIFI) are global, meaning that wherever they are accessed from the same value is returned.

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.

SmartThings Custom Presence

posted Feb 10, 2015, 12:58 PM by Joshua Lyon   [ updated Dec 29, 2016, 10:30 AM ]

In this tutorial, we will briefly demonstrate how to use Tasker and SharpTools to create an accurate and effective custom presence solution for SmartThings. The built-in presence feature of the SmartThings mobile application has been criticized for randomly indicating that a person is no longer present in their home (when they are sleeping or sitting on the couch). 


At the end of the tutorial, you will have a custom presence solution using the proximity to your WiFi access point as the trigger for determining your presence. Additionally, the tutorial provides commentary on areas where you might choose to use alternative methods/customization that would better determine presence for your home. 


You might also be interested in the following SharpTools articles:

Requirements:

  • Tasker - automation for Android
  • SharpTools - SmartThings control for Tasker
  • OptionalAutoLocation - fused location provider plugin for Tasker
    Alternatively, you can also use the built-in Tasker location providers

If you are interested in setting up a high accuracy presence solution with AutoLocation, @destructure00 from the SmartThings Community has a fantastic write-up showing how to set nested geofences which balance high-accuracy with great battery life.

High-Level Approach 

  1. Create a Simulated Presence Device in the SmartThings IDE
  2. Create a context for entering/leaving your defined area
    • Geo-fence, WiFi, Cell Towers... or all the above!
  3. Set the Simulated Presence Device to present or away


Instructions

Create a Simulated Presence Device
  1. Navigate to the SmartThings IDE
  2. Login (or register and then login)
  3. Select 'My Devices' from the navigation
    SmartThings IDE - My Devices
  4. Click New Device in the top-right corner of the page
    SmartThings - New Device
  5. Enter a name and Network ID for the device and select the following options:
    Name: Custom Presence
    Device Network ID: FAKE_PRESENCE (or something else unique)
    Type: Simulated Presence Sensor
    Version: Published
    Location: Home (or whatever your location is named)
    Hub: Home Hub (or whatever your hub is named)
    [View Sample Screenshot]
  6. Click the 'Create' button at the bottom of the Create Device screen.

You should now have a new 'Custom Presence' device listed in your SmartThings mobile app. Unlike normal presence devices, you can manually control this presence device setting it to 'not present' (away) or 'present' (arrived). 
Continue to the instructions below to see how we can use this simulated presence device along with Tasker to create an accurate and effective presence device.

Create a context for entering/leaving your defined area

In this section, we will explain how to create a Tasker context for which will trigger when you enter or leave your defined area. Note that there are many different approaches to determining location and only a few of those are noted here. So if you have other ideas on how you might be able to more effectively determine your location, feel free to use those.
  • GPS  - Latitude/Longitude positioning (example)
  • WiFi - proximity or connection to a particular Access Point (example)
  • Cellular - proximity or connection to cellular towers in the area (example)
  • Fused Location - a location provider that combines GPS, WiFi, and Cellular
  • Manual - manual interaction/control to toggle presence indication
In order to keep this tutorial accessible to the broadest audience, we are going to use the 'WiFi Near'  condition that is built into Tasker. GPS, WiFi, and Cellular options are built-in to Tasker, but we have found that the Fused Location via AutoLocation provider provides the best accuracy both indoors and outdoors (particularly when WiFi is left on).
  1. Open Tasker
  2. From the Profiles tab, click the '+' icon at the bottom of the screen.
  3. Select the 'State' context > Net > Wifi Near
  4. In the SSID field, press the search icon to list the nearby access points
  5. Select your preferred access point from the displayed list
    Note: the SSID field should get filled in with your access point's name (SSID)
  6. Press the back button on your mobile device to save the Context
    Note: Continue onto setting up the action in the section below.

As noted in the Tasker: Location Without Tears article:
Wifi Near does regular Wifi Scans and will activate when it recognizes an AP you have configured is nearby. Note: you don't have to connect to the AP. You could configure e.g. the neighbours AP if the signal is strong enough.

Frequency of checks is controlled by Menu / Prefs / Monitor / Wifi Scan Seconds (screen on) and Menu / Prefs / Monitor / Display Off All Checks (screen off).

Check the Wifi Toggle box if you don't want wifi on all the time. It will then be toggled when Tasker needs to do a scan. This isn't needed in In Android 4.4+ if you select Scanning Always Available in Advanced Wifi Settings and will save power.

Set the Simulated Presence Device to present or away

Following the previous section where we had just completed setting up the context of a Tasker profile and had just clicked the back button to save the context.
  1. After setting up the context section of the profile, you should now be prompted to setup or select a Task
    Note: You can also setup the task outside of a profile by opening Tasker and switching to Tasks tab.
  2. Select the 'New Task +' option
  3. Optionally, enter a Task Name and click the checkmark to continue.
    Note: At this point, we are creating the task for the 'enter' portion of the context (eg. the WiFi is nearby). Later we will create an 'exit' condition for when the Wifi AP is not nearby.
  4. Click the '+' icon at the bottom of the screen to add a new action
  5. Select Plugin > SharpTools > A Thing
  6. Click the pencil icon on the configuration line
  7. Enter the following configuration:
    Device Type: Simulated Presence Sensor
    Device: Custom Presence (or whatever you named it early)
    Command: arrived
  8. Click Apply to save the SharpTools configuration
  9. Press the back button on your phone to save the Action
  10. Press the back button again to close out the Task Edit
  11. From the Profile tab of the main Tasker screen, long press on the 'A Thing' task within your 'Wifi Near' profile and select 'Add Exit Task'
  12. Select the 'New Task +' option
  13. Optionally, enter a Task Name and click the checkmark to continue.
  14. Click the '+' icon at the bottom of the screen to add a new action
  15. Select Plugin > SharpTools > A Thing
  16. Click the pencil icon on the configuration line
  17. Enter the following configuration:
    Device TypeSimulated Presence Sensor
    DeviceCustom Presence (or whatever you named it early)
    Commanddeparted
  18. Click Apply to save the SharpTools configuration
  19. Press the back button on your phone to save the Action
  20. Press the back button again to close out the Task Edit
  21. Press the back button one last time to exit out of Tasker and activate the newly created profile

Closing Comments

At this point, Tasker is setup to check to see if you are in range of your Wifi access point and will automatically change the presence sensor to arrived when you are near the Wifi access point and away if you are no longer in range of the access point.

We used the 'Wifi Near' Tasker context in this example to as it is included with Tasker and is easy to understand. Note that the author of this article recommends the AutoLocation plugin which provides a fused location provider which can provide a more flexible geolocation solution. As you might guess, the 'Wifi Near' context is dependent on being able to detect the access point... so if for some reason there are connectivity issues with the access point, the phone will trigger the exit condition. 

The fused location provider in AutoLocation helps get around this by using a geofence and location determined using Wifi+GPS+Cellular so there is a bit of fail-over built into the provider. The geofence capabilities of Autolocation also provide a visual representation your location and makes it easier to increase the size of the circle to reduce false alarms.

Other Community Thoughts

Resiliency and Retries: You may be interested in adding more resiliency to your profiles through the use of retries. Some users have found that the transition from Wifi to Cellular (or vice-a-versa) can cause the SharpTools commands to timeout while the network is unavailable. 

Hellfire51 put together a nice example showing how to add retries to your profile:

https://community.smartthings.com/t/sharptools-presence/35744

Prompt to unlock doors: You may decide that you don't want your phone to automatically perform an action for you. For example, you may prefer the phone to display a notification or prompt asking you if you really want to perform the action. 

eibyer put together an example showing how to use custom presence to trigger a prompt asking if he wants to manually unlock his doors

https://community.smartthings.com/t/phone-presence-tasker-sharptools-no-more-doors-unlocking-at-random/33631


Troubleshooting:

  • Leaving WiFi turned on for your Android device provides for the best location sensitivity in many applications
  • If you are on Android 4.4+, turn on the 'Scanning Always Available' option from Android Settings > WiFi > Advanced
  • If you are using the AutoLocation plugin or other geofence methods, try increasing the size of your geofence radius to be more forgiving
    • If you live/work/play within in a relatively small area, you may want to decrease the size of your geofence to provide a more accurate indication of presence and prevent false positives.
  • If you believe you are getting false-positives, try adding a 'Notify', 'Say', or 'Flash' action to your entry and exit tasks
    • For example, you might add a notification saying 'Arriving' to the entry task and a notification showing 'Leaving' to the exit Task to help you understand when the phone thinks you are coming or going
    • Additionally, if you are using AutoLocation, you can view the logs to see when AutoLocation thinks you are entering or leaving a Geofence and where it thinks you are at that time

Tasker Conditional Actions

posted Jan 28, 2015, 9:46 AM by Joshua Lyon   [ updated Oct 26, 2015, 2:18 PM ]

This is a draft stub of this article and may have formatting and grammatical errors.

High Level Approach

Things

  1. Things: Long press on the thing in the main SharpTools UI and subscribe to the desired Attribute
  2. Things: Setup a Thing State event in Tasker to react to the push event from the subscribed attribute
  3. Create the desired action - such as Notify to display the value
  4. At the bottom of the action, click the + sign next to IF to setup a conditional execution
  5. Things: Set the left variable to the desired SharpTools variable - for example %st_attr_value
  6. Set the conditional operator to the desired type - typically use match (~) rather than equals (=)
  7. Set the value on the right side of the operator to the desired value - use lower-case to case-insensitive matching

Modes

  1. Modes: Open the modes pane in SharpTools, long press on any mode, and choose 'Subscribe to all mode changes'
  2. Modes: Setup a Mode Change event in Tasker to react to mode changes
  3. Create the desired action - such as Notify to display the value
  4. At the bottom of the action, click the + sign next to IF to setup a conditional execution
  5. Modes: Set the left variable to %st_mode
  6. Set the conditional operator to the desired type - typically use match (~) rather than equals (=)
  7. Set the value on the right side of the operator to the desired value - use lower-case to case-insensitive matching
    Example: %st_mode ~ night
For more details on how to use conditional actions with Mode changes, check out the Conditional Mode Change article which includes a video showing how to react to only specific mode change events.

Key Items to Check

  • Keep in mind the way Tasker does pattern matching
  • Make sure you are subscribed to the thing/attribute
    • A star icon will be displayed next to the thing name if you are subscribed to any of it's attributes
  • Make sure the filter on the Thing State is set to catch the event
    • For testing purposes, try leaving the filters blank to match everything
    • Remember that the filters do partial matching
  • Try using flash or notify to display the contents of the variable to make sure you are getting the values you expect

Screenshots

Ensure the thing/attribute is subscribed:
    SharpTools Subscription
Make sure the Thing State filters will catch the event / attribute change you are looking for:
     Tasker Thing State Filters
Setup conditionals on the actions - typically using matches (~) and lowercase:
     Tasker Conditional Action
Make sure you are matching against the desired variable and value:
     Tasker Conditional Configuration

Voice Command: With Variables

posted Jan 1, 2015, 2:03 PM by Joshua Lyon   [ updated Mar 1, 2016, 11:47 AM ]

In this tutorial, we will briefly demonstrate how to use Tasker, AutoVoice, and SharpTools to use voice commands to control devices in your smart home using variables. If you are looking for a more basic tutorial on controlling your devices, see here - and if you are interested in just the details of dimming a light (without voice control), see here. At the end of the tutorial, you will be able to say Okay Google, Dim the bedroom light to 60 percent. and your phone will send a command to your Bedroom Light to change the dimming level.

Requirements:

  • Tasker - automation for Android
  • AutoVoice (Pro) - voice recognition for Tasker
  • SharpTools - SmartThings control for Tasker

Instructions

  1. Open Tasker
  2. In Profiles, click the "+" icon to add a new profile
  3. Select Event > Plugin > AutoVoice > Recognized
  4. Click the pencil icon to configure the AutoVoice plugin
  5. Tap the Command Filter option and type the following:
    Dim the bedroom light to (?<level>.+)%
    Note: the (?<level>.+) saves the spoken device name to the %level Tasker variable
  6. Check the Use Regex box
  7. Select the checkmark at the top of the screen to save your plugin settings
  8. Press the back button on your phone to save the Tasker event profile
  9. At the prompt to select a Task, select New Task
  10. Leave the optional Task Name blank and click the check mark to continue
  11. Click the + icon at the bottom of the screen to add an action
  12. Choose Plugin > SharpTools> A Thing
  13. Click the pencil icon to configure the SharpTools plugin
  14. Tap the tag icon in the action bar to enter Tasker variable mode
  15. Enter the device name in the Device field (eg. bedroom light)
  16. Enter the command to send: setLevel
  17. From the menu, check the box for `Override Parameters`
    A plus icon appears below the command allowing you to add parameters
  18. Click the `+` icon to add a new parameter and tap the AZ icon to change the variable type to numeric (09)
    Parameter 1: %level
  19. Press Apply
  20. Press the back button on your phone to save the SharpTools Action
  21. Press the back button again to close out the Task Edit
  22. Press the back button one more time to back out of Tasker completely and ensure the profile becomes active

Now you should be able to say Okay Google, Dim the bedroom light to [level] percent where [level] is a number between 0 and 100 and the associated light should dim to the desired percentage.

Other Thoughts

This approach can be used with other devices which have commands that accept parameters. Consider the following example for changing the cooling setpoint of your thermostat:
  • AutoVoice Filter: Change cooling setpoint to (?<temperature>.+) degrees
  • Device Type: Z-Wave Thermostat
  • Thing: Downstairs Thermostat
  • Command: setCoolingSetpoint
  • Parameter 0: %temperature

Troubleshooting:

  • Make sure you can manually toggle the desired device from the main SharpTools interface
  • Check the AutoVoice logs to see what it is recognizing
  • Turn on the Received Command Toast in AutoVoice for debugging
  • Make sure the command filter and variable %level are spelled exactly as noted in the instructions
  • This tutorial assumes you have AutoVoice Google Now Integration already setup
  • Some devices, like GE Link light bulbs, will only dim when using 1 parameter for setLevel
    • These devices still report that 2 parameters are required from SmartThings, so you must override the settings
    • From the 'A Thing' configuration screen, open the menu and check the box for 'Override Parameters'
    • You should now see 'X' icons show up to the right of each parameter field. Click the 'X' next to Parameter 2.
    • Follow the instructions above as normal, ignoring Parameter 2.

Voice Query: Is the bedroom light on?

posted Jan 1, 2015, 1:35 PM by Joshua Lyon   [ updated Nov 14, 2015, 7:24 PM ]

In this tutorial, we will briefly demonstrate how to use Tasker, AutoVoice, and SharpTools to query the status of devices in your home. At the end of the tutorial, you will be able to say Okay Google, is the bedroom light on? and your phone will check the status of the light and say the status as a voice response (eg. "The bedroom light is on" or "The bedroom light is off").

Requirements:

Instructions

  1. Open Tasker
  2. In Profiles, click the "+" icon to add a new profile
  3. Select Event > Plugin > AutoVoice > Recognized
  4. Click the pencil icon to configure the AutoVoice plugin
  5. Tap the Speak Filter option and say the following when prompted:
    Is the bedroom light on
  6. Select the option that matches your query from the list that is presented to you.
    Note: AutoVoice will attempt convert your voice command into text and will display the list of options with the most likely option in the first position.
  7. Check the Exact Command box
  8. Select the checkmark at the top of the screen to save your plugin settings
  9. Press the back button on your phone to save the Tasker event profile
  10. At the prompt to select a Task, select New Task
  11. Leave the optional Task Name blank and click the check mark to continue
  12. Click the + icon at the bottom of the screen to add an action
  13. Choose Plugin > SharpTools> Thing: Get Attribute
  14. Click the pencil icon to configure the SharpTools plugin
  15. Select the 'Thing' you want to check the status of
    Example: Bedroom Light
  16. Select the attribute
    Example: switch
  17. Press Apply
    Note: the names of the Tasker variables that will be set are displayed at this point
  18. Press the back button on your phone to save the SharpTools Action
  19. Click the + icon at the bottom of the screen to add another action
  20. Choose Alert > Say
  21. In the Text field, enter: The bedroom light is %st_attr_value
  22. Press the back button on your phone to save the Say Action
  23. At the bottom of the screen, press the play icon to test the Task
    Note: With Tasker 4.6+ you will see a play icon next to each Action in the task as it is executed
  24. Press the back button again to close out the Task Edit
  25. Press the back button one more time to back out of Tasker completely and ensure the profile becomes active

Other Thoughts:

This approach can be used to answer other queries like:
  • What temperature is the AC set to?
    • AutoVoice filter: What temperature is the AC set to
    • Thing: Downstairs AC
    • Attribute: thermostatSetpoint
  • Is the front door locked?
    • AutoVoice filter: Is the front door locked
    • Thing: Front Door
    • Attribute: lock
  • Did I leave the garage open?
    • AutoVoice filter: Did I leave the garage open
    • Thing: Garage
    • Attribute: contact or door or switch (depends on device type)
The same concept applies as was used in the instructions above. Simply swap out the AutoVoice filter for your updated query and replace the thing and attribute in the Thing: Get Attribute configuration. 

If you don't want to have the response spoken aloud, you might consider using the Alert > Notify or Alert > Flash action to have the result of the attribute query displayed on screen.

Many devices have several different attributes that may be of interest to you, so play around and see what's out there. For example, in addition to pulling in the thermostatSetpoint, you might also be interested in pulling in the thermostatMode to see if it is set to heat or cool.

Dynamic Queries

You can also use the `Thing: Get Attribute` plugin with variables to get the current status of many of your things at once or to use variables to get the status of a desired device. To do this, tap the tag icon in the top action bar to switch to variable mode. 

Once you have switched the plugin into variable mode, you can either directly enter a string into the fields or you can use a Tasker variable (eg. %device)

For example, if we wanted to setup a profile that allowed us to ask 'Is the [device] on?', we could change the voice query from above to use AutoVoice's RegEx feature to allow us to dynamically ask if a device is on using a query like:
  • AutoVoice Filter: (?<q>Is|Are) the (?<device>.+?) (?<onoff>on|off|on or off|off or on)
Note: Make sure the "Use RegEx" box is checked in AutoVoice when using this approach -- this will convert the funky groups in parenthesis to variables that get captured.

Then in the `Thing: Get Attribute` plugin we would use the following configuration:
  • Thing: %device
  • Attribute: switch
And finally, we could spit out the result using an action like Alert > Flash:
  • Text: The %device is %st_attr_values(1)


Important: When you are using `Thing: Get Attribute` in variable mode, the response changes from a set of single-value strings to a set of string arrays. 

When you are using `Thing: Get Attribute` for a single device (Eg. with the drop-downs), you'll get the following variables:
  • %st_attr_name
  • %st_attr_value
  • %st_thing_id
  • %st_thing_name
When you use `Thing: Get Attribute` in variable mode, you'll get the following variables (which are each arrays):
  • %st_attr_names()
  • %st_attr_values()
  • %st_thing_ids()
  • %st_thing_names()
For more information on variable arrays in Tasker, see the documentation linked below:

Troubleshooting:

  • Make sure you can manually toggle the desired device from the main SharpTools interface
  • Check the AutoVoice logs
  • Make sure the %st_attr_value variable is spelled correctly as it must be exact

Dim a Light

posted Dec 31, 2014, 12:37 PM by Joshua Lyon   [ updated Jan 10, 2016, 1:33 PM ]

This tutorial shows how to use the SharpTools Tasker Plugins (or Widgets) to dim a light in your SmartThings automated home.

Tasker

  1. Open Tasker
  2. Navigate to Tasks using the tab bar at the top
  3. Tap the + icon at the bottom to add a new Task
  4. Name the Task (for example Turn Upstairs Light On) and press the checkmark to continue
  5. Within the Task Edit screen, press the + icon at the bottom to add a new Action
  6. Select Plugin > SharpTools > A Thing
    Note: Older versions of Tasker did not have the application grouping and would be Plugin > A Thing
  7. Within the Action Edit: A Thing screen, click the pencil icon to modify the configuration
  8. Select the Dimmer Switch device type (or relevant dim capable device type)
  9. Select the desired device (for example, Upstairs Hall)
  10. Select the setLevel command
    Note: after selecting the setLevel command, parameter fields should become available
  11. Enter the following settings in the parameter fields:
    Parameter 1: 50 
    Parameter 2: 0 
    Note: Some devices, like GE Links, will only work with one parameter. See the notes below.
  12. Press Apply to save your settings
    Note: If prompted to unlock Tasker/Widgets, follow the prompt to either start the trial or perform the In-App-Purchase
  13. Press the back button to save your Task
  14. From the Task Edit screen, press the play icon at the bottom of the screen to test your Task
Setting up the Task is just one part of having a complete Tasker setup. Check out the Introduction to Tasker article to better understand how a Task fits with a Context or the Voice Control Things articles for an example. 

Widgets

Each phone/launcher has different ways to add widgets to your homescreen. This guide assumes the reader has knowledge of how to add a widget to their homescreen.
  1. Follow the steps for your launcher to pick a Widget/Shortcut to be added your homescreen
  2. Select the 'A Thing' widget
  3. Select the Dimmer Switch device type (or relevant dim capable device type)
  4. Select the desired device (for example, Upstairs Hall)
  5. Select the setLevel command
    Note: after selecting the setLevel command, parameter fields should become available
  6. Enter the following settings in the parameter fields:
    Parameter 1: 50 
    Parameter 2: 0 
    Note: Some devices, like GE Links, will only work with one parameter. See the notes below.
  7. Press Apply to save your settings
    Note: If prompted to unlock Tasker/Widgets, follow the prompt to either start the trial or perform the In-App-Purchase
Note: Many launchers display the list of widgets after a long press of the homescreen or within their app drawer. Several of the SharpTools widgets are actually shortcuts and some launchers, like Nova Launcher, group these separate from traditional widgets

Notes

  • Parameter 1 is the percentage we would like to dim to (eg. 50 = 50%)
  • Parameter 2 is the duration over which we would like to dim
    • Only certain devices actually accept this value. You must enter a value even if your device does not support dimming over a duration.
    • For an immediate dim or for devices that don't support dimming over a duration , enter 0
    • Some devices, like GE Link light bulbs, will only dim when using 1 parameter for setLevel
      • These devices still report that 2 parameters are required from SmartThings, so you must override the settings
      • From the 'A Thing' configuration screen, open the menu and check the box for 'Override Parameters'
      • You should now see 'X' icons show up to the right of each parameter field. Click the 'X' next to Parameter 2.
      • Follow the instructions above as normal, ignoring Parameter 2.
  • The device type must support the setLevel command to perform dimming
    • This is supported with the out-of-the-box Dimmer Switch types and the Better Virtual Dimmer device types.
  • Some custom launchers do not support adding a Shortcut widget (like those used with SharpTools). Make sure your launcher supports adding Shortcuts or use a launcher like the Google Now Launcher.

1-10 of 13