本帖最后由 人生观 于 2017-8-21 13:10 编辑
本帖资料来源于本站和互联网搜索引擎!!! 本人只是简单规整HomeAssistant安装教程(Jones)本站大神代码
在安装PIP的时候如果出现失败本帖提供本地安装文件
get-pip.zip
(1.22 MB, 下载次数: 31)
#首先改一下sudoer设置,省得sudo时总要求输密码sudo nano /etc/sudoers
#在最下面(看好,是此文件的最下方,否则会被下面的设置所覆盖而无效!)添加以下内容(jones改为你的用户名):
jones ALL=NOPASSWD: ALL
#可选项,如果在安装ubuntu时没有更改时区的,使用下面的代码更改时区
sudo dpkg-reconfigure tzdata
#必选项!更换国内源!如果不更换,sudo apt-get update会非常慢
#首先是备份原源地址,然后将虚线间的代码加入sources.list,contrl + x, y 退出
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
sudo nano /etc/apt/sources.list
---------------------------------------------------------------------------------------------------------
deb http://mirrors.aliyun.com/ubuntu/ yakkety main restricted
deb http://mirrors.aliyun.com/ubuntu/ yakkety-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ yakkety universe
deb http://mirrors.aliyun.com/ubuntu/ yakkety-updates universe
deb http://mirrors.aliyun.com/ubuntu/ yakkety multiverse
deb http://mirrors.aliyun.com/ubuntu/ yakkety-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ yakkety-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ yakkety-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ yakkety-security universe
deb http://mirrors.aliyun.com/ubuntu/ yakkety-security multiverse
---------------------------------------------------------------------------------------------------------
#更新源信息,安装更新
sudo apt-get update && sudo apt-get upgrade -y
#做一些清理工作,安装python3,默认应该是已经安装的
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get purge -y python3-pip
sudo apt-get install python3
#安装PIP
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 ./get-pip.py
sudo apt-get install python3-pip
#安装Python3虚拟环境
sudo apt-get install python3-venv
#添加一个名为homeassistant的用户
sudo useradd -rm homeassistant
#转到/srv目录,建立homeassistant文件夹
cd /srv
sudo mkdir homeassistant
#更改此文件夹的所有者和所属组
sudo chown homeassistant:homeassistant homeassistant
#更换用户
sudo su -s /bin/bash homeassistant
#切换目录,创建并进入虚拟环境
cd /srv/homeassistant
python3 -m venv homeassistant_venv
source /srv/homeassistant/homeassistant_venv/bin/activate
#虚拟环境下安装pip
pip install --upgrade pip
#安装依赖netdisco,理论上直接默认安装即可,但有的Hass版本需要指定1.0.0rc3,则按下面的命令输入
pip3 install netdisco
#pip3 install netdisco==1.0.0rc3
#正式安装HomeAssistant,速度会非常快
pip3 install homeassistant
#安装完毕,退出虚拟环境
exit
#设置开机启动,建立service文件,将#中间的部分拷入,按ctrl + x, y 退出。
sudo nano /etc/systemd/system/[email protected]
#########################################################################
[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=homeassistant
Environment=PATH="$VIRTUAL_ENV/bin:$PATH"
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"
[Install]
WantedBy=multi-user.target
#########################################################################
#更新系统设置
sudo systemctl daemon-reload
#设置HomeAssistant开机启动
sudo systemctl enable [email protected]
#启动HomeAssistant
sudo systemctl start [email protected]
#重新启动HomeAssistant
sudo systemctl restart [email protected]
#查看HomeAssistant状态
sudo systemctl status [email protected]
HomeBridge-博联 安装代码(搜索引擎搞来的)已测试!!!
搭建homebridge的部分
#先更新和升级当前环境
sudo apt-get update
sudo apt-get -y upgrade
-------------------------
#安装三个系统组件 screen ,samba, git
sudo apt-get install screen
sudo apt-get install samba
sudo apt-get install git
--------------------------
sudo apt-get install git make
sudo apt-get install g++
curl -sL https://deb.nodesource.com/setup_7.x |sudo -E bash -
sudo apt-get install nodejs=v7.x
#安装必要的依赖包
sudo apt-get -y install libavahi-compat-libdnssd-dev
#安装homebridge,hap-nodejs , node-gyp
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
###假如你不是用我上述的方法安装的NodeJS的话,那么很有可能/usr/lib/这个目录会变成/usr/local/lib/。
cd /
#安装与homebridge关联的 homeassistant
sudo npm install -g --unsafe-perm homebridge
sudo npm install -g homebridge-homeassistant
##(摄像头插件)
sudo npm install -g homebridge-ip-camera
###(博联插件)
sudo npm install -g homebridge-broadlink-rm
#####(升级)
#
sudo npm upgrade -g homebridge-homeassistant
sudo npm install -g [email protected]
#运行homebridge试试看是否正常运行,如果可以正常运行,就ctrl+c退出来
homebridge
cd /home/lyp/.homebridge
#建立config.json的配置文件
sudo nano config.json
#鼠标右键粘贴如下内容
------------------------------
{
"bridge": {
"name": "Homebridge",
"username": "00:0X:2X:CX:9X:X1",
"port": 51826,
"pin": "123-55-888"
},
"platforms": [
{
"platform": "HomeAssistant",
"name": "HomeAssistant",
"host": "http://192.168.1.122:8123",
"password": "rocketer",
"supported_types": ["binary_sensor", "climate", "cover", "fan", "garage_door", "device_tracker", "input_boolean", "light", "lock", "media_player", "rollershutter","sensor", "scene", "switch"]
}
]
}
--------------------------------
上面的内容,注意格式,注意大小写、粘贴完毕后,按键盘上的Ctrl+X键,输入 Y,保存退出。
另外:请注意这几段段代码
"username": "aX:XC:a9:4X:8X:36", ###这个MAC地址大写就可以}
"port": 51826, ###通讯端口,可以修改,但我觉得不用修改###
"pin": "123-22-999" ###PIN码,任意修改,格式是XXX-XX-XXX,只能是数字####
"host": "http://192.168.121.195:8123",
###其中的192.168.121.195是你的树莓派的局域网IP地址####
"password": "mimamima",
###这个是密码,因为我们没有修改Ubuntu的登录密码,所以这里是mimamima####
#再次输入homebridge 回车,检查运行有没有错误
#
#搭建homebridge的部分
#先更新和升级当前环境
sudo apt-get update
sudo apt-get upgrade
####将homebridge设置成随系统启动######
cd /
sudo adduser --system homebridge
sudo mkdir /var/homebridge
sudo cp /home/lyp/.homebridge/config.json /var/homebridge/ (注意使用自己的用户名和路径)
sudo cp -r /home/lyp/.homebridge/persist /var/homebridge
sudo chmod -R 0777 /var/homebridge
cd /etc/default
sudo nano homebridge
#########将下面的内容复制粘贴进去,然后Ctrl+X,然后Y,回车,保存退出####
# 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 /var/homebridge
# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*
####分界线#####################################
cd /etc/systemd/system
sudo nano homebridge.service
#########将下面的内容复制粘贴进去,然后Ctrl+X,然后Y,回车,保存退出####
[Unit]
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
####分界线#####################################
cd /
sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge
sudo systemctl status homebridge
sudo reboot ####重启####
###最后,你想返回去修改PIN码,MAC地址等等参数,可以按以下命令行来做####
sudo systemctl stop homebridge ###停止homebridge运行###
cd /var/homebridge ###进入目录###
sudo nano config.json ###编辑配置文件###
sudo reboot ###重启####
MQTT安装代码(Jones)本站大神代码
#更新下系统,更新前记得改国内源,不知怎么更换的看这贴:[url=http://bbs.hassbian.com/thread-27-1-1.html]http://bbs.hassbian.com/thread-27-1-1.html[/url]
sudo apt-get update
sudo apt-get upgrade -y
#安装mosquitto和mosquitto-clients(后者主要用于测试,如果不想测试,可以只安装前者)
sudo apt-get install mosquitto mosquitto-clients
#更改mqtt设置
sudo nano /etc/mosquitto/conf.d/mqtt.conf
#在上面文件里加入:
=====================================
allow_anonymous false
password_file /etc/mosquitto/pwfile
=====================================
#设置用户和密码,这里用户为mqtt,可改为你想设的用户名,密码自设,这里都设为mqtt
sudo mosquitto_passwd -c /etc/mosquitto/pwfile mqtt
#设置开机启动,以及启动,停止,重启代码(enable为开机启动,其他你们懂的):
sudo /etc/init.d/mosquitto enable|disable|start|stop|restart|reload|
#重启系统
sudo reboot
#测试MQTT,在一个终端下发布,另个终端下接收,测试是否成功。看不懂此条者请忽略。
mosquitto_sub -d -u mqtt -P mqtt -t dev/test
mosquitto_pub -d -u mqtt -P mqtt -t dev/test -m "hello world"
Samba 配置 功能方便局域网内修改HomeAssistant配置文件在使用的时候请去掉我在代码中括号内的备注!!!切记
##再来建立Samba服务#####
sudo smbpasswd -a pi (账户名要写已有账户树莓派默认PI 其他系统写你自己的账户名)
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 =
######分界线####################################
sudo service smbd restart
#########手动重启Home-assistant#################
sudo systemctl restart [url=mailto:[email protected]][email protected][/url]
#################################################
到此结束 ~~!!!
|