舊手機利用篇(三):部署homeassistant

一、準備工作
舊手機一部,下載安裝termux,termux相關配置見:https://runing.fun/try/webServer-fileServer-aiAi.html,以下過程如果沒有科學環(huán)境,沒什么基礎可能需要兩三個小時。
二、安裝python
安裝python并安裝所需依賴
pkg install python tur-repo clang ?openssl libffi
# 更新已安裝依賴
pkg upgrade
三、安裝homeassistant
安裝
# 建立虛擬環(huán)境
python -m venv hass
# 進入虛擬環(huán)境
source hass/bin/activate
# 安裝
pip install homeassistant虛擬環(huán)境不建也可以,但是如果還需要跑其他項目,需要不同的python版本,或者把Termux中的python升級了都可能會影響hass的運行。
問題pip
如果存在以下錯誤(lru 失敗):
Running setup.py install for lru-dict ... error
error: subprocess-exited-with-error
× Running setup.py install for lru-dict did not run successfully.
│ exit code: 1
╰─> [14 lines of output]
? running install
? /data/data/com.termux/files/home/hass/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
? ? warnings.warn(
? running build
? running build_ext
? building 'lru' extension
? creating build
? creating build/temp.linux-aarch64-cpython-310運行一下命令安裝即可:
pip3.10 install git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d
四、運行
帶log運行
hass -v
問題解決
錯誤一(numpy編譯失敗):
Unable to install package PyTurboJPEG==1.6.7: error: subprocess-exited-with-error
× Building wheel for numpy (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [264 lines of output]
Running from numpy source directory.
setup.py:86: DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html
......
SystemError: One of the required function to build numpy is not available (the list is ['sin', 'cos', 'tan', 'sinh', 'cosh', 'tanh', 'fabs', 'floor', 'ceil', 'sqrt', 'log10', 'log', 'exp', 'asin', 'acos', 'atan', 'fmod', 'modf', 'frexp', 'ldexp']).
[end of output]直接ctrl+c結束運行,然后去官方的
看下所需numpy版本,手動安裝,比如我的是1.23.2MATHLIB="m" pip3.10 install numpy==1.23.2
錯誤二(ha-av安裝失敗)
Unable to install package ha-av==10.1.0:
......
pkg-config could not find libraries ['avformat', 'avcodec', 'avdevice', 'avutil', 'avfilter', 'swscale', 'swresample']結束運行,先安裝ffmpeg之后再安裝ha-va
pkg install ffmpeg
pip install ha-av==10.1.0
注:如果控制臺輸出內容不是install 或者build,也不是error,記得打開瀏覽器訪問你設備的http://ip:8123進行訪問,,,他的日志中沒有過于明確的啟動成功提示!?。?/strong>
五、配置
頁面成功訪問,就離成功不遠了,以下是配置過程中可能遇到的一些問題
錯誤一 :(創(chuàng)建時區(qū)信息時報錯)
Valid options can be found here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones for dictionary value @ data['time_zone']
# 執(zhí)行,安裝時區(qū)庫
pip install tzdata錯誤二:創(chuàng)建用戶時報錯(編譯pycares庫錯誤)
ERROR (SyncWorker_1) [homeassistant.util.package] Unable to install package radios==0.1.1
deps/c-ares/src/lib/ares_getnameinfo.c:300:15: error: call to undeclared function 'getservbyport_r'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] ?? ? ? ?if (getservbyport_r(port, proto, &se, (void )tmpbuf, ?? ? ? ? ? ?^ deps/c-ares/src/lib/ares_getnameinfo.c:300:15: note: did you mean 'getservbyport'? /data/data/com.termux/files/usr/include/netdb.h:262:17: note: 'getservbyport' declared here struct servent getservbyport(int port_in_network_order, const char* proto); ?? ? ? ? ? ? ?^ 1 error generated. error: command '/data/data/com.termux/files/usr/bin/aarch64-linux-android-clang' failed with exit code 1
解決方法:下載源碼,修改配置后手動編譯安裝
# 切換到home目錄,便于查找
cd ~
# 下載源碼
wget https://github.com/saghul/pycares/archive/refs/tags/pycares-4.3.0.zip
# 解壓
tar -zxf pycares-4.3.0.zip
# 進入目錄找到配置文件
cd pycares-pycares-4.3.0/deps/build-config/config_android/
# 修改配置,注釋//#define HAVE_GETSERVBYPORT_R 1這一行(前面加//注釋),在131行左右
vim ares_config.h
# 返回該源碼文件的主目錄,執(zhí)行python3.11 setup.py install命令編譯安裝,
cd ../../../
python setup.py install如果install報錯:找不到文件,則還需要更新setuptools
clang-16: error: no such file or directory: 'deps/c-ares/src/lib/ares__addrinfo2hostent.c' clang-16: error: no input files
# 直接安裝,若提示已存在,請卸載重裝
pip install setuptools
結束
再次hass ?-v運行,若正常啟動,頁面多點一點沒什么輸出什么錯誤,就可以進行自定義配置了,具體配置涉及到的東西很多,這里就不介紹了,推薦一些我參考的文章:
,首推,頁面全英文;
,主要看如何配置hacs插件部分,手機上裝的是hass core,和他的版本不太一樣,有些功能沒有,小米集成插件我用的是Xiaomi Miot Auto,據說是兩家合一了,反正我沒找到他那個;
各依賴、插件的官方github,里面的issue和readme可以幫你解決大多數(shù)問題
# 后臺運行homeassistant
nohup hass > hass.log 2>&1 &
# 清下緩存(非必要)
pip cache purge# 退出虛擬環(huán)境
deactivate

我也第一次整這玩意兒,踩了不少坑,有問題歡迎評論區(qū)一塊兒交流