本帖最后由 25989406 于 2017-7-11 18:40 编辑
我的基础是已经通过非docker的方式安装了homebridge,这里有一些基础例如怎么ssh、怎么引用第三方套件、怎么启用chroot 我这里不做介绍,请参考前面的帖子 https://bbs.hassbian.com/thread-435-1-1.html
首先官网明确的给出群辉装ha有两种方案,一种是直接装一种是通过docker,我这里简单翻一下前者,添加了我自己的修改和理解,相比于homebridge依赖复杂的node环境和苹果的avahi环境,mqtt和homeassistant简单多了,个人认为homeassistant不用docker装更简单,对小白来说坑更少。找官方方法的直接见:
https://home-assistant.io/docs/installation/synology/
其他问题可以微博联系http://weibo.com/1147593092/profile
群晖搭Mosquitto也就是MQTT,的话直接在chroot下参照ubuntu的安装方式,基本可以无脑安装
https://bbs.hassbian.com/thread-28-1-5.html
下面开始说homeassistant(只依赖第三方套件的python3,无其他依赖):
1.网页登录你的群辉,系统套件中心里安装python3
2.创建名为homeassistant的新用户,添加到users用户组
3. 控制面板-安全性-防火墙-编辑规则
新增一条 目的端口为8123的TCP协议白名单(如果使用其他端口请自行修改)
4.ssh到你的群辉服务器上,后面都考命令行安装
4.1 检查 python3的运行目录是否正确 (套件安装的默认路径为 /volume1/@appstore/py3k/usr/local/bin)
# cd /volume1/@appstore/py3k/usr/local/bin
[/code]
4.2 安装 PIP (Python’s package management system)
# sudo python3 -m ensurepip
4.3 用 PIP 安装 Homeassistant包
# sudo python3 -m pip install homeassistant
4.4 创建 homeassistant配置目录并进入(这里我的方式跟官方的方式不同,我直接使用群晖用户的默认目录做为config路径,所以不需要创建,直接进入/var/services/homes/homeassistant)
# cd /var/services/homes/homeassistant
4.5 创建启动文件
#vim hass-daemon
#!/bin/sh
# Package
PACKAGE="homeassistant"
DNAME="Home Assistant"
# Others
USER="homeassistant"
PYTHON_DIR="/volume1/@appstore/py3k/usr/local/bin"
PYTHON="$PYTHON_DIR/python3"
HASS="$PYTHON_DIR/hass"
INSTALL_DIR="/var/services/homes/homeassistant"
PID_FILE="$INSTALL_DIR/home-assistant.pid"
FLAGS="-v --config $INSTALL_DIR --pid-file $PID_FILE --daemon"
REDIRECT="> $INSTALL_DIR/home-assistant.log 2>&1"
start_daemon ()
{
sudo -u ${USER} /bin/sh -c "$PYTHON $HASS $FLAGS $REDIRECT;"
}
stop_daemon ()
{
kill `cat ${PID_FILE}`
wait_for_status 1 20 || kill -9 `cat ${PID_FILE}`
rm -f ${PID_FILE}
}
daemon_status ()
{
if [ -f ${PID_FILE} ] && kill -0 `cat ${PID_FILE}` > /dev/null 2>&1; then
return
fi
rm -f ${PID_FILE}
return 1
}
wait_for_status ()
{
counter=$2
while [ ${counter} -gt 0 ]; do
daemon_status
[ $? -eq $1 ] && return
let counter=counter-1
sleep 1
done
return 1
}
case $1 in
start)
if daemon_status; then
echo ${DNAME} is already running
exit 0
else
echo Starting ${DNAME} ...
start_daemon
exit $?
fi
;;
stop)
if daemon_status; then
echo Stopping ${DNAME} ...
stop_daemon
exit $?
else
echo ${DNAME} is not running
exit 0
fi
;;
restart)
if daemon_status; then
echo Stopping ${DNAME} ...
stop_daemon
echo Starting ${DNAME} ...
start_daemon
exit $?
else
echo ${DNAME} is not running
echo Starting ${DNAME} ...
start_daemon
exit $?
fi
;;
status)
if daemon_status; then
echo ${DNAME} is running
exit 0
else
echo ${DNAME} is not running
exit 1
fi
;;
log)
echo ${LOG_FILE}
exit 0
;;
*)
exit 1
;;
esac
4.6 创建软连接
# ln -s /volume1/@appstore/py3k/usr/local/bin python3
# ln -s /volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/homeassistant
4.7 修改相关权限
# sudo chown -R homeassistant:users /var/services/homes/homeassistant
# sudo chmod -R 664 /var/services/homes/homeassistant
4.8 给启动脚本添加执行权限:
#sudo chmod 777 /var/services/homes/homeassistant/hass-daemon
5.大功告成,在群晖里执行以下试试吧:
sudo /var/services/homes/homeassistant/hass-daemon start
运行成功后日志会打印在/var/services/homes/homeassistant/home-assistant.log里
5.最后设置自动启动
选择root账号
/var/services/homes/homeassistant/hass-daemon restart
|