Home Assistant Add-on: InfluxDB v2

Add-on: InfluxDB v2

InfluxDB v2 in Home Assistant, almost just like the Home Assistant Community Add-on: InfluxDB.

InfluxDB v2 is an open source time series database optimized for high-write-volume.
It’s useful for recording metrics, sensor data, events,
and performing analytics. It exposes an HTTP API for client interaction and is
often used in combination with Grafana to visualize the data.

InfluxDB v2 comes with its own admin interface for managing your users, databases,
data retention settings, and lets you peek inside the database.

Installation

The installation of this add-on is pretty straightforward and not different in comparison to installing any other Home Assistant add-on.

  1. Click the Home Assistant My button below to open the add-on on your Home
    Assistant instance.

    Open this add-on in your Home Assistant instance.

  2. Click the “Install” button to install the add-on.

  3. Start the “InfluxDB v2” add-on.

  4. Check the logs of the “InfluxDB” to see if everything went well.

Configuration

Note: Remember to restart the add-on when the configuration is changed.

Currently only supports HTTP and limited configuration options. SSL/TLS & other options are in the backlog.

Example add-on configuration:

Ports:
  - InfluxDB server: 8086 (8086/tcp)

Integrating into Home Assistant

The influxdb integration of Home Assistant makes it possible to transfer all state changes to an InfluxDB database.

You need to do the following steps in order to get this working:

  • Browse to http://{{ HOME_ASSISTANT_URL }}:8086 (replace {{ HOME_ASSISTANT_URL }} with the address to your home assistant installation)
  • Go through the onboarding process by creating a default user, password, organization and bucket.
  • Save the operator token for future use. Note: It’s best to create a separate user and token to be used in home assistant. Operator token has unlimited permissions to your InfluxDB installation.

Now we’ve got this in place, add the following snippet to your Home Assistant configuration.yaml file.

influxdb:
  api_version: 2
  ssl: false
  host: a0d7b954-influxdb
  port: 8086
  token: GENERATED_AUTH_TOKEN
  organization: RANDOM_16_DIGIT_HEX_ID
  bucket: BUCKET_NAME
  tags:
    source: HA
  tags_attributes:
    - friendly_name
  default_measurement: units
  exclude:
    entities:
      - zone.home
    domains:
      - persistent_notification
      - person
  include:
    domains:
      - sensor
      - binary_sensor
      - sun
    entities:
      - weather.home

Restart Home Assistant.

You should now see the data flowing into InfluxDB by visiting the web-interface and using the Data Explorer.

Full details of the Home Assistant integration can be found here:

https://www.home-assistant.io/integrations/influxdb/

Known issues and limitations

  • No SSL.
  • This InfluxDB v2 addon currently does not support Home Assistant web access, in other terms the ingress. Reason is that InfluxDB v2 does not support path-based reverse proxies, leading to technical challenges.

FAQ

Migrating from InfluxDB v1 to v2 (intermediate difficult level)

To migrate from InfluxDB (hass community addon), easiest is to use Advanced SSH & Web Terminal
addon with Protection mode disabled. You’re then able to execute docker commands with elevated permissions.

Please note: Using the following mentioned methods may impact and/or destroy your entire Home Assistant installation if you don’t know what you’re doing. Please take appropriate precautions like backups and reading up on the machanics before proceeding.

docker ps -a # Descibe the containers running and finding the Ids.
docker exec -it {{ addon_xxxxx_influxdb }} /bin/bash # Enter the v1 container. Replace addon_xxxxx_influxdb with the v1 Id
influx_inspect export -database homeassistant -retention autogen -out /data/exports/influxdb -lponly -datadir /data/influxb -waldir /data/influxdb/wal # Export the influxdb timeseries data
exit # Exit container to host
docker cp {{ addon_xxxxx_influxdb }}:/data/exports/influxdb /root/ # Copy the backup to host
docker cp /root/influxdb {{ addon_xxxxx_influxdbv2 }}:/data/imports # Copy the backup to the v2 container (Make sure it's started)
docker exec -it {{ addon_xxxxx_influxdbv2 }} /bin/bash # Enter the v2 container. Replace addon_xxxxx_influxdbv2 with the v2 Id
influx write \
  --org-id homeassistant \
  --bucket homeassistant \
  --file /data/imports \
  --token {{ TOKEN }} # Replace {{ TOKEN }} with your homeassistant/operator token.

