安装mysql服务

  1. sudo apt-get install libmysqlclient-dev
  2. sudo apt-get install python-dev python3-dev
  3. sudo apt-get install mysql-server

新建mysql数据库

  1. sudo mysql -u root -p

提示你输入数据库密码

  1. ** enter root password **

新建数据表,如果存在,会提示。

  1. CREATE DATABASE hass_db;
  2. CREATE USER 'hass'@'localhost' IDENTIFIED BY '你的密码';
  3. GRANT ALL PRIVILEGES ON *.* TO 'hass'@'localhost';
  4. FLUSH PRIVILEGES;

进入虚拟环境,安装mysql客户端

  1. sudo su -s /bin/bash homeassistant
  2. source /srv/homeassistant/bin/activate
  3. pip3 install --upgrade mysqlclient

查看Mysql 是否运行:

  1. sudo service mysql status
  2. sudo service mysql start

在你的configuration.yaml,增加下面代码

  1. recorder:
  2. purge_interval: 2
  3. purge_keep_days: 5
  4. db_url: mysql://hass:你的密码@localhost/hass_db?charset=utf8

除此之外,还可以在configuration.yaml中加入purge_days参数(多久清理一次),exclude(排除),include(包含)等:

  1. recorder:
  2. purge_days: 5
  3. db_url: mysql://dbuser:password@localhost/dbname?charset=utf8
  4. exclude:
  5. domains:
  6. - automation
  7. - weblink
  8. - updater
  9. entities:
  10. - sun.sun # Don't record sun data
  11. - sensor.last_boot
  12. - sensor.date
  13. include:
  14. domains:
  15. - sensor
  16. - switch
  17. - media_player
  18. exclude:
  19. entities:
  20. - sensor.last_boot
  21. - sensor.date
文档更新时间: 2017-10-26 21:56   作者:Tristan