文章目錄
- 一、什么是home-assistant?
- 1.核心架構
- 2.集成架構
- 二、在樹梅派5上安裝home-assistant
- 三、接入米家
- 1.對比下趨勢
- 2.手動安裝插件
- 3.配置方式
- 四、接入公牛
- 1.手動安裝插件
- 2.配置方式
- 五、接入海爾
- 1.手動安裝插件
- 2.配置方式
- 六、接入國家電網
一、什么是home-assistant?
Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts.
一款將本地控制與隱私置于首位的開源家庭自動化解決方案,由全球各地的 DIY 愛好者與技術極客玩家社區共同驅動。
1.核心架構
Home Assistant 核心由四個主要部分組成。除此之外,它還包含許多輔助類用于處理常見場景,例如提供實體或處理位置信息。
- 事件總線(Event Bus):負責協調事件的觸發與監聽 —— 這是 Home Assistant 的核心命脈。
- 狀態機(State Machine):跟蹤各類實體的狀態,并在狀態變更時觸發 state_changed 事件。
- 服務注冊表(Service Registry):在事件總線上監聽 call_service 事件,并允許其他代碼注冊服務操作。
- 定時器(Timer):每秒在事件總線上發送一次 time_changed 事件。
來源:https://developers.home-assistant.io/docs/architecture/core
2.集成架構
Home Assistant Core 可以通過 集成(integrations) 進行擴展。每個集成負責 Home Assistant 中的一個特定 領域(domain)(如燈光、傳感器、媒體設備等)。集成能夠監聽或觸發事件、提供操作功能,并維護實體狀態。
集成由兩部分組成:組件(component)(基礎邏輯)和 平臺(platforms)(與其他集成交互的模塊)。集成使用 Python 編寫,能夠充分利用 Python 的所有優勢。開箱即用的 Home Assistant 提供了大量內置集成,覆蓋常見的智能家居設備和服務。
來源:https://developers.home-assistant.io/docs/architecture_components
二、在樹梅派5上安裝home-assistant
https://www.home-assistant.io/installation/
https://github.com/home-assistant/operating-system/releases
目前是在樹梅派安裝docker運行的home-assistant,后面打算采用HA OS。
docker-compose up -d
version: '3'
services:# https://www.home-assistant.io/installation/linux#docker-composehomeassistant:container_name: homeassistantimage: "homeassistant/home-assistant"environment:- TZ=Asia/Shanghaiports:- "8123:8123"volumes:- /root/homeassistant:/config- /etc/localtime:/etc/localtime:ro- /etc/hosts:/etc/hosts:ro- /run/dbus:/run/dbus:rorestart: unless-stoppedprivileged: truenetwork_mode: host
三、接入米家
好久沒更新了:https://github.com/ha0y/xiaomi_miot_raw
最近還在更新:https://github.com/al-one/hass-xiaomi-miot
官方強勢來襲:https://github.com/XiaoMi/ha_xiaomi_home
1.對比下趨勢
https://ossinsight.io/analyze/XiaoMi/ha_xiaomi_home?vs=al-one%2Fhass-xiaomi-miot#overview
還是建議用小米官方的
2.手動安裝插件
git clone https://github.com/XiaoMi/ha_xiaomi_home
cp -r ha_xiaomi_home/custom_components/xiaomi_home /root/homeassistant/custom_components
3.配置方式
安裝完成后,重啟 Home Assistant。待 Home Assistant 啟動后,在「設置」菜單中點擊「設備與服務」選項,在新界面中選擇「添加集成」,搜索「xiaomi home」,按照提示操作即可。
四、接入公牛
1.手動安裝插件
https://github.com/stevenjoezhang/hass-iotbull
git clone https://github.com/stevenjoezhang/hass-iotbull
cp -r hass-iotbull/custom_components/bull /root/homeassistant/custom_components
2.配置方式
安裝完成后,重啟 Home Assistant。待 Home Assistant 啟動后,在「設置」菜單中點擊「設備與服務」選項,在新界面中選擇「添加集成」,搜索「Bull IoT」,按照提示操作即可。
五、接入海爾
https://github.com/banto6/haier
1.手動安裝插件
git clone https://github.com/banto6/haier
cp -r haier/custom_components/haier /root/homeassistant/custom_components
2.配置方式
通過Stream抓包,搜索關鍵詞:assign,點擊查看json即可
https://zhuanlan.zhihu.com/p/697084466
六、接入國家電網
這種感覺不太好:https://github.com/ARC-MX/sgcc_electricity_new/blob/master/ha_addons_doc/Add-on%E6%95%99%E7%A8%8B.md
還是老本行,用docker吧
services:sgcc_electricity_app:env_file:- .envimage: registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity:latest # for use docker.io: arcw/sgcc_electricity:latestcontainer_name: sgcc_electricitynetwork_mode: "host"environment:- SET_CONTAINER_TIMEZONE=true- CONTAINER_TIMEZONE=Asia/Shanghairestart: unless-stoppedvolumes:- ./:/data # if you want to read homeassistant.db, homeassistant.db is in the container at /data/command: python3 main.pyinit: true
.env如下:
### 以下項都需要修改
## 國網登錄信息
# 修改為自己的登錄賬號
PHONE_NUMBER="xxx"
# 修改為自己的登錄密碼
PASSWORD="xxxx"
# 排除指定用戶ID,如果出現一些不想檢測的ID或者有些充電、發電帳號、可以使用這個環境變量,如果有多個就用","分隔,","之間不要有空格
IGNORE_USER_ID=xxxxxxx,xxxxxxx,xxxxxxx# SQLite 數據庫配置
# or False 不啟用數據庫儲存每日用電量數據。
ENABLE_DATABASE_STORAGE=False
# 數據庫名,默認為homeassistant
DB_NAME="homeassistant.db"## homeassistant配置
# 改為你的localhost為你的homeassistant地址
HASS_URL="http://localhost:8123/"
# homeassistant的長期令牌
HASS_TOKEN="eyxxxxx"## selenium運行參數
# 任務開始時間,24小時制,例如"07:00”則為每天早上7點執行,第一次啟動程序如果時間晚于早上7點則會立即執行一次,每隔12小時執行一次。
JOB_START_TIME="07:00"
# 每次操作等待時間,推薦設定范圍為[2,30],該值表示每次點擊網頁后所要等待數據加載的時間,如果出現“no such element”諸如此類的錯誤可適當調大該值,如果硬件性能較好可以適當調小該值
RETRY_WAIT_TIME_OFFSET_UNIT=15## 記錄的天數, 僅支持填寫 7 或 30
# 國網原本可以記錄 30 天,現在不開通智能繳費只能查詢 7 天造成錯誤
DATA_RETENTION_DAYS=7## 余額提醒
# 是否繳費提醒
RECHARGE_NOTIFY=False
# 余額
BALANCE=5.0
# pushplus token 如果有多個就用","分隔,","之間不要有空格
PUSHPLUS_TOKEN=xxxxxxx,xxxxxxx,xxxxxxx