本帖最后由 smc326 于 2017-12-10 16:34 编辑
感想论坛各位大神的教程
参考:
https://bbs.hassbian.com/thread-988-1-1.html 开启root
https://bbs.hassbian.com/thread-473-1-1.html 首次安装
http://bbs.feng.com/forum.php?mod=viewthread&tid=10857822 老高的
https://bbs.hassbian.com/thread-1471-1-1.html python3.6
https://bbs.hassbian.com/thread-1484-1-1.html 配置homeAssistant
https://bbs.hassbian.com/thread-1413-1-1.html 配置Mariadbhttps://bbs.hassbian.com/thread-1471-1-1.html 升级python3.6
等
一、 SD卡写入 系统,就不详细写了!! https://github.com/home-assistant/pi-gen/releases/latest 这个是最新的hassbian,也是很久没有更新了
二、 连接网线,电源之后等很久吧(网络没问题半个小时之内),系统自动安装 home-assistant 最新版本,也可能是上一版本;直到chrome浏览器能进去192.168.x.x:8123(这个IP地址,我用手机软件FING确认的)(很多情况,系统可能进不去,建议重新写SD卡,用联通电信的网都可以正常安装HomeAssistant,个别宽带可能安装不上,或者断网导致系统没有正确安装,本人二次安装几次,有时成功有时失败,所以 不喜欢二次命令安装,干脆重新写SD卡 )
三、 1、putty连接树莓派 帐号pi,密码raspberry
2、修改系统密码 passwd
3、修改树莓派系统时区
sudo dpkg-reconfigure tzdata
我选择的是亚洲ASIA,重庆chongqing
4、修改树莓派源为阿里源 sudo nano /etc/apt/sources.list 添加以下内容,并把原始的源#号掉
deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib rpi
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ stretch main non-free contrib rpi
因为我用的hassbian是stretch的内核,所以千万不能用jessie,以后树莓派换内核,阿里云还得换
ctrl + x 然后 y 回车 确认文件名 退出
更新原有程序:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get update
复制代码
5、修改树莓派固定IP, 我用的是有线固定IP,无线2.4G泛滥,很不稳定
①先 ifconfig 获取有线网卡名称,MAC地址(※记下来,后面用到 )
②第一行冒号前的就是网卡名称,而不是eth01
③修改固定IP sudo nano /etc/dhcpcd.conf
# Example static IP configuration:
interface enxb827eb98a30d //把eht01改成自己的网卡名称
static ip_address=192.168.1.40/24 //改成想要的IP
static ip6_address=fd51:42f8:caae:d92e::ff/64 //不用动
static routers=192.168.1.1 //网关
static domain_name_servers=192.168.1.1 8.8.8.8 fd51:42f8:caae:d92e::1
复制代码
具体可能很多方法修改固定IP,但我觉得这种最有效
6、安装samba,mariadb,mqtt
全部使用hass自带程序安装
sudo hassbian-config install samba
sudo hassbian-config install mariadb
sudo hassbian-config install mosquitto
复制代码
安装mqtt的时候会让输入帐号和密码,一定记住了,其他具体配置在后面
7、配置samba
官方的命令其实可以正常网上邻居访问配置文件了,但是没有密码,不能访问PI的配置目录,干脆按照Tozy 的教材都改了,明白点的就把需要改的地方改了
sudo smbpasswd -a pi //给pi建个smb的密码
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.original // 备份原配置文件,这个随意
sudo nano /etc/samba/smb.conf
[global]
netbios name = raspberrypi
server string = The Pi File Center
workgroup = WORKGROUP
hosts allow =
remote announce =
remote browse sync =
[HOME ASSISTANT]
path = /home/homeassistant/.homeassistant
comment = No comment
browsable = yes
read only = no
valid users =
writable = yes
guest ok = yes
public = yes
create mask = 0777
directory mask = 0777
force user = root
force create mode = 0777
force directory mode = 0777
hosts allow =
[PI]
path = /home/pi
comment = No comment
browsable = yes
read only = no
valid users =
writable = yes
guest ok = yes
public = yes
create mask = 0777
directory mask = 0777
force user = root
force create mode = 0777
force directory mode = 0777
hosts allow =
复制代码
ctrl + x 然后 y 回车 确认文件名 退出
重启samba服务
sudo service smbd restart
7、开启Root账户,方便winscp修改文件
1) 给root建立密码
sudo passwd root
输入两次密码
2) 切换至root帐号,测试是否可用
su root
3) 修改ssh配置文件,使root可以登录
sudo nano /etc/ssh/sshd_config
找到PermitRootLogin一行,把后面prohibit-password修改为 yes ,并把前面#号去掉; 保存退出,然后重启系统,应该可以使用root登陆winscp了 权限自然也都有了
###建议只用ROOT账户登入winscp,修改一些文件用
###用pi帐号安装程序
8、配置 HomeAssistant 用putty打开
sudo nano /home/homeassistant/.homeassistant/configuration.yaml
用notepad++打开samba下的,\\Raspberrypi\home assistant\configuration.yaml
具体修改参见 https://bbs.hassbian.com/thread-1484-1-1.html
9、开始安装 HomeBridge
1)添加8.X数据源
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
上面的8.x是代表nodejs的版本,到底哪个版本好用我也不清楚,我是安装的8.x,没任何问题,也可以试验试验9.x
2) 安装nodejs
sudo apt-get install -y nodejs
3 ) 安装nodejs
sudo apt-get -y install libavahi-compat-libdnssd-dev
4)nodejs安装完,开始正式安装homebridge
sudo npm install -g --unsafe-perm homebridge hap-nodejs node-gyp
cd /usr/lib/node_modules/homebridge/
sudo npm install --unsafe-perm bignum
cd /usr/lib/node_modules/hap-nodejs/node_modules/mdns
sudo node-gyp BUILDTYPE=Release rebuild
cd /
sudo npm install -g homebridge-homeassistant
复制代码
打下 homebridge 测试下~~~出现二维码就是成功了;测试不成功,重新运行下上面命令
先在键盘上按Ctrl+C
停止HomeBridge的运行,重新出现命令行提示符
然后输入 cd /home/pi/.homebridge 并回车
5)修改你的homebridge配置文件
sudo nano /home/pi/.homebridge/config.json
配置如下:
{
"bridge": {
"name": "MY HOME", //随意起
"username": "XX:27:XX:98:XX:0D", //ifconfig查询你使用的网卡mac地址
"port": 51926, //随意填,别太大了
"pin": "325-03-326" //随意,自己能记住
},
"platforms": [
{
"platform": "HomeAssistant",
"name": "MY HOME", //homeassistant里面你配置的名字
"host": "http://192.168.1.40:8123", //树莓派的IP
"password": "SMC5528869", //homeassistant里面你配置的密码
"supported_types": ["automation", "binary_sensor", "climate", "cover", "device_tracker", "fan", "group", "input_boolean", "light", "lock", "media_player", "remote", "scene", "script", "sensor", "switch", "vacuum"],
"default_visibility": "visible",
"logging": true
}
]
}
复制代码
再次输入 homebridge,测试下配置文件是否可用 6)配置homebridge自启动
sudo useradd --system homebridge
sudo chmod -R 0777 /home/pi/.homebridge/
sudo nano /etc/default/homebridge
复制以下内容
# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /home/pi/.homebridge/
# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*
复制代码
ctrl + x 然后 y 回车确认退出 sudo nano /etc/systemd/system/homebridge.service
复制以下内容
[Unit][/align]Description=Node.js HomeKit Server
After=syslog.target network-online.target
[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
复制代码
ctrl + x 然后 y 回车确认退出
sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge
sudo systemctl status homebridge // 查看Homebridge运行状态
复制代码
homebridge安装到此,我每次安装完这个,每次重启都要先关闭homeassistan,然后用sudo reboot重启,哪位大神可以指教下
注:修改homebridge配置文件,只要用notepad++修改\\Raspberrypi\pi\.homebridge\config.json 然后重启,或者 sudo systemctl restart homebridge
10、配置 Mariadb
1) 新建mariadb数据库
sudo mariadb -u root -p
你输入数据库密码
CREATE DATABASE hass_db;
CREATE USER 'hassuser'@'localhost' IDENTIFIED BY '你的密码';
GRANT ALL PRIVILEGES ON *.* TO 'hassuser'@'localhost';
FLUSH PRIVILEGES; exit 2)在你的
configuration.yaml,增加下面代码
recorder:
purge_interval: 2 #每两天执行一次清理,重启会重置
purge_keep_days: 5 #历史数据保存的天数
db_url: mysql://smc326:5626151@localhost/hass_db?charset=utf8
复制代码
3)重启设备
11、HomeAssistan升级(根据需要)
sudo systemctl stop
[email protected]
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistant
exit
sudo systemctl start
[email protected]
12、Python3.6升级 (不一定有必要,如果升级后哪些功能失效就重新安装一遍)
1) 安装一些依赖包
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev sqlite3
复制代码
2) 编译3.6安装包并安装
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar xzvf Python-3.6.3.tgz
cd Python-3.6.3/
./configure
make
sudo make install
3) 重建HomeAssistan
stop
[email protected]
sudo su -s /bin/bash homeassistant
python3.6 -m venv /srv/homeassistant
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistantexit
sudo systemctl start
[email protected]
13、总结
多学多看多总结,这些基础的东西安装完不知道是否有些功能出现冲突,请大家多多尝试