『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 10817|回复: 17

[经验分享] 安装homeassistant到lede x86

[复制链接]

2

主题

16

帖子

150

积分

论坛分享达人

积分
150
金钱
134
HASS币
0
发表于 2018-1-21 15:58:43 | 显示全部楼层 |阅读模式
本帖最后由 llqy 于 2018-1-21 18:43 编辑

帖子老难编辑了,大家可以来简书看我文章
起因
2018.1.16
混hass群时,看其他人讨论的火热,一时冲动买了个软路由 小马v1

货到后
2018.1.19
本想搞个exsi,发现默认买的版本是2G内存版本,exsi6要求4G起步,GG。转而直接装lede x86,koolshare论坛版,各种装不起来,换了2.6版本的img终于装成功了。不容易啊!分网口为wan,lan后,搞起。感觉还可以,性能杠杠的内存使用了9.34%(200MB差不多),netdata监控如下,内存完全过剩。



                               
登录/注册后可看大图


RAM


感觉还得设置下qos,不知道管用不,默默感受下


                               
登录/注册后可看大图


QOS


最后感谢koolshare论坛的大大们,开发了这么好的lede x86

homeassistant
2018年1月21日 15:54:04
对 我就是要把homeassistant直接装到lede x86里。
1. 安装可爱的debian
由于lede默认的仓库里的轮子不足,不足以满足安装homeassistant,所以只能曲线救国了,用debootstrap装debian,如下图,安装软件koolshare仓库里的unifi Controller



                               
登录/注册后可看大图


安装unifi Controller




                               
登录/注册后可看大图


选择单独安装debian

2. 安装homeassistant到debian
winscp登陆到路由器,putty登陆到路由器,然后在putty里

#切换到debian子系统
chroot /mnt/sda3/debian /bin/bash  
#没有返回就成功

#更新下软件
 apt update -y && apt upgrade -y  

#安装python3 python3-venv python虚拟空间  python3-pip python包管理器
apt install python3 python3-venv python3-pip

#转到/srv目录,建立homeassistant文件夹
cd /srv
mkdir homeassistant

#更改此文件夹的所有者和所属组
sudo chown homeassistant:homeassistant homeassistant

#更换用户
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

#正式安装HomeAssistant,速度会非常快
pip3 install homeassistant

#先试试,运行下,等好久,看网络,最后提示运行了,不是什么正则安装xxx,就浏览器打开路由器ip:8123
hass
3.开机启动能用了后,就想开机启动

#切换到debian子系统[/indent][indent]chroot /mnt/sda3/debian /bin/bash  

#新建启动脚本
cd /etc/init.d/
touch hass-daemon

脚本如下,参考官方文档init.d启动 ,有修改

#!/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
# Created with: [url=https://gist.github.com/naholyr/4275302#file-new-service-sh]https://gist.github.com/naholyr/4275302#file-new-service-sh[/url]
PRE_EXEC="cd /srv/homeassistant; source /srv/homeassistant/homeassistant_venv/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() {
  if [ ! -d "$PID_DIR" ]; then
    echo "It seems you did not run"
    echo -e "\tservice hass-daemon install"
    return 1
  fi
  if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
    echo 'Service already running' >&2
    return 1
  fi
  echo -n 'Starting service… ' >&2
  local CMD="$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
    return 1
  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 script will"
  echo -n "also be deleted! That cannot be undone. [yes|No] "
  local SURE
  read SURE
  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 still installed."
  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
脚本测试下
#离开子系统debian
exit

#脚本安装下,就是更新到rc.xd
chroot /mnt/sda3/debian /bin/bash service hass-daemon install
#返回如下
Installing Home Assistant Daemon (hass-daemon)

#脚本启动
chroot /mnt/sda3/debian /bin/bash service hass-daemon start
网页测试下,路由器ip:8123,ok下一步。
4. 真开机启动
还需要把启动脚本放到我们的lede x86里,
[/indent][indent]#退出debian,然后
cd /etc

