SmartThings Data Visualisation using InfluxDB and Grafana

This is awesome. I’ve been playing with this all weekend now, and i’m finally ready to shut off InitialState. THANKS

I had enabled authentication on my InfluxDB server since it’s on a publicly accessible host but forgot to restart it (or something) so all of a sudden today when it did restart unexpectedly my log started filling with authentication errors.
I didn’t look closely at the sample code for using httpPost before using it so if anyone else is hosting their InfluxDB server on a host outside your LAN this more complete code should work including authentication if you use it (and you should unless you want some internet goon to do terrible things with your database). The gist of the change is including the headers that have your authentication info in them with the call to httpPost().

def postToInfluxDB(data) {
logger("postToInfluxDB(): Posting data to InfluxDB: Host: ${state.databaseHost}, Port: ${state.databasePort}, Database: ${state.databaseName}, Data: [${data}]","debug")

//try {
//    def hubAction = new physicalgraph.device.HubAction(
//    	[
//            method: "POST",
//            path: state.path,
//            body: data,
//            headers: state.headers
//        ],
//        null,
//        [ callback: handleInfluxResponse ]
//    )
//	
//    sendHubCommand(hubAction)
//}
//catch (Exception e) {
//	logger("postToInfluxDB(): Exception ${e} on ${hubAction}","error")
//}

// For reference, code that could be used for WAN hosts:
def url = "http://${state.databaseHost}:${state.databasePort}/write?db=${state.databaseName}" 
try {
	httpPost(
    [
		uri: url,
        headers: state.headers,
        body: data
   ]) 
   { response ->
        if (response.status != 204 ) {
           log.debug "Response Status: ${response.status}"
           log.debug "Response data: ${response.data}"
           log.debug "Response contentType: ${response.contentType}"
        }
   }
} catch (e) {	
      logger("postToInfluxDB(): Something went wrong when posting: ${e}","error")
}

}

2 Likes

There has been mention of VPS hosting (AWS, Azure) but out of interest are there any others using other platforms/services?

In my case I’m just using a Linux based KVM slice from buyvm.net, their cheapest one since my requirements are minimal. I use it for other development stuff so it made sense to keep everything together for me.
InfluxDB does desire a huge amount of RAM for its original intended function of storing/processing large amounts of data. The trickle of info coming from SmartThings currently puts its memory usage at about 150MB so the 1GB slice I’m using should hold up fine for now.

1 Like

Interesting, I wasn’t aware of buyvm, I will check them out. I have put a test install on a base spec OVH VPS and it seems to be running okay. Only got 10Gb storage though so may need to upgrade (I also plan to run various other applications).

I have also added an internal/external option to the SmartApp to allow easier switching. Just need to add a set of settings for the group enumeration rather than having to add them manually each time, then I will get the modifications posted.

I am using the httpPost approach since my database is in the cloud. It is working fine. But it is throwing an error:

postToInfluxDB(): Something went wrong when posting: java.lang.IllegalArgumentException: Response does not contain data

Despite the error, everything is being sent to InfluxDB. So it is not a big deal. Just curious why this is happening.

Are there any specific steps to take when additional devices are added to the hub --to include them in influxdb / grafana?

Has anyone had luck running Grafana panels in ActionTiles? I have attempted to use the "Publish Snapshot link however these do not seem to stay up-to-date. Also, the snapshots do not display through the Full Kiosk browser on Amazon Fire tablets.

i really cant get this to work. I don’t even know where to start and look. I get no values to grafana, i can’t pick all attributes that should be, only a few is choosable. What could be wrong?

Thanks for this code! I will try installing it this weekend, but I was wondering what do you think the best option is for using a Windows Home Server box? Should I just virtualbox linux on it?

Thanks again!

I tried it on a virtual machine running Linux for a couple of months, but didn’t want to leave mi main pc 24/7 on. Ended up with a Raspberry Pi 3 flawlessly.

That’s exactly what I’m doing. I have it and my Ubiquiti controller running on the same Raspberry PI.

How many devices and graphs are you guys graphing? I’m worried my imp won’t run well on a PI I have so much going on.

Just an Aeon HEM (2 more to come), 5 contact sensors and a 3 PIR sensing temperatures.

1 Like

Are there any special considerations/configurations for running the SmartApp for two hubs at different locations in SmartThings? I setup the SmartApp for my home location, and it’s working great (hub and InfluxDB/Grafana server on the same network). I then setup another SmartApp instance on another location I manage using my public IP (this hub is remote) and credentials, enabled port forwarding for 8086. I am not seeing any data in the database, however.

I did a packet capture on the server, and for the hub that’s working I see it send an HTTP POST with /write?db=SmartThings. For the other hub, I don’t see any similar HTTP POST requests, only a FIN ACK once the TCP session is established.

Any ideas why the behavior would be different from different hubs?

Thanks

Looks like there is a section in the code specifically for WAN connections to InfluxDB. I uncommented out the section, and I am seeing data now.

// For reference, code that could be used for WAN hosts:

Im having a slight issue with power consumption logging. In Live log from ST IDE, the values are correct. However when they appear in the Influx database, 3 out of 5 devices seem to get converted:frowning:

300W would turn up as 3, and 200W as 2. Ive verified in the database with SELECT * FROM power, that the values are indeed 0, 1, 2, 3 instead of 0/100/200/300 watt.

Any ideas how to fix this? It was working when I set it up last week. Only thing Ive done since then is to rename some devices in ST.

EDIT: I renamed the devices with issues back to what they were previously named, and it now works again… Strange?

10 aeon multisensors (motion, temperature, humidity, light, battery)
7 switchs (status and power consumption)
2 sirens

Can anyone help with my query? I’m logging thermostatoperatingstate. I’ve got it graphing fine, but trying to make a single stat that shows runtime for the current interval.

This is the closest I can get but it displays 52 minutes. I have about 17 minutes of runtime displayed.

SELECT mode(“valueBinary”) FROM “thermostatOperatingState” WHERE “deviceName” = ‘Ecobee’ AND $timeFilter GROUP BY time($interval) fill(previous)

Seems like you want to do “Direct Link Rendered Image” instead of “Snapshot”.
It looks something like this (specifying the previous week of data):
http://play.grafana.org/render/dashboard-solo/db/grafana-play-home?orgId=1&panelId=4&from=now-1w&to=now&width=640&height=480&tz=UTC%2B02%3A00&timeout=5000

Then in ActionTiles, you add it as a “Media” item and select “This Media is a still image or GIF”

2 Likes