技术宅改变世界 技术宅改变世界

梅林搭建home-assistant

in Geeks read (14036) 文章转载请注明来源!

安装entware

entware-setup.sh

安装python以及依赖

将pip缓存指向U盘

mkdir /tmp/mnt/sda1/.cache
ln -s /tmp/mnt/sda1/.cache /root/.cache
# 如果你自身闪存足够,可以不修改指向

安装所需包

opkg install python3 python3-pip gcc pkg-config libopenssl libffi python3-pyopenssl python3-openssl make

配置ffi.h和ffitarget.h

  • 因为home-assistant需要python-miio依赖,但是编译过程中需要ffi.h和ffitarget.h

    wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz  # 下载包
    tar -zxvf libffi-3.2.1.tar.gz
    cd libffi-3.2.1
    ./configure
    make
    cp armv7l-unknown-linux-gnueabi/include/*.h /opt/include # armv7l-unknown-linux-gnueabi 路径根据实际情况修改

安装所需库

pip3 install --upgrade setuptools
pip3 install sqlalchemy
pip3 install netifaces
pip3 install python-miio
pip3 install xmltodict
#部分库会自动安装,所以这边就不一一列举出来了

配置启动

  • 进入目录/opt/etc/init.d,创建文件hass-daemon,并将下面内容写入文件后chmod a+x /opt/etc/init.d/hass-daemon
#!/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: https://gist.github.com/naholyr/4275302#file-new-service-sh
PRE_EXEC=""
# Typically /usr/bin/hass
HASS_BIN="hass"
RUN_AS="ghostcir"
PID_DIR="/opt/var/run"
PID_FILE="$PID_DIR/hass.pid"
CONFIG_DIR="/opt/etc/homeassistant"
LOG_DIR="/opt/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
    return 1
  fi
  echo -n 'Starting service… ' >&2
  local CMD="$PRE_EXEC $HASS_BIN $FLAGS"
  $CMD
  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
  • 安装

    /opt/etc/init.d/hass-daemon install
  • 启动

    /opt/etc/init.d/hass-daemon start

接入设备

home-assistant梅林entware
发表新评论
已有 12 条评论
  1. aa
    aaChrome 96
    回复

    有人成功的吗,能否交流一下

  2. zong
    zong 10QQ浏览器 10
    回复

    Installing Home Assistant Daemon (hass-daemon)
    就提示了个这个,然后就又是命令行
    不应该要下载安装吗?
    怎么提示完这个直接给结束了
    请给指导下,谢谢

  3. Abel
    AbelSafari 15
    回复

    makemake以后一直 not found

  4. 张四狗
    张四狗 10Chrome 87
    回复

    UNKNOW USER GHOSTCIR

    1. GhostCir
      GhostCir本文作者Chrome 87
      回复

      @张四狗 RUN_AS="ghostcir"
      这里需要修改

      1. zong
        zong 10QQ浏览器 10
        回复

        @GhostCir 改成自己的用户名,运行chmod a+x /opt/etc/init.d/hass-daemon,提示Installing Home Assistant Daemon (hass-daemon),然后再去启动,提示启动失败。关键/opt/etc/homeassistant这里面也没文件,是程序没下载下来,还是需要自己放程序进去

      2. zong
        zong 10QQ浏览器 10
        回复

        @GhostCir 这里修改成自己的用户名吗?

  5. dylan
    dylanChrome 80
    回复

    wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz # 下载包
    tar -zxvf libffi-3.2.1.tar.gz
    cd libffi-3.2.1
    ./configure
    makemake以后一直 not found

  6. dylan
    dylanChrome 80
    回复

    感谢!!

  7. e3
    e3Chrome 71
    回复

    新问题 再装HA的时候遇到这错误 Using cached https://files.pythonhosted.org/packages/ce/3a/3d540b9f5ee8d92ce757eebacf167b9deedb8e30aedec69a2a072b2399bb/bcrypt-3.1.6.tar.gz Could not find a version that satisfies the requirement cffi>=1.1 (from versions: )

  8. e3
    e3Chrome 71
    回复

    需要安装
    opkg install python3-dev

  9. e3
    e3Chrome 71
    回复

    netifaces 安装失败
    Command "/opt/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-7ch870g6/netifaces/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ls3hinai/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-7ch870g6/netifaces/

博客已萌萌哒运行
© 2024 • Powered by Typecho • Theme for yotu
PREVIOUS NEXT
雷姆
拉姆