物联网从HomeAssistant开始

文章目录

一、什么是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。

bash 复制代码
docker-compose up -d
yaml 复制代码
version: '3'
services:
  # https://www.home-assistant.io/installation/linux#docker-compose
  homeassistant:
    container_name: homeassistant
    image: "homeassistant/home-assistant"
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "8123:8123"
    volumes:
      - /root/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
      - /etc/hosts:/etc/hosts:ro
      - /run/dbus:/run/dbus:ro
    restart: unless-stopped
    privileged: true
    network_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.手动安装插件

bash 复制代码
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

bash 复制代码
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.手动安装插件

bash 复制代码
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教程.md

还是老本行,用docker吧

yaml 复制代码
services:
  sgcc_electricity_app:
    env_file:
      - .env
    image: registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity:latest # for use docker.io: arcw/sgcc_electricity:latest
    container_name: sgcc_electricity
    network_mode: "host"
    environment:
      - SET_CONTAINER_TIMEZONE=true
      - CONTAINER_TIMEZONE=Asia/Shanghai
    restart: unless-stopped
    volumes:
      - ./:/data        # if you want to read homeassistant.db, homeassistant.db is in the container at /data/
    command: python3 main.py
    init: 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
相关推荐
静水流深LY9 小时前
大疆无人机“指点飞行模式”(TapFly)
物联网
k↑1 天前
物联网之使用Vertx实现MQTT-Server最佳实践【响应式】
物联网·mqtt·微服务·响应式
通信大模型1 天前
基于注意力机制的无人机轨迹优化方法:面向无线能量传输的物联网系统
人工智能·深度学习·物联网·无人机·信息与通信
中科岩创2 天前
某公园楼栋自由曲面薄壳结构自动化监测
大数据·网络·物联网·自动化
zskj_zhyl2 天前
数字康养新范式:七彩喜平台重构智慧养老生态的深度实践
大数据·人工智能·物联网
Cynthia AI2 天前
射频前端模组芯片(PA)三伍微电子GSR2337 兼容替代SKY85337, RTC7646, KCT8247HE
物联网·智能手机·智能路由器·智能音箱·射频开关芯片
程序猫A建仔2 天前
【物联网】基于树莓派的物联网开发【1】——初识树莓派
物联网
TDengine (老段)3 天前
TDengine 在智慧油田领域的应用
大数据·数据库·物联网·时序数据库·iot·tdengine·iotdb