Authors & contributors

Author of this repository is Daniel Oldberg.
Huge credits to Franck Nijhof and Home assistant community for their work on the original InfluxDB project that was used as a foundation.

License

MIT License

Copyright (c) 2018-2023

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

6 Likes

Hi @danieloldberg,

First, thanks for your addon. This is exactly what I’m looking for.

Now, my noob question (…) :

I’ve influxdb (v1) installed and the intallation of v2 is went well.

I’d like to export my databases to influx v2.
I’ve tried with you code but I’ve an error message.
So, I’ve tried to modify it. Here is it :

docker ps -a # Descibe the containers running and finding the Ids.
docker exec -it addon_a0d7b954_influxdb /bin/bash # Enter the v1 container. Replace addon_xxxxx_influxdb with the v1 Id
influx_inspect export -database home_assistant -retention autogen -out /usr/share/hassio/addons/data/a0d7b954_influxdb/influxdb/exports/influxdb -lponly -datadir /usr/share/hassio/addons/data/a0d7b954_influxdb -waldir /usr/share/hassio/addons/data/a0d7b954_influxdb/influxdb/wal # Export the influxdb timeseries data
exit # Exit container to host
docker cp addon_a0d7b954_influxdb:/usr/share/hassio/addons/data/a0d7b954_influxdb/influxdb/exports/influxdb /root/ # Copy the backup to host
docker cp /root/influxdb 47c55538-influxdbv2:/data/imports # Copy the backup to the v2 container (Make sure it's started)
docker exec -it 47c55538-influxdbv2 /bin/bash # Enter the v2 container. Replace addon_xxxxx_influxdbv2 with the v2 Id
influx write \
  --org-id Influxdb \
  --bucket HomeAssistant \
  --file /data/imports \
  --token ###### \# Replace {{ TOKEN }} with your homeassistant/operator token.

and the error message :

export: lstat /usr/share/hassio/addons/data/a0d7b954_influxdb: no such file or directory

Can you help me?

Update : everthing is ok.

There is a little error : influbd in the place of influxb
Here :
influx_inspect export -database homeassistant -retention autogen -out /data/exports/influxdb -lponly -datadir /data/influxb -waldir /data/influxdb/wal # Export the influxdb timeseries data

Hey @mitch55.

Sorry for late response.
Great you got it working.

FYI, it’s not recommended to put your tokens up on the internet. I’d suggest you edit your post and remove it.

Cheers.

1 Like

You can see edited content (tokens still there)

Where?
I deleted it? image

I don’t see an other one?

???

The last edit was on the 29th september ! When @danieloldberg pointed it out to me.
image

And my token has no longer been visible since.

I don’t understand the purpose of your message.

All edits are visible. I am seeing this conversation for the first time, yet I can look back at your edits and see that your token ends with “ZWd3w”…

You may consider changing tokens, just to be careful, since this public posting won’t ever disappear. :hugs:

Oh, I understand now.

I didn’t know edits were visible.

I’m going to change it, thanks.

Hi.

I’m having a bit of trouble getting HA to connect to InfluxDB using this. Getting the following error in logs:

