Hubitat + InfluxDB + Grafana Howto [Ubuntu Linux]

You are right.

I have tested with a virtual temperature sensor. I have set values from 1-10, then incremented by 5 up to 50.

The values all showed up in Grafana but with delays. Values from 0 to 30 where shown first then the rest. I think the events are sent to InfluxDB at the polling rate which in this case is 1 minute. Am I right?

Lets be clear there are two settings.

One is soft polling. That is how often InfluxDB will ask HE what the value is for given attributes for devices it tracks and write to InfluxDB. This can be important under certain circumstances to make sure you have something in the db at given intervals. This has nothing to do though with getting event driven changes into InfluxDB from HE.

The second value is how often to write to the DB. This value basically just tells influxdb logger how long to wait before posting events to the database unless the queue gets full. This doesn't effect the time of the event as that is part of the data that is queued. If a device changed 3 times in one minute all 3 events would be posted when that 1 min was up. It may take 1 min for new data to appear, but the values will reflect what happened in that interval and when in that interval.

Technically you could set the polling interval to 0 and just turn polling off completely. Depending on what and how you graph that may be fine.

The default code allows the queue to get to 100 before it forces a write to the Influxdb server. You can easily change that to a different number, or just 1 if you like. That number is there though to help reduce overall load. I have tweaked that number a few times to see if i could improve load. What i found worked best was setting the write to db value to 1 minute.

1 Like

To anyone needing help making this work on InfluxDB 2.X+, I edited the original app to include an API token section. Leave the username/password blank, but add an API token from your InfluxDB (create a token, then it should begin working.

Here is the updated Github link:
https://raw.githubusercontent.com/jaondayko/InfluxDB-Logger/master/influxdb-logger.groovy

1 Like

This is what i have achieved so far. Setup is working pretty good.

1 Like

Nice dashboard! What UPS do you have? I run a backups pro 1500 with a external 12v battery but it's a pain pulling stats from it.

Thank you,
APC RT1000 with network management card.
Use kahn-hubitat's app. It works like a charm. I have previously used a Raspberry Pi to get data from the UPS but this is way easier.

2 Likes

I have a small problem with InfluxDB Logger. When i add any device or modify a setting and hit done it loads forever. It does the job, but i don't like that i have to force the exit from the app's page. Does anyone have the same issue? I think it is related to the hub but triggered by this app.

Also, added some features to the dashboard.

I am still not convinced about the refresh rate sync between the devices and the database. At some point UPS Output was higher than UPS Input. The gauges should show values in real time, but if the refresh rate is not equal you might get wrong values.
Example:
The APC app has a refresh rate of 2 minutes. It is not recommended tot set it lower.
The Smartthings Outlet has a refresh rate based on power change of 10 watts, so it is faster if the value changes with more than 10 watts.

Opera Snapshot_2022-09-18_081957_192.168.1.12

Graph looks ok.

v 1.2 - changed from *mean to *last . Hope this solves some of the issues.

Hi @jaondayko1 I tried your modification, and I cannot get this to work with an InfluxDB2 Bucket. I suspect that it is because the Organisation is not defined?

I found Konnichy (GitHub - Konnichy/SmartThings-codersaur: Samsung SmartThings SmartApps and Device Handlers) modified the original SmartThings version to work with v2, and his version calls the Organisation. Sadly, I'm not clever enough to convert his version to work on Hubitat, or diff/merge any differences from his to yours.

Have you got this working on an InfluxDB2 setup? The error I get in Hubitat logs is:

postToInfluxDB(): Something went wrong! Response from InfluxDB: Status: 404, Headers: [X-Influxdb-Build:OSS, X-Platform-Error-Code:not found, X-Influxdb-Version:2.1.1, Content-Length:54, Date:Sat, 15 Oct 2022 15:07:28 GMT, Content-Type:application/json; charset=utf-8], Data: null

That looks like it cannot find the database to write to (Hence I think missing the Org)?

Edit - worked it out. The code is now using Async, so around line 811 in the code you need to make sure the writedb code is update to read

uri: "http://${state.databaseHost}:${state.databasePort**}/api/v2/write?org=${state.databaseOrg}&bucket=${state.databaseName}",**

1 Like

Glad you got it to work. I'm currently trying to figure it out as well.

A detail question -- is "Database" in the HE app synonymous with "Bucket" in InfluxDB? I'm not sure what to enter for Database in the logger app within HE. Any help is appreciated!

Yes, database is bucket.

1 Like

I'm using InfluxDB 2 also, so I applied @jason12's async change to the version posted a few posts above by @jaondayko1. But I still get the below error in the HE log from Influx. Anyone have any ideas?

postToInfluxDB(): Something went wrong! Response from InfluxDB: Status: 404, Headers: [X-Influxdb-Build:OSS, X-Platform-Error-Code:not found, X-Influxdb-Version:v2.4.0, Content-Length:69, Date:Tue, 18 Oct 2022 18:50:33 GMT, Content-Type:application/json; charset=utf-8], Data: null

That suggests it can't find your bucket. Have you put in the right organisation?

Hmm, is there a place in Influx where you assign a bucket to the org? I can see from the Influx web interface that I'm logged on my org. And my org has a bucket in it called hubitat_events that I have put into the Database field of the HE app. The host IP and port are correct--I've triple checked that. I've left the Username and Password blank, per instructions above in the thread, and then pasted in the API Token (not the Bucket ID) under "Database Auth Token". Then I picked a handful of HE devices that are definitely generating events.

Anything jump out as wrong?

Edit: also, just to be sure, I deleted and recreated the logger app in HE. When I did, I saw a new error message in the HE log: errorjava.lang.RuntimeException: java.sql.SQLException: Values of types "BOOLEAN" and "INTEGER" are not comparable; SQL statement: SELECT COUNT() FROM EVENT_SUBSCRIPTION WHERE FILTER = ? AND HANDLER = ? AND INSTALLED_APP_ID = ? AND SUBSCRIBED_INST_APP_ID = ? [90110-214] Query: SELECT COUNT() FROM EVENT_SUBSCRIPTION WHERE FILTER = ? AND HANDLER = ? AND INSTALLED_APP_ID = ? AND SUBSCRIBED_INST_APP_ID = ? Parameters: [0, handleAppTouch, 1924, 1924] on line 881 (method updated).

Does your hubitat logger have an option to define the Org? If not, then that is the problem - the org needs to be defined in Hubitat. I must have added it in. If you aren't defining the org in the app code you need to add it in.

You could try merging these commits into your version:
InfluxDB2.x support by Mavrrick · Pull Request #21 · HubitatCommunity/InfluxDB-Logger · GitHub

But make sure the change in the // Hubitat Async http Post section (around line 812) I said is also made. Clearly I went round in circles and ended up making changes I hadn't remembered I needed to do to make it work!

1 Like

That did the trick. You are my hero. Thank you thank you thank you.

@andutgv Are you still running this from a Pi ? And if so. Are you using the local SD card storage or connected a proper drive to the pi for the influxdb data ?

Yes. But i mounted an SSD as a drive. Works flawless since 3 months ago.

1 Like

Just anycase anyone watching this thead isn't aware the InfluxDB Logger just got updated and includes support for Influx DB instances using both v1 and v2 versions of the database. It also supports TLS which means you can use this with a Free Influx Cloud account. There are also further updates coming that will improve performance like adjusting the Write Queue Limit and adjustments to a few methods that improve performance considerably when creating the batch to post to InfluxDB.

2 Likes

is there any clean walkthrough of setting up HE with InfluxDB and Grafana using docker on a SynologyNAS? I spent like an hour on it today and couldn't get it working... Not sure what I'm missing - i get 400 errors (unauthed) in my HE logs.