InfluxDB


The influxdb component makes it possible to transfer all state changes to an external InfluxDB database. See the official installation documentation for how to set up an InfluxDB database, or if you’re using Hass.io, there is a community add-on available.

There is currently support for the following device types within Home Assistant:

The influxdb database component runs parallel to the Home Assistant database. It does not replace it.

Configuration

The default InfluxDB configuration doesn’t enforce authentication. If you have installed InfluxDB on the same host where Home Assistant is running and haven’t made any configuration changes, add the following to your configuration.yaml file:

# Example configuration.yaml entry
influxdb:

You will still need to create a database named home_assistant via InfluxDB’s command line interface. For instructions on how to create a database check the InfluxDB documentation relevant to the version you have installed.

Configuration Variables

host

(string)(Optional)IP address of your database host, e.g., 192.168.1.10

Default value: localhost

port

(integer)(Optional)Port to use

Default value: 8086

username

(string)(Optional)The username of the database user. The user needs read/write privileges on the database

password

(string)(Optional)The password for the database user account.

database

(string)(Optional)Name of the database to use. The database must already exist.

Default value: home_assistant

ssl

(boolean)(Optional)Use https instead of http to connect.

Default value: false

verify_ssl

(boolean)(Optional)Verify SSL certificate for https request.

Default value: true

max_retries

(integer)(Optional)Set this to allow the component to retry if there was a network error when transmitting data.

Default value: 0

default_measurement

(string)(Optional)Measurement name to use when an entity doesn’t have a unit.

Default value: uses the entity id of the entity

override_measurement

(string)(Optional)Measurement name to use instead of unit or default measurement. This will store all data points in a single measurement.

exclude

(list)(Optional)Configure which components should be excluded from recording to InfluxDB.

entities

(list)(Optional)The list of entity ids to be excluded from recording to InfluxDB.

domains

(list)(Optional)The list of domains to be excluded from recording to InfluxDB.

include

(list)(Optional)Configure which components should be included in recordings to InfluxDB. If set, all other entities will not be recorded to InfluxDB. Values set by the exclude lists will take precedence.

entities

(string | list)(Optional)The list of entity ids to be included in recording to InfluxDB.

domains

(string | list)(Optional)The list of domains to be included in recording to InfluxDB.

tags

(string | list)Tags to mark the data.

Default value: 0

tags_attributes

(string | list)(Optional)The list of attribute names which should be reported as tags and not fields to InfluxDB. For example, if set to friendly_name, it will be possible to group by entities’ friendly names as well, in addition to their ids.

Default value: 0

component_config

(string)(Optional)This attribute contains component-specific override values. See Customizing devices and services for format.

override_measurement

(string)(Optional)Measurement name to use instead of unit or default measurement. This will store all data points in a single measurement.

component_config_domain

(string)(Optional)This attribute contains domain-specific component override values. See Customizing devices and services for format.

override_measurement

(string)(Optional)Measurement name to use instead of unit or default measurement. This will store all data points in a single measurement.

component_config_glob

(string)(Optional)This attribute contains component-specific override values. See Customizing devices and services for format.

override_measurement

(string)(Optional)Measurement name to use instead of unit or default measurement. This will store all data points in a single measurement.

Examples

Full configuration

influxdb:
  host: 192.168.1.190
  port: 20000
  database: DB_TO_STORE_EVENTS
  username: MY_USERNAME
  password: MY_PASSWORD
  ssl: true
  verify_ssl: true
  max_retries: 3
  default_measurement: state
  exclude:
    entities:
       - entity.id1
       - entity.id2
    domains:
       - automation
  include:
    entities:
       - entity.id3
       - entity.id4
  tags:
    instance: prod
    source: hass

Sensor

The influxdb sensor allows you to use values from an InfluxDB database to populate a sensor state. This can be use to present statistic about home_assistant sensors if used with the influxdb history component. It can also be used with an external data source.

To configure this sensor, you need to define the sensor connection variables and a list of queries to your configuration.yaml file. A sensor will be created for each query:

# Example configuration.yaml entry
sensor:
  - platform: influxdb
    queries:
      - name: mean value of foo
        where: '"name" = ''foo'''
        measurement: '"°C"'

Configuration Variables

host

(string)(Optional)IP address of your database host, e.g. 192.168.1.10.

Default value: localhost

port

(string)(Optional)Port to use.

Default value: 8086

username

(string)(Optional)The username of the database user.

password

(string)(Optional)The password for the database user account.

ssl

(boolean)(Optional)Use https instead of http to connect.

Default value: false

verify_ssl

(boolean)(Optional)Verify SSL certificate for https request.

Default value: false

queries

(list)(Required)List of queries.

name

(string)(Required)The name of the sensor.

unit_of_measurement

(string)(Optional)Defines the units of measurement of the sensor, if any.

measurement

(string)(Required)Defines the measurement name in InfluxDB (the FROM clause of the query).

where

(string)(Required)Defines the data selection clause (the where clause of the query).

value_template

(template)(Optional)Defines a template to extract a value from the payload.

database

(string)(Optional)Name of the database to use.

Default value: home_assistant

group_function

(string)(Optional)The group function to be used.

Default value: mean

field

(string)(Required)The field name to select.

Default value: value

Examples

Full configuration

The example configuration entry below create two request to your local InfluxDB instance, one to the database db1, the other to db2:

  • select last(value) as value from "°C" where "name" = "foo"
  • select min(tmp) as value from "%" where "entity_id" = ''salon'' and time > now() - 1h
sensor:
  platform: influxdb
  host: localhost
  username: home-assistant
  password: password
  queries:
    - name: last value of foo
      unit_of_measurement: °C
      value_template: '{{ value | round(1) }}'
      group_function: last
      where: '"name" = ''foo'''
      measurement: '"°C"'
      field: value
      database: db1
    -  name: Min for last hour
      unit_of_measurement: '%'
      value_template: '{{ value | round(1) }}'
      group_function: min
      where: '"entity_id" = ''salon'' and time > now() - 1h'
      measurement: '"%"'
      field: tmp
      database: db2