#编辑rc.local文件,可以用vi,也可以用winscp
vi rc.local
在exit 0 前添加一行
chroot /debian/debian service hass-daemon start
rc.local文件如下
# Put your custom commands here that should be executed once[/indent][indent]# the system init finished. By default this file does nothing.
chroot /debian/debian service hass-daemon start
exit 0
重启路由器,看看网页是否打得开 路由器ip:8123
可以再安装个mosquitto
opkg update
opkg upgrade
opkg install mosquitto
参考:
https://home-assistant.io/
https://home-assistant-china.github.io/
https://home-assistant.cc/
https://bbs.hassbian.com/forum.php
https://bbs.hassbian.com/forum.php?mod=viewthread&tid=27&highlight=ubuntu
http://koolshare.cn/thread-92191-1-1.html

评分

参与人数 2金钱 +38 收起 理由
+ 18 专门注册账号来顶你!
Roger + 20 佩服你的钻研精神!

查看全部评分

回复

使用道具 举报

10

主题

661

帖子

5318

积分

论坛元老

Rank: 8Rank: 8

积分
5318
金钱
4652
HASS币
50
发表于 2018-1-21 16:51:34 来自手机 | 显示全部楼层
厉害了  牛批
回复

使用道具 举报

6

主题

275

帖子

3943

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3943
金钱
3663
HASS币
0
发表于 2018-1-21 18:25:16 | 显示全部楼层
HA可以适用的平台太多了!
回复

使用道具 举报

6

主题

275

帖子

3943

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3943
金钱
3663
HASS币
0
发表于 2018-1-21 18:37:00 | 显示全部楼层
秀一下俺的新玩具
QQ拼音截图20180121183002.png
QQ拼音截图20180121183056.png
QQ拼音截图20180121183151.png
QQ拼音截图20180121183241.png
QQ拼音截图20180121183327.png
QQ拼音截图20180121183415.png
QQ拼音截图20180121184925.png
回复

使用道具 举报

2

主题

16

帖子

150

积分

论坛分享达人

积分
150
金钱
134
HASS币
0
 楼主| 发表于 2018-1-21 18:40:09 | 显示全部楼层
Roger 发表于 2018-1-21 18:37
秀一下俺的新玩具

我本来也想搞exsi 迫于内存2g。。
回复

使用道具 举报

6

主题

275

帖子

3943

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3943
金钱
3663
HASS币
0
发表于 2018-1-21 18:40:55 | 显示全部楼层
油管4K完美
QQ拼音截图20180121183837.png
QQ拼音截图20180121183938.png
QQ拼音截图20180121184000.png
回复

使用道具 举报

6

主题

275

帖子

3943

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3943
金钱
3663
HASS币
0
发表于 2018-1-21 18:51:12 | 显示全部楼层
LEDE软路由,性能太强劲了!
回复

使用道具 举报

123

主题

4626

帖子

1万

积分

管理员

囧死

Rank: 9Rank: 9Rank: 9

积分
16017
金钱
11306
HASS币
45
发表于 2018-1-21 19:29:39 | 显示全部楼层
严重佩服楼主折腾精神!
回复

使用道具 举报

14

主题

656

帖子

3840

积分

论坛元老

Rank: 8Rank: 8

积分
3840
金钱
3179
HASS币
10
发表于 2018-1-21 21:36:05 | 显示全部楼层
刚买了atom的电脑棒 看来我的好好想想了……
回复

使用道具 举报

14

主题

656

帖子

3840

积分

论坛元老

Rank: 8Rank: 8

积分
3840
金钱
3179
HASS币
10
发表于 2018-1-21 22:32:33 | 显示全部楼层
刚看看了一下你买的那个软路由……顺带查了一下
发现有关于 —》取消ESXi的4G内存安装检查限制 的相关教程
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-3 16:16 , Processed in 0.240176 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表