安装mysql服务
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev python3-dev
sudo apt-get install mysql-server
新建mysql数据库
sudo mysql -u root -p
提示你输入数据库密码
** enter root password **
新建数据表,如果存在,会提示。
CREATE DATABASE hass_db;
CREATE USER 'hass'@'localhost' IDENTIFIED BY '你的密码';
GRANT ALL PRIVILEGES ON *.* TO 'hass'@'localhost';
FLUSH PRIVILEGES;
进入虚拟环境,安装mysql客户端
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
pip3 install --upgrade mysqlclient
查看Mysql 是否运行:
sudo service mysql status
sudo service mysql start
在你的configuration.yaml,增加下面代码
recorder:
purge_interval: 2
purge_keep_days: 5
db_url: mysql://hass:你的密码@localhost/hass_db?charset=utf8
除此之外,还可以在configuration.yaml中加入purge_days参数(多久清理一次),exclude(排除),include(包含)等:
recorder:
purge_days: 5
db_url: mysql://dbuser:password@localhost/dbname?charset=utf8
exclude:
domains:
- automation
- weblink
- updater
entities:
- sun.sun # Don't record sun data
- sensor.last_boot
- sensor.date
include:
domains:
- sensor
- switch
- media_player
exclude:
entities:
- sensor.last_boot
- sensor.date
文档更新时间: 2017-10-26 21:56 作者:Tristan