Recorder


The recorder component is storing details in a database which then are handled by the history component.

Home Assistant uses SQLAlchemy as Object Relational Mapper (ORM). This means that you can now use any SQL backend for the recorder that is supported by SQLAlchemy, like MySQL, MariaDB, or PostgreSQL.

The default database engine is SQLite which doesn’t require any configuration. The database is stored in your Home Assistant configuration directory (.homeassistant) and called home-assistant.db.

To setup the recorder component in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
recorder:

Configuration variables:

  • purge_days (Optional): Delete events and states older than x days.
  • db_url (Optional): The URL which point to your database.
# Example configuration.yaml entry
recorder:
  purge_days: 5
  db_url: sqlite:///home/user/.homeassistant/test
Database engine db_url
SQLite sqlite:///PATH/TO/DB_NAME
MySQL mysql://SERVER_IP/DB_NAME
MySQL mysql://user:[email protected]_IP/DB_NAME
PostgreSQL postgresql://SERVER_IP/DB_NAME
PostgreSQL postgresql://scott:[email protected]_IP/DB_NAME

Installation notes

Not all Python bindings for the chosen database engine can be installed directly. This section contains additional details which should help you to get it working.

MYSQL

For MySQL you may have to install a few dependencies:

$ sudo apt-get install libmysqlclient-dev
$ pip3 install mysqlclient

PostgreSQL

For PostgreSQL you may have to install a few dependencies:

$ sudo apt-get install postgresql-server-dev-X.Y
$ pip3 install psycopg2