本帖最后由 Jxjhheric 于 2017-9-15 09:20 编辑
默认的SQLite会在默认的配置文件夹下产生home-assistant_v2.db文件,随着使用容量会越来越大,现在通过mysql来替代它:
在debian下测试:
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt install mysql-server mysql-client libmysqlclient-dev python-dev python3-dev
$ mysql -u root -p
$ CREATE DATABASE dbname;
$ CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'password';
$ GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'localhost';
$ FLUSH PRIVILEGES;
测试是否成功:
$ mysql -u dbuser dbname -p
env安装的需要先进入环境:
$ ssh pi@your_raspberry_pi_ip
$ sudo su -s /bin/bash hass
$ source /srv/hass/hass_venv/bin/activate
$ pip3 install --upgrade mysqlclient
查看Mysql 是否运行:
sudo service mysql status
sudo service mysql start
最后在 configuration.yaml中加入
recorder:
db_url: mysql://dbuser:password@localhost/dbname?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
|