Logger: homeassistant.components.influxdb
Source: components/influxdb/__init__.py:487
Integration: InfluxDB ([documentation](https://www.home-assistant.io/integrations/influxdb), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+influxdb%22))
First occurred: 12:33:03 PM (4 occurrences)
Last logged: 12:36:15 PM

* Cannot connect to InfluxDB due to '<urllib3.connection.HTTPConnection object at 0x7f9e7ade0450>: Failed to establish a new connection: [Errno -5] Name has no usable address'. Please check that the provided connection details (host, port, etc.) are correct and that your InfluxDB server is running and accessible. Retrying in 60 seconds.

Using the following config:

influxdb:
  api_version: 2
  ssl: false
  host: a0d7b954-influxdb
  port: 8086
  token: xxxx
  organization: xxxx
  bucket: xxxx

Any Ideas?

fixed by replacing

host: a0d7b954-influxdb

with

host: ip address of HA machine

:person_facepalming:

I have installed the addon and created the integration file as described here InfluxDB - Home Assistant for version 2.x.x
and it is happily writing to the influxdb Home-assistant bucket

I want to create a sensor to extract values for my apexchart.
But get an error that says: queries_flux’ is an invalid option for ‘influxdb’

  queries_flux:
    - range_start: "-1d"
      name: influx_buiten_temperatuur
      query: >
        filter(fn: (r) => r["_measurement"] == "°C")
        |> filter(fn: (r) => r["_field"] == "value")
        |> filter(fn: (r) => r["domain"] == "sensor")
        |> filter(fn: (r) => r["entity_id"] == "buiten_temperatuur")
        |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
        |> yield(name: "mean")

What am I doing wrong?

Getting error messages in the log, although some data is flowing to influxdb from homeassistant.
Before changing host aadress to use ip of homeassistant server, no data was flowing at all but same error message was displayed.

Should I worry about the error message still, because some data is maybe not flowing?

ts=2023-12-29T13:58:06.991700Z lvl=info msg=Unauthorized log_id=0mPQPug0000 error="authorization not found"

Using the default config:

influxdb:
  api_version: 2
  ssl: false
  host: zzz.zzz.zzz.zzz
  port: 8086
  token: XXXX
  organization: YYY
  bucket: homeassistant
  tags:
    source: HA
  tags_attributes:
    - friendly_name
  default_measurement: units
  exclude:
    entities:
      - zone.home
    domains:
      - persistent_notification
      - person
  include:
    domains:
      - sensor
      - binary_sensor
      - sun
    entities:
      - weather.home

Hello,
I have just noticed v2 is available.
Some time ago I installed InfluxDB (ver.1).
Can both versions be running at the same time? Probably not, especially because they are using the same port number, no?
Should I uninstall ver.1 (4.8.0)?
Does it mean I also have to remove this entry in configuration.yaml?

influxdb:
 host: a0d7b954-influxdb
 database: home_assistant
 username: homeassistant
 password: PASSWORD
 max_retries: 3
 default_measurement: state

By the way, do I have to configure Telegraf to be able to see something flowing?

1 Like

One more thing.
Is there no option for the add-on to appear in the left-hand side panel?
InfluxDB ver.1 had such an option.

Both can be run as long as you configure different ports.
You can though only run one influxdb integration.

No way unfortunately as Influxdb v2 does not support reverse proxy. It’s mentioned as a known issue.

Do I need Node-Red to pass data from InfluxDB v2 add-on to Grafana add-on?
Grafana shows “3 buckets found” so I assume the connection between InfluxDB v2 and Grafana is OK.
But I am not sure what do do next?
Do I have to manually create FLUX queries? Or is there some magic button to start the flow from InfluxDB v2 to Grafana?
Sorry for the noob question.

I don’t understand why I can’t see this in my Grafana.
Is this not available when FLUX language is used?

Grafana video

Easiest way to get your data showing in Grafana is to build your query in InfluxDB v2 for the entities you want to display, then simply select “script editor”. If you copy the query then open Grafana, you can simply paste this into a dashboard you have previously created. This should then start displaying your recorded data.

Thanks.
Copying the script was indeed what I missed.
By the way, does anyone know how to get Grafana working on localhost:3000?