本帖最后由 zzzzzqf 于 2018-10-25 21:23 编辑
树莓派3b+安装homeassistant1. 安装树莓派操作系统参考网站教程:https://blog.csdn.net/weixin_39449466/article/details/80686835 1.1. 下载操作系统官网下载RASPBIAN STRETCH WITH DESKTOP版本 下载后文件为:2018-10-09-raspbian-stretch.zip,大小:1.33 GB 解压后文件为:2018-10-09-raspbian-stretch.img,大小:3.85 GB 1.2. 下载SD卡格式化软件大小:6.67 MB 下载地址:https://www.sdcard.org/downloads/formatter_4/eula_windows/index.html 安装好后,选择sd卡后,直接点quick format就行。 1.3. 下载SD卡烧录软件大小:11.9 MB 下载地址: https://jaist.dl.sourceforge.net/project/win32diskimager/Archive/win32diskimager-1.0.0-install.exe 安装好后,选择sd卡,选择刚刚解压的img文件,直接点写入就行。 1.4. 修改配置,支持HDMI在SD卡的根目录下,找到config.txt,打开把下面的#注释取消就行了。 #uncomment if hdmi display is not detected and composite is being output hdmi_force_hotplug=1# 1.5. 修改配置,支持SSH打开cmd命令窗口,输入SD卡所在盘符,输入echo >ssh。 因为目前官方系统默认不开启ssh,在根目录下建立这个文件可以ssh了。 1.6. 插入SD卡将SD拔出,插入树莓派中,上电启动树莓派。 2. 第一次启动配置2.1. 配置时区、语言、wifi等按照图形界面的提示,把这些都配置好就行了 2.2. 扩展系统空间在ssh中输入: sudo raspi-config 然后选择第一个ExpandFilesystem。OK 2.3. 更改密码如果之前改过密码了,那么就不用改了,没改的话,按照下面改密码。 如果刚才的设置界面没退出 选择 2 ChangeUser Password就可以 如果刚才退出了 再次输入sudoraspi-config就行了 3. 更换系统国内源参考地址: https://bbs.hassbian.com/forum.php?mod=viewthread&tid=4013&highlight=%E6%A0%91%E8%8E%93%E6%B4%BE%2B%E7%B3%BB%E7%BB%9F 3.1. 修改树莓派Raspbian系统源sudo nano /etc/apt/sources.list 如下:注意要看自己的系统版本(stretch) # Uncomment line below then 'apt-get update' toenable 'apt-get source' #科大源 3.2. 修改debian软件源sudo nano /etc/apt/sources.list.d/raspi.list
如下: # Uncomment line below then 'apt-get update' toenable 'apt-get source' #科大源
3.3. 更改pip的国内的源我的pip配置文件在/etc/pip.conf pi@raspberrypi:~ $ nano /etc/pip.conf 把原来的用#注释掉,然后在配置文件中写入
[global]
[install] trusted-host = pypi.mirrors.ustc.edu.cn 保存后,执行 sudo apt-get update 4. 配置VNC按照树莓派官网教程来做 4.1. Enabling VNC Server(安装VNC服务端)sudo apt-get update sudo apt-get install realvnc-vnc-serverrealvnc-vnc-viewer 安装好之后,有两种开启模式,图形界面操作和命令行 4.1.1. 图形界面1) On your Raspberry Pi, boot intothe graphical desktop. 2) Select Menu >Preferences > Raspberry Pi Configuration > Interfaces. 3) Ensure VNC is Enabled. 4) 其实这个地方也可以开启SSH服务等 4.1.2. 命令行1) sudo raspi-config 2) Navigate to InterfacingOptions. 3) Scroll down and select VNC> Yes. 4.2. Windows端文件:VNC-Viewer-6.18.907-Windows.exe 大小:9.53 MB 安装好之后,直接在输入框中输入树莓派的ip地址,然后根据提示输入用户名和密码就可以远程控制树莓派了。 5. 安装HomeAssistant我没有用hass.io的方式来安装 5.1. 前置条件You must have Python 3.5.3 or later installed(including the package python3-dev) which is the case for RaspbianStretch. 我之前下载的系统就是官网最新的2018-10-9的Raspbian Stretch,满足了这个python版本要求,它包含了两个版本的python,2.7和3.5.3
pi@raspberrypi:~ $ python Python 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright","credits" or "license" for more information. >>>
pi@raspberrypi:~ $ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright","credits" or "license" for more information. >>>
5.2. 开始安装1) Update the system. $ sudo apt-get update $ sudo apt-get upgrade –y
2) Install the dependencies. $ sudo apt-get install python3 python3-venvpython3-pip
3) 创建homeassistant用户 $ sudo useradd -rm homeassistant -G dialout,gpio
4) 设置homeassistant用户密码 pi@raspberrypi:~ $ sudo passwd homeassistant
5) 创建homeassistant工作目录 $ cd /srv $ sudo mkdir homeassistant $ sudo chown homeassistant:homeassistanthomeassistant $ sudo -u homeassistant -H –s
6) 创建python3虚拟环境 $ cd /srv/homeassistant $ python3 -m venv . $ source bin/activate (homeassistant)homeassistant@raspberrypi:/srv/homeassistant $ python3 -m pip install wheel (homeassistant)homeassistant@raspberrypi:/srv/homeassistant $ pip3 install homeassistant
5.3. 设置开机启动
5.3.1. 创建脚本pi@raspberrypi:~ $ cd /etc/init.d/ pi@raspberrypi:/etc/init.d $ nano hass-daemon 将以下脚本全部复制到hass-daemon中 5.3.2. 脚本内容#!/bin/sh ### BEGIN INIT INFO # Provides: hass # Required-Start: $local_fs $network $named $time $syslog # Required-Stop: $local_fs $network $named $time $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Description: Home\ Assistant ### END INIT INFO
# /etc/init.d Service Script for Home Assistant PRE_EXEC="cd /srv/homeassistant; python3 -mvenv .; source bin/activate;" # Typically /usr/bin/hass HASS_BIN="hass" RUN_AS="homeassistant" PID_DIR="/var/run/hass" PID_FILE="$PID_DIR/hass.pid" CONFIG_DIR="/home/$RUN_AS/.homeassistant" LOG_DIR="/var/log/homeassistant" LOG_FILE="$LOG_DIR/home-assistant.log" FLAGS="-v --config $CONFIG_DIR --pid-file$PID_FILE --log-file $LOG_FILE --daemon"
start() { create_piddir if [ -f$PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then echo'Service already running' >&2 return1 fi echo -n'Starting service… ' >&2 localCMD="$PRE_EXEC $HASS_BIN $FLAGS;" su -s/bin/bash -c "$CMD" $RUN_AS if [ $?-ne 0 ]; then echo"Failed" >&2 else echo'Done' >&2 fi }
stop() { if [ !-f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE") 2>/dev/null; then echo'Service not running' >&2 return1 fi echo -n'Stopping service… ' >&2 kill$(cat "$PID_FILE") while ps-p $(cat "$PID_FILE") > /dev/null 2>&1; do sleep 1;done; rm -f$PID_FILE echo'Done' >&2 }
install() { echo"Installing Home Assistant Daemon (hass-daemon)" update-rc.d hass-daemon defaults create_piddir mkdir -p$CONFIG_DIR chown$RUN_AS $CONFIG_DIR mkdir -p$LOG_DIR chown$RUN_AS $LOG_DIR }
uninstall() { echo"Are you really sure you want to uninstall this service? The INIT scriptwill" echo -n"also be deleted! That cannot be undone. [yes|No] " localSURE readSURE if ["$SURE" = "yes" ]; then stop remove_piddir echo"Notice: The config directory has not been removed" echo$CONFIG_DIR echo"Notice: The log directory has not been removed" echo$LOG_DIR update-rc.d -f hass-daemon remove rm -fv "$0" echo"Home Assistant Daemon has been removed. Home Assistant is stillinstalled." fi }
create_piddir() { if [ !-d "$PID_DIR" ]; then mkdir-p $PID_DIR chown$RUN_AS "$PID_DIR" fi }
remove_piddir() { if [ -d"$PID_DIR" ]; then if [-e "$PID_FILE" ]; then rm-fv "$PID_FILE" fi rmdir-fv "$PID_DIR" fi }
case "$1" in start) start ;; stop) stop ;; install) install ;; uninstall) uninstall ;; restart) stop start ;; *) echo"Usage: $0 {start|stop|restart|install|uninstall}" esac
5.3.3. 注册自启动服务$ sudo service hass-daemon install 5.3.4. 其他说明1) SELECT AUSER.(设置运行hass的用户) Create or pick a user that the Home Assistantdaemon will run under. Update script to set RUN_AS to the username that should be used to execute hass.
2) CHANGE HASS EXECUTABLE ANDOTHER VARIABLES IF REQUIRED. (设置运行hass的工作目录和其他变量) Some installation environments may require achange in the Home Assistant executable hass. Update script to set HASS_BIN to the appropriate hass executable path. Please also check the other variables for theappropriate value. In general the defaults should work
3) 我不知道为什么在安装完之后,直接运行hass,web端就是不能访问hass,设置开启启动后就能访问了,奇怪。 5.4. 重启树莓派pi@raspberrypi:~ $ reboot
6. web访问Home Assistant第一次访问的话,还需要设置用户名和密码。
|