Influxdb and Grafana

Short description of how to export data from Homey to influxdb using homeyscript.

There is no available apps for exporting to Influxdb at the moment. Luckily the influxdb API is a very simple HTTP API.

If you are able to use prometheus.io instead of influxdb, you should consider that, as there is an app supporting export to prometheus.io.

What I did was to create a homeyscript that takes a few argument separated with ;. The parameters are:

  • Name of the measurement. I use names like temperature, motion, logic

  • Name of the device

  • A group name (to group devices, like room)

  • The measured value.

The influxdb.js script goes like this:

let a = args[0].split(',')

let measurement = a[0].trim()
let device = a[1].trim()
let zone = a[2].trim()

let value = a[3].trim()
if (isNaN(value)) {
    value = '"' + value + '"'
}

fetch("http://influx.yourhostname.com:30369/write?db=homey", {
    headers: {
      'Accept': 'application/json',
      'Authorization': 'Basic xxxxxxxxxxxxx' // fill in with your credentials
    },
    method: "POST",
    body: body
}).then((response) => {
    console.log(response)
})

return true;

Remember to update the credential parts. Your username, colon, your password, base64 encoded.

I use one flow for temperature change, power change, humidity change. For logic variables, its not that easy. I have to use one flow for each Logic variable. If you use better logic, you would not need that and one flow to catch all logic would be sufficient.

Here is an example of a flow:

As the flow has generated data over some time, you may start to create grafana dashboards.

For keeping track of logic variables that changes over time, check out the Grafana discrete panel.

Questions for you.

  1. As you can see in the discrete panels above, it will not know the "start" value until the first value changes. Any ideas how to fix that? May be tweak the query to fetch data for a few more hours back in time? I've not managed to get this working yet, let me know if you make it work.

Last updated