Blog Search Results for

How to Control Access to Connected Devices With Losant Go

Bao Nguyen
Bao Nguyen 7 minute read

Last week, we launched the Losant Go mobile app which makes your phone an IoT device. You can set up Losant Go to enable and disable workflows inside of Losant, which can have some practical uses. For example, you could limit your AirBnB renters to have access to your IoT devices only when you allow them. Or you could allow employees to access to the office during off hours.

The following tutorial will show you how to use the Losant Go app to enable and disable a workflow with notifications, walk you through setting up your workflow to check if it is active, and show you an example using SMS to trigger a physical device through IFTTT and Twilio.

Using the Losant Go app to enable/disable a workflow

If you have not setup the Losant Go app, download it on the App Store or Google Play. Follow the instructions for Auto Setup.

1.  Login to Losant.com, and navigate to the "Losant Mobile App" workflow.

view-applications.png

click-app.png

click-workflow.png

2. On the workflow, locate the "Get Value" node and drag it to the workflow and connect it to the "Debug" node.

You can do that by dragging the bottom of the "Debug" node to the top of the "Get Value" node.

drag-get-value.png

connect-node.png

3. In the properties tab, set the following values:

Label: "Get Enabled" (Optional. I like to do this for readability)
Value Identifier: "enabled"
Payload Path for Value: "data.enabled"
Default Value Type: "JSON" Default Value: 0

In this step, we are retrieving the current value of "enabled" and giving it a default value of 0 if it has not been set.

get-enabled.png

4. Drag the "Conditional" node to the workflow and connect it the "Get Enabled" node.

drag-conditional.png

5. In the properties tab, set the following values:

Label: "Toggle Enabled"
Expression: "{{ data.enabled }} === 1"

This checks to see if the "data.enabled" value is 1. If it is equal to 1, the workflow will take the right path (green diamond). If it is false, it will take the left path (red diamond).

set-conditional.png

6. Locate the "Store Value" node and drag it to the workflow.

drag-store-value.png

7. Connect the right side of the "Toggle Enabled" node to the "Store Value" node. In the properties tab, set the following values:

Label: "Disable"
Value Identifier:"enabled"
Value Type: "JSON" Value: 0

This toggles the "enabled" value to 0 if it is currently 1.

set-disabled.png

8. Click on the "Disable" tab, and copy and paste the node (cmd+c and cmd+v on mac). Connect that node to the left side of the "Toggle Enabled" node, and set the following values in the properties tab:

Label: "Enable"
Value Identifier: "enabled"
Value Type: "JSON" Value: 1

This toggles the "enabled" value to 1 if it is currently 0.

You can also drag another "Store Value" node on to the workflow, but I wanted to show you a shortcut

set-enabled.png

9. Click "Deploy Workflow".

click-deploy-workflow.png

Now, your workflow is ready to test. You can view the "enabled" value in the storage panel.

storage-panel.png

Open up the Losant Go app, and tap the Go button. If you click refresh, you will notice that the value will show up as "1". If you press the button again, and click refresh, you will notice that this value becomes "0".

refresh-button.png

enabled-1.png

enabled-1.png

At this point, your Losant Go button sets the enabled value to 0 (for disabled) or 1 (for enabled).  It would be nice if you could receive a notification when the workflow was disabled or enabled.

Integrating Twillio for notifications

First, we’ll setup notifications. To do this. I will be using Twillio. You can sign up for a free account to test this. Go to www.twillio.com to create your account. Follow the steps on Getting Started to obtain a phone number. Once you get that information, you should have what you need to integrate Losant with Twillio.

1. Locate the "Twillio" node, drag it to the workflow and connect it to the "Enable".

drag-twillio.png

2. Click on the "Twillio" node and set the following properties, which were obtained through the Twillio account setup:

Label: "Enabled Msg"
Twillio Account SID: (Your SID)
Twillio Auth Token: (Your auth token)
From Template: (Your assigned Twillio number)
SMS Message Template: "Your workflow has been enabled"
To Number Template 1: (The number you want to be notified at. I used the same number as the phone with the Losant Go app)

twillio-enabled.png

3. Copy and paste the the "Enabled Msg" and connect it to the "Disable" node.

copy-twillio-disabled.png

4. Set these properties on that node:

Label: "Disabled Msg"
Twillio Account SID: (Your SID - Should be the same)
Twillio Auth Token: (Your auth token - Should be the same)
From Template: (Your assigned Twillio number - Should be the same)
SMS Message Template: "Your workflow has been disabled"
To Number Template 1: (Should be the same)

twillio-disabled.png

5. Deploy the workflow.

Now, when you tap the Go button, you should receive a notification with the enabled status of your workflow.  However, there’s still some more work to do for your workflow to know how to use this.

Setting Up your Workflow

Now, let’s setup your workflow to acknowledge this enabled state. Since we have a Twillio account already setup, let’s use that to trigger a workflow via a webhook.

1. Click "Webhooks" in the navigation.

click-webhooks.png

2. Click on "Add Webhook".

add-webhook.png

3. Give your webhook a name. "Twillio Webhook" is what I chose.

name-webhook.png

4. Click "Save Webhook".

save-webhook.png

5. Navigate back to your Workflow editor, and drag the "Webhook" node onto the Workflow.

drag-webhook.png

6. Set the following properties on the "Webhook" node:

Label: Twillio Webhook (Optional)
Make sure that the "Twillio Webhook" is selected in the dropdown

set-webhook-properties.png

7. Copy and paste the "Get Enabled" node.
Connect it to the "Twillio Webhook". We can leave all these settings the same, but you can ensure that the properties are the following"

Label: "Get Enabled" (Optional. I like to do this for readability)
Value Identifier: "enabled"
Payload Path for Value: "data.enabled"
Default Value Type: "JSON"
Default Value: 0

copy-get-enabled.png

8. Drag the "Conditional" node the workflow, and connect it to the "Get Enabled" node

drag-conditional-webhook.png

9. Set the properties of the "Conditional" node to the following:

Label: isEnabled Expression:  === 1

This node checks to see if the workflow node is enabled. If it is enabled, it will take the path to the right. For testing purposes, we’ll use a debug node and a virtual button to check if it works.

set-conditional-workflow.png

10. Drag a "Debug" node to each side of the conditional to output both states. Enter the following properties for the disabled state:

Label: Debug Disabled (Optional)
Message: Workflow Disabled

debug-disabled.png

11. Enter the following information for the enabled debug node.

Label: Debug Enabled (Optional)
Message: Workflow Enabled

debug-enabled.png

12. Drag a "Virtual Button" to the workflow and connect to the the "Get Enabled" node.
This will allow you to test the workflow without calling the Twillio Webhook.

drag-virtual-button.png

13. Deploy workflow.

When you click on the "Virtual Button", it will trigger the workflow. Click it, and check the "Debug" panel. You’ll notice that it will show the current state of the webhook.

Now, toggle the workflow enabled state by tapping the Losant Go button again. After toggling the status of the workflow, click the "Virtual Button" again, and check the debug panel. You’ll notice that it will show that the workflow took the other path.

debug-output-disabled.png

Now, let’s make the workflow do something useful. You can have your workflow connect to IFTTT using by calling a webhook. If you connect to IFTTT, you can have it control many devices like a dryer, oven, or garage door. In my case, I’m going to have my workflow connect to IFTTT to toggle a WeMo Insight Switch connected to a light.

Connecting your workflow to IFTTT

First, go to IFTTT.com and create an account. Once you create your account, do the following:

1. Click on "My Recipes".

click-recipes.png

2. Click "Create Recipe"

create-recipe.png

3. Click "This".

ifttt-this.png

4. Search for the "Maker" Trigger and click on it.

ifttt-click-maker.png

5. Click "Receive a web request".

ifttt-click-receive-web.png

6. Type "toggle_switch".

ifttt-type-toggle-switch.png

7. Click "That".

ifttt-click-that.png

8. Search for "Wemo insight switch" and click on it.

ifttt-wemo-insight-switch.png

If you have not connected your Wemo Insight Switch to IFTTT, you can follow the on screen steps to connect it. Once it is connected continue to the next step

9. Click "toggle on/off".

ifttt-toggle-on-off.png

10. Select your WeMo switch from the dropdown list and click "Create Action"

ifttt-create-action.png

11. Click "Create Recipe".

ifttt-create-recipe.png

At this point, IFTTT is setup, but you’ll need to locate the url for the workflow.

12. Go to https://www.ifttt.com/maker and click on "How to Trigger Events".

ifttt-how-to-trigger.png

13. Copy the line at under "Make a Post or Get web request to", and replace {event} with "toggle_switch".
Paste that line somewhere that you can access later.  It should look something like this:

https://maker.ifttt.com/trigger/toggle_switch/with/key/{key set by IFTTT}

You will use this line to insert into your Losant workflow

ifttt-webhook-url.png

14. Go back to your Losant Workflow. Drag the "http" node to the workflow and connect it to "Debug Enabled".

This will make a GET request to trigger the IFTTT recipe.

drag-http.png

15. Set the properties of the "HTTP" node to:

Label: Call to IFTTT (Optional)
URL Template: (url that you copied above)

set-ifttt-properties.png

16. Click "Deploy Workflow"

Now, you should be able to test this using your "Virtual Button". Be sure to enable your workflow using the Losant Go button. When you click your "Virtual Button", your light should turn on or off each time you click the button.

Finally, let’s give some one the ability to text message a number to toggle the switch.

Trigger your workflow by SMS

1. Log back into twillio.com.

2. Click on the Three Dot icon.

twillio-click-three-dot.png

3. Click on "Phone Numbers".

twillio-phone-numbers.png

4. Click on the phone number that you used earlier.

twillio-click-number.png

5. Go to your Losant Workflow and click on the "Twillio Webhook" node.

click-twillio-webhook.png

6. Click on "copy" to get the Losant webhook url.

click-copy.png

7. Paste that in the "Messages" > "A message come in" box.

This passes your Twillio payload over to the specified URL, which in this case, is your Twillio Webhook.

twillio-losant-webhook.png

8. Click Save.

twillio-save.png

Now when someone sends you a text to your twillio number, it will toggle the switch. And if you tap your Losant Go button, it will disable the sender's ability to toggle the switch. You can go one step further and make the sender text you a passcode to toggle the switch, but I’ll leave that up for you to try out.

What other ways are you using Losant Go to control access to connected devices? Love to hear about it in comments below!