Use Microsoft Flow and webCoRE to Log SmartThings Data

January 14, 2019

In this article, we'll go over how to integrate Microsoft Flow with webCoRE and have data captured from SmartThings logged into a Google Sheets spreadsheet.  In order to continue, you should have the following:

  • Samsung SmartThings hub with sensors already added
  • webCoRE installed and running
  • A Microsoft account

Let's get started!

Microsoft Flows

First, let's open Microsoft Flow and login.  From the dashboard, we'll click on My flows > New > Create from blank.

On the next page, click Create from blank (yes, again).  Now, you'll be asked to search for a connector or trigger.  We'll search for http request and select the When a HTTP request is received item under Triggers.  Under Show advanced options, we'll specify POST for the method.

Don't forget to fill in the sample payload or click on Test (top right) and then click on I'll perform the trigger action.  I prefer to click Test and execute the API call.  Flow will turn the JSON that it receives into variables that you can drop into future actions.

Once added, we'll click on New step and add the Current time item.

Click on New step once more and select Convert time zone.  We'll set the following but feel free to tweak as you wish:

Last but definitely not least, we'll click on New step and select Insert row (Google Sheets).  Once logged into Google Drive, you can browse for any Google Sheets document that you have already created and select it.  From there, you can select your worksheet of choice.  As you can see, I have filled in the columns by clicking on the input box and selecting either Converted time or the See more button and then the variables from our HTTP request.  If you don't see any variables here, make sure that you've either filled in the sample JSON payload in the When a HTTP request is received step or that you've clicked Test > I'll perform the trigger action and then called the API.  Doing so creates these variables that you can plug into each cell.

Now, click Save.  Once saved, an HTTP POST URL is generated and is shown on the When a HTTP request is received widget.  Copy that URL - we'll need it in the next section.

webCoRE

Browse to your webCoRE instance and create a new piston.  Then, select Create a blank piston.

Here is the bulk of the required code.  This will call our webhook which will kick off our Microsoft Flow, flow.  Please be sure to replace the webhook URL with the URL that you copied from Microsoft Flow above.

execute
every other hour, at :30 past the hour
do
Set variable {bathroomSinkTemperature} = Bathroom Sink Water Leak Sensor's temperature;
Set variable {bathroomToiletTemperature} = Toilet Water Leak Sensor's temperature;
Set variable {upstairsPorchDoorTemperature} = Upstairs Porch Door's temperature;
Set variable {laundryRoomTemperature} = Kitchen Door's temperature;
Set variable {diningRoomTemperature} = Nest Thermostat - Dining Room (Home)'s temperature;
Set variable {sideDoorTemperature} = Side Door's temperature;
Set variable {frontDoorTemperature} = Front Door's temperature;
Set variable {kitchenSinkTemperature} = Kitchen Sink Water Leak Sensor's temperature;
Make a POST request to https://webhook-url-goes-here with JSON encoded data {bathroomSinkTemperature,bathroomToiletTemperature,upstairsPorchDoorTemperature,laundryRoomTemperature,diningRoomTemperature,sideDoorTemperature,frontDoorTemperature,kitchenSinkTemperature};
end every;
end execute;

Once done, test it out!  If it successfully runs (the piston and the flow), you should see a new row in your Google Sheets spreadsheet:

Note
If you have a free Microsoft account, you only get 750 flow runs per month. You can check your usage by clicking on the gear next to your name on the top navbar of Flows. I have noticed that the count is delayed and takes a while to update.

©2024 Tyler Wright