SmartThings Data Visualisation using InfluxDB and Grafana

This is what I have been looking for in Grovestreams/Initial State, but done the way I want it… I love hosting this on my own system. It just works out so much nicer for me.

I am having an issue with motion sensors though. I’m seeing motion events pushed in the InfluxDB Logger within the IDE, but I’m unable to see any changes within Grafana.

My interval in the SmartApp is set to five minutes. Any way I can decrease the interval so that quick status changes on devices will reflect within the graph?

My long term goal is to track how often the cats are setting off motion sensors, and then move the sensors to a better spot or change the rules to ignore the cats.

There should be no need to do this. Whenever a device generates an event (i.e. because the value of an attribute has changed) the SmartApp will forward it to InfluxDB. The polling interval is only required to send values to InfluxDB for attributes that don’t change very often and hence need extra data-points for Grafana to chart.

If you can see the data points in InfluxDB then it seems like your issue is with the queries in Grafana, in particular the Group By clause. Check if you are grouping by time().

Thanks! I finally got around to making some tweaks, and I’m now able to see the changes in presence.
I’m still working on motion though.

Hello. I found this project in another thread’s post by @michaelahess. Interesting!

I’ve been looking for an excuse to get a Pi. But, as a Linux novice, I could use a little guidance before I dive in. Thanks in advance for any help.

What would be the cheapest Pi that would work for this?

With a barely functional knowledge of the Linux CLI and how packages are installed, how difficult will it be for me to follow @zcapr17 's recipe? Put another way, should I expect a number of hiccups peculiar to my configuration that will be difficult for me to interpret and repair?

Thank you.

I run a virtualbox virtual machine on my primary PC, this runs Ubuntu which is a pretty simple download and install process documented all over the web. The instructions @zcapr17 provided where enough to get me up and running, without any difficulty. I’m seasoned on linux, but I think it was straightforward enough for anyone to get it working.

Running on a Pi might take additional effort in resolving dependencies on Raspbian, but I’d think it should work very well on the Pi 2 or 3. Not sure I’d try to run it on anything less. You’ll want a fast SD card for the database though. I have roughly 120 devices, after about 9 months the database is just shy of 300MB, so it doesn’t have to be large, just fast.

I would be curious to hear if anyone else has run this on a Pi and their experience.

I installed on a pi 3 running Raspbian last week it was not easy due to the dependencies and CPU architecture but got there in the end. Hopefully I can go though the bash history and make a tutorial for the Pi install

3 Likes

@zcapr17 This is awesome and works great! I also have an issue with apostrophes in the device name. Obviously it’s better to use the device ID anyways so that’s what I’m doing. It definitely looks to be a Grafana issue because the data makes it into InfluxDB just fine. I’m running Grafana 1.1.1. The error in Grafana is:

{
"error": "error parsing query: found s, expected ; at line 1, char 69",
"message": "error parsing query: found s, expected ; at line 1, char 69"
}

The query it’s trying to make it:

SELECT max("valueBinary") FROM "switch" WHERE "deviceName" = 'Cole's Bedroom Light' AND time > now() - 12h GROUP BY time(5m) fill(null)

This looks like a bug with Grafana (it doesn’t automatically escape apostrophes). You’ll need to escape the apostrophe in the SELECT query using a backslash. Try:

SELECT max("valueBinary") FROM "switch" WHERE "deviceName" = 'Cole\'s Bedroom Light' AND time > now()

Would anyone mind sharing their dashboard JSON code? Really don’t want to creat one from scratch.

Each use case is very different so that may not be effective. It’s really easy once you follow the basic tutorial in that post. The hardest part is documenting which device ID goes to which device, I keep a spreadsheet with that relevant info. Here’s the config for an “all” graph for one variable.






And a combo with x and y overlaid.


So I had my temp sensors reporting last night when I was setting this up, and this morning they just stopped. I have “no data points” on my graph.

the Smart App is working as i can see data in the Influx logger

InfluxDB is working as I can see all my measurements “SHOW MEASURMENTS”

I can’t also see other measurements such as “BATTERY”

The only thing that isn’t making sense to me is that I have TWO input fields to the right of FROM before WHERE. I have had too much to drink right now, so I can’t take a screenshot, but where you

Here is my code:

SELECT mean(“value”) FROM “temperature” WHERE $timeFilter GROUP BY time($interval), “deviceName” fill(previous)

Alias by: $tag_deviceNAME // Format as: Time Series

I’m not new to ST, but I am a bit of a rookie on this whole DB/Grafana stuff, but I know the basics and concepts.

Cheers.

I got this all setup and working on a Raspberry Pi3 last night. Seems to be working great, but sometime during the night I started getting a bunch of holes in my power graph.

Then it seems to look worse when I zoom in. The big holes are almost exactally 2 minute windows. During those zero values I can watch realtime logging and am seeing ST sending proper readings.

Any ideas what could be happening?

My HEM reports to the hub every 15 seconds. Could that be too fast? CPU/Disk utilization seems fine on the Pi…

[EDIT]
For whatever it’s worth, I disabled the temp/humidity sensors and my power graph looks much better. Still an occasional dropout.

Under Display (graph settings) do you have Stacking and Null value set to Null value=Connected?

I did, and that fills the holes in…

I plan on turning that on eventually for asthetics. Just wanted to make sure this wasn’t some simple fix that I’m missing first.

So I turned off logging of all other sensors and the graph looks a lot better. I’m going to set my power monitor to report less often, and turn the other sensors on then see what happens…

just got versions of grafana and influx for windows… will try getting it working there. .let you know

2 Likes

What, what!! When did those get released?! :nerd_face:

I’ve been trying to get this going for the last two days and something is broken somewhere. I should start by saying I am a complete novice when it comes to Linux OS. I have Ubuntu running on a virtual box and I have the InfluxDB and Grafana servers running there. I can pull up both of them on a web browser. My SmartThings IDE logs show the info going to InfluxDB, the database I created shows up in Grafana. But when I go into the dashboard on Grafana and select the database as the datasource, there is no data to choose from. On InfluxDB, if I query “show measurements”, there is no data. So I have to assume that Influx and Grafana are talking to each other fine, but something is broken between SmartThings and InfluxDB. Any idea where I should be looking?

I’m having the exact same issue as jbhugh…
Running an ubuntu ec2 instance on AWS.
influxdb is running, 8086/8083 ports are accessible to the world.
I can run a “tcpdump -i eth0 port 8086” and I see the data from ST hitting the server, but it’s not dumping it into influxdb.
I’m a unix sysadmin, so I’m very familiar with unix/linx OS’s.

Any ideas?

Just to make sure influx is working, I ran this from a remote workstation and it did process the request:
curl -POST http://<IP_Masked>:8086/query --data-urlencode “q=CREATE DATABASE foofoo”

Connected to http://localhost:8086 version 1.2.1
InfluxDB shell version: 1.2.1

show databases;
name: databases
name


_internal
SmartThings
foofoo

Well, not sure what I did, but for some reason now it seems to be working. Pretty coo!
Thanks for the code!

I fixed my issue… Sometimes you just have to step back and think about what it is you are trying to do. I realized that the IP address I put into the settings of the smart app was for my ‘Host’ computer and that the virtual server likely had a different IP. So I did some digging into the Virtual Box and set up port forwarding from the host to the virtual server and all is well.