Trending & Analyzing SmartThings Devices (Part 3 of 4)

Table of Contents

Publishing Custom SmartApps

To deploy a custom SmartApp, you first need to login to SmartThings Graph. Be sure to login with the same account that you use to login to the SmartThings app on your phone. I originally setup my SmartThings hub using a separate account than the individual user accounts for the app. This caused issues when publishing apps, since the user that publishes the custom SmartApp via Graph is the only user that can install the SmartApp using the iOS or Android app. It sounds, confusing (and it can be), but we'll walk through it all here.

Once you've logged in, navigate to "My SmartApps" on the top navigation.

There's a number of ways to add SmartApps to SmartThings. The easiest is to copy and paste the code of a SmartApp as a new app. In a future post, we'll actually connect SmartThings to GitHub so that we can publish our own apps in a more robust way, but we'll follow a crawl-walk-run mentality here and introduce these concepts slowly.

Click the "New Smart App" button at the top right, then click the "From Code" tab. You'll be presented with a screen like the following.

Into the white code box, paste the following script, then click the "Create" button.

Credit where credit is due. This SmartApp was originally created by David Lomas and is also available at his github repo. I've posted it on my own repo due to the requirement that the script be configured for your specific SmartThings groups, which I'll explain below.

Once you've clicked "Create", you should see a message that the "InfluxDB Logger" SmartApp was created.

This SmartApp is a little special, because we want to be able to report what SmartThings Groups our devices are a member of when we send the data to InfluxDB. This allows us to slice and dice our data using the Group, so if we had 10 outlets in one room, and those outlets were all part of a group, we could trend the power usage for that room.

Unfortunately, a limitation exists in SmartThings today that prevents a SmartApp from querying the group names. This means we need to manually set the group names in our SmartApp, and update them any time we create a new group.

From the navigation at the top of the screen, click "My Locations", then click the name of your location. If you scroll down, you should see a section called "Groups" that contains a list of your groups.

For each of these groups, click the group and make note of the group name, and the group ID. The ID can be found by looking at the URL of the group page. As an example, my Office group has an ID of 40cf3ca5-a8c0-48d7-aa29-934e8fe46e21.

Once you've made a list of all your groups and their IDs, click "My SmartApps" again to go back to the SmartApps list.

Click on the InfluxDB Logger SmartApp, and scroll all the way to the bottom of the code until you see the group listing, and add each of your groups so they look like the following.

Finally, click "Save", and then "Publish" -> "For Me". Verify that you see a "SmartApp published successfully" message.

Installing Custom SmartApps

Now that the custom SmartApp has been published, we can install and configure an instance of it. The act of publishing simply makes the SmartApp available for use within your SmartThings environment.

From your SmartThings app, navigate to "Automation", select "SmartApps", and click "Add a SmartApp".

At the bottom of the list, tap "My Apps".

You'll now see the "InfluxDB Logger" SmartApp that we just published. Tap it, and we'll install an instance of this app and configure it.

Enter the static IP for your InfluxDB server in the Host field, and leave the port set to 8086. In the Database Name field, enter the name of the database we created, SmartThings. Since we didn't setup authentication to InfluxDB, we don't need a username or password, so leave those blank.

The Soft-Pooling Interval allows you to define a period of time (in minutes) that the InfluxDB Logger SmartApp will poll all of the selected devices for their status/values and send that data to InfluxDB. This soft-poll happens in addition to state changes, which are automatically sent to InfluxDB.

Lastly, we need to select the devices that we want to monitor and report to InfluxDB. Select all of the devices you want to monitor, then scroll down and enter a name.

When you're finished with your configuration, tap "Done", and you should now see your new InfluxDB Data Monitoring app on your SmartApps list. This SmartApp is now running and sending data to InfluxDB for the devices you selected.

There's a number of considerations for selecting devices to report status on. Due to the fact that you can install multiple instances of a SmartApp, it's possible to create another instance that contains different devices with a different soft polling interval. This is useful if you want to see more granular data for different types of devices. As an example, maybe you want your energy meter devices to report their power consumption every minute, but you only want thermostat temperatures to be reported every 15 minutes.

Validating Data Connectivity

Now that we've published the SmartThings SmartApp, installed an instance of the SmartApp, and connected it to InfluxDB, we can now confirm that InfluxDB is receiving data from the SmartApp.

After going back to the InfluxDB server and running influx to enter the InfluxDB Shell, we can now run USE SmartThings to connect to our SmartThings database, and then run a simple query like SELECT * FROM water to display any water sensors that we selected for monitoring. Obviously what you check for here will vary based on the devices you selected. If we see data returned, we know that everything is working.

Next Steps

We've now deployed a custom SmartApp, configured it for our groups, selected the devices we want to monitor, and connected it to our InfluxDB server. In part 4 we'll install Grafana and create our first dashboard to help analyze the data we're collecting.