2024年9月29日星期日 上午11:38:14

[Discovery]Home Assistant New devices discovered Series:如何判断一个智能设备能否接入home assistant?(含小米设备接入ha的各种协议插件介绍)

2 年 前
#2449 引用
在HomeAssistant有多种接入设备的方式

设备接入

1.自动发现接入(mqtt、homekit ... )
2.配置文件接入
3 HA 的内置插件直接连接
PC 、 Synology 、特斯拉等都可以通过 HA 的内置插件直接连接HA
4.第三方插件接入



MQTT自动发现接入

MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的"轻量级"通讯协议,

http://iotts.com.cn/course/homeassistant/%E8%87%AA%E5%8A%A8%E5%8F%91%E7%8E%B0Mqtt%E8%AE%BE%E5%A4%87/
二、另一种就是使用MQTT服务

https://www.homedt.net/253362.html



HomeAssistant中MQTT设备的自动发现逻辑是:

MQTT设备将自身的配置信息发布在事前定义的主题位置上
HomeAssistant从这个主题位置读取信息,生成对应的系统内实体设备


Home Assistant-自动发现Mqtt设备

设备的接入方式并非一键连接,需要在树莓派目录 \usr\share\hassio\homeassistant 下修改配置文件 configuration.yaml 。

以 Yeelight 灯带为例(非原生 Homekit 设备)。HA 自动搜索无法正确配置 Yeelight 灯带,因此需要手动加入。从路由器或 App 中获取设备的 IP 地址即可无缝接入 HA。

将以下内容拷贝至 configuration.yaml 中并更改 IP 地址。(注意 yaml 格式和缩进)




New devices discovered

1.当硬件设备支持HomeAssistant的MQTT自动发现协议时,会自动将设备添加到HomeAssistant之中,无需单独开发使用集成插件;

如:自己开发的MQTT设备。

设备可能涉及到一个授权问题
如: boardlink 智能插座,需要 boardlink app 里面授权-勾选允许 第三方软件 访问
  

本人再用支持自动发现设备列表

Yeelight wifi ceiling

Yeelight.ceiling26
Yeelight.color8


aqara

M1S  discovered by homkit controller


mijia

小爱音箱-6318  小爱音箱PRO  


2.如果硬件设备不支持自动发现,则可以使用手动配置的方式。

获取token。
举例:为了消除对专有软件(米家app)的依赖,米家设备提供一种在局域网控制的方式。在使用这个局域网控制协议之前需要获取到待接入设备设备的token


3.在HA里使用的集成插件接入设备

通过插件支持一些智能语音输入控制,比如安装HAbridge可以使用亚马逊echo音箱、京东音箱和天猫精灵控制HomeAssistant支持的设备,安装HomeBridge和homekit就可以让IOS的Siri控制设备。

单个集成组件接入单个设备



选用集成将米家设备批量集成到HomeAssistant

优先选择三个集成,

它们的好处是可以统一化添加管理,相对于单个集成组件,更加方便快捷.






Home Assistant使用API并操作小米米家智能插座

https://www.msly.cn/boards/topic/1107/


小米IOT控制端API及小米IOT设备规范 SDK
https://github.com/linruiand/miot-api


小米IOT设备规范v1.md
https://github.com/linruiand/miot-api/blob/master/manual/%E5%B0%8F%E7%B1%B3IOT%E8%AE%BE%E5%A4%87%E8%A7%84%E8%8C%83v1.md

小米IOT设备规范v2.md
https://github.com/linruiand/miot-api/blob/master/manual/%E5%B0%8F%E7%B1%B3IOT%E8%AE%BE%E5%A4%87%E8%A7%84%E8%8C%83v2.md



0
2 年 前
#2450 引用

Software Requirement


.Server  software
Raspberry Pi 3B
└── .Home assistant Integration
    ├── build in Integration
    │   ├── xiaomi miio Integration    ->米家多功能网关xiaomi miio,DGNWG02LM,DGNWQ05LM,ZHWG11LM-lumi.gateway.aqhm01,ZHWG11LM-763-lumi.gateway.mieu01
    │   │   └── python-miio
    │   ├── Xiaomi Gateway (Aqara) Integration  ->只支持aqara miio网关设备v1-v3,米家多功能网关(升级版),需要key
    │   │   └── python-miio
    │   ├── Homekit Controller  Integration
    │   └── sensors
    │       └── react.yaml
    ├── Third Custom Integration
    │   ├── syssi' xiaomi_miio_raw Integration -> https://github.com/syssi/xiaomi_raw
    │   │   └── python-miio
    │   ├── ha0y'xiaomi_miot_raw  -> https://github.com/ha0y/xiaomi_miot_raw  its author has not updated it for a long time
    │   │   └── python-miio
    │   ├── AlexxIT’s Xiaomi Gateway3  Integration  -> https://github.com/AlexxIT/XiaomiGateway3  网关
    │   │   └── python-miio
    │   ├── alone's Xiaomi Miot Auto  Integration
    │   └── niceboy https://github.com/niceboygithub/AqaraCameraHubfw
    │       └──


Make Python virtual environment + Home Assistant Core run automatically




source:
xiaomi miio Integration
https://www.home-assistant.io/integrations/xiaomi_miio/

Xiaomi Gateway (Aqara) Integration
blog:https://bbs.iobroker.cn/t/topic/8588/10


Which Xiaomi Integration to use? Gateway 2 local, Gateway 3 local, MioT, Miot Auto?

I have a lot of Xiaomi devices

I know 5 Xiaomi devices integrations:


Xiaomi Gateway (Aqara)  
Xiaomi Miio (for Gateway 2, i have it)
Xiaomi Raw syssi‘s Xiaomi Raw xiaomi_miio_raw  https://github.com/syssi/xiaomi_raw
Xiaomi Gateway 3 https://github.com/AlexxIT/XiaomiGateway3
Xiaomi MioT  ha0y'xiaomi_miot_raw
Xiaomi Miot Auto  alone’s xiaomi_miot

Integrations provide different functionality:

MioT and Miot Auto provide control of devices like humidifiers, cameras etc, but don’t provide local control,
Miio - provides local control, good support of wifi devices with more entities to control.
Gateway 3 - provides local control, good support of BLE and Zigbee devices with more entities to control.

So integrations have different pros and cons.

source:https://community.home-assistant.io/t/which-xiaomi-integration-to-use-gateway-2-local-gateway-3-local-miot-miot-auto/292418
0
2 年 前
#3583 引用
Home Assistant can discover and automatically configure zeroconf/mDNS and uPnP devices on your network.

Hass works by loading “components” to support various platforms and devices.




DNS -mdns 这篇讲得很清楚
https://iotespresso.com/a-beginners-guide-to-mdns-and-dns-sd/


Home Assistant New devices discovery
https://zhuanlan.zhihu.com/p/586183356
0
2 年 前
#10260 引用
小米各插件区别

python-miio -  库

https://python-miio.readthedocs.io/en/latest/index.html#

https://github.com/rytilahti/python-miio

This library (and its accompanying cli tool) can be used to interface with devices using Xiaomi’s miIO and MIoT protocols.


This library is used by various projects to support MiIO/MiOT devices. If you are using this library for your project, feel free to open a PR to get it listed here!


Python library & console tool for controlling Xiaomi smart appliances (by rytilahti)

python-miio 是一个由第三方实现的开源 miIO / MIoT 协议库,兼容大多数小米IoT智能家居设备,虽然该库目前还没有迈入1.0正式版本,但根据笔者一年多的使用情况看,取代米家App进行日常操作几乎没有任何问题。

另得益于该工具对米家原生的协议的实现,无论是网关还是智能设备都不需要进行刷机等改造工作,这也是笔者非常看重和喜欢的点,是真正贯彻开源控制、闭源固件理念的产物。

python-miio 还附带提供了基于命令行的调试工具 miiocli,供感兴趣的终端用户直接进行调
操作简介blog:https://sspai.com/post/68306

使用文档

https://python-miio.readthedocs.io/en/latest/#



for example

通过python控制小米设备(扫地机器人)  
https://zhuanlan.zhihu.com/p/108683947




tools  miiocli

https://github.com/rytilahti/python-miio

Check that your device is miio.miioprotocol:Discovery by entering the following in a Terminal app on Mac:

root@raspberrypi:~# miiocli discover
INFO:miio.miioprotocol:Sending discovery to <broadcast> with timeout of 5s..
INFO:miio.miioprotocol:  IP 192.168.2.101 (ID: 3dc69984) - token: b'ffffffffffffffffffffffffffffffff'
INFO:miio.miioprotocol:  IP 192.168.2.111 (ID: 1c5c4959) - token: b'ffffffffffffffffffffffffffffffff'
INFO:miio.miioprotocol:  IP 192.168.2.107 (ID: 18a6ce8d) - token: b'ffffffffffffffffffffffffffffffff'
INFO:miio.miioprotocol:  IP 192.168.2.112 (ID: 1c69b97e) - token: b'ffffffffffffffffffffffffffffffff'
INFO:miio.miioprotocol:  IP 192.168.2.109 (ID: 21283c86) - token: b'ffffffffffffffffffffffffffffffff'
INFO:miio.miioprotocol:Discovery done
INFO:miio.discovery:Discovering devices with mDNS for 5 seconds...


You can get some information from any miIO/MIoT device, including its device model, using the info command:

miiocli device --ip <ip> --token <token> info



root@raspberrypi:~# miiocli device --ip 192.168.2.109 --token 2408ba10c691feeb2e7cef627dc0683d info
Model: chuangmi.plug.212a01
Hardware version: esp32
Firmware version: 2.1.8_0041


Model: yeelink.light.ceil26



root@raspberrypi:~# miiocli yeelight --ip 192.168.2.111 --token db163fe4508e246026d7b83950a8fbde status
Name:
Update default on change: True
Delay in minute before off: 0
Developer mode: True
Main light
   Power: True
   Brightness: 100
   Color mode: ColorTemperature
   Temperature: 6494
   Color flowing mode: False
Moonlight
   Is in mode: False
   Moonlight mode brightness: 0
root@raspberrypi:~# miiocli device --ip 192.168.2.111 --token db163fe4508e246026d7b83950a8fbde info
Model: yeelink.light.ceil26
Hardware version: esp32
Firmware version: 2.1.7_0018
root@raspberrypi:~# miiocli yeelight --ip 192.168.2.111 --token db163fe4508e246026d7b83950a8fbde info
Model: yeelink.light.ceil26
Hardware version: esp32
Firmware version: 2.1.7_0018




miio-cli yeelight --ip <ip of the device> --token <token of the device> set_developer_mode 1

miiocli yeelight --ip 192.168.2.111 --token db163fe4508e246026d7b83950a8fbde set_developer_mode 1

miiocli yeelight --ip 192.168.2.111 --token db163fe4508e246026d7b83950a8fbde set_developer_mode 1
Setting developer mode to True
['ok']




下面的官方集成和第3方集成都是以此库为基础进行二次开发的

将米家设备集成到HomeAssistant时,一定要优先选择三个集成,

它们的好处是可以统一化添加管理,相对于单个集成组件,更加方便快捷


Xiaomi Gateway 3   https://github.com/AlexxIT/XiaomiGateway3

Xiaomi MIoT    https://github.com/ha0y/xiaomi_miot_raw      /xiaomi_miot_raw

Xiaomi Miot Auto  https://github.com/al-one/hass-xiaomi-miot





M1S
miiocli device --ip 192.168.2.130 --token 6c75456c435847543168765250447035 i
0
2 年 前
#10261 引用
XIAOMI MIIO  integration  -  Xiaomi Mijia Wifi devices (Mi IO) Binding
官方插件

https://www.home-assistant.io/integrations/xiaomi_miio/
https://github.com/home-assistant/core/tree/dev/homeassistant/components/xiaomi_miio

This integration is used to control Xiaomi products implementing the Mi IO protocol. This protocol is used for most of Xiaomi Mi Ecosystem wifi devices which is branded as MiJia. If your Xiaomi wifi device is controlled by the mihome app, most likely it communicates using the Mi IO protocol and can communicate with ha using this integration.

适用设备


小米2018年前老版的设备,比如:插座1代 2代等。当时只支持miio协议。目前MIOT新协议额的设备已不适用 2022-11-12更新


https://github.com/home-assistant/core/blob/dev/homeassistant/components/xiaomi_miio/const.py


The xiaomi_miio gateway integration allows you to control the gateway and its connected subdevices. detail:https://www.home-assistant.io/integrations/xiaomi_miio#xiaomi-gateway

SUPPORTED XIAOMI GATEWAY MODELS:

Gateway name  Zigbee id  model  supported
Chinese version  lumi.gateway.v3  DGNWG02LM  yes
Aqara hub  lumi.gateway.aqhm01  ZHWG11LM  yes
Mijia Zigbee 3.0  lumi.gateway.mgl03  ZNDMWG03LM  yes




These devices were produced 2 or 3 years ago, which are hard to buy, and the latest XiaoMi devices are not in the catalog.


一直以来小米设备都可以通过XIAOMI MIIO来接入.这个接入方法用了很久,也好用稳定,
就是相当麻烦,通常要编辑configuration.yaml,要获取Token;

下面是小弟验证可以接入的设备,使用方法介绍:https://drunkfish.me/ha2/


Yeelight设备还要在官方app里打开局域网控制等等。

openhab

This binding is used to control Xiaomi products implementing the Mi IO protocol. This protocol is used for most of Xiaomi Mi Ecosystem wifi devices which is branded as MiJia. If your Xiaomi wifi device is controlled by the mihome app, most likely it communicates using the Mi IO protocol

Currently the miio binding supports more than 340 different models.

https://www.openhab.org/addons/bindings/miio/

how  to use

输入米家app的账号和密码

如:使用miio_raw将Yeelight灯接入HA

在HA的配置文件configuration.yaml

本插件使用miio协议

0
2 年 前
#10262 引用

XIAOMI MIIO  integration - xiaomi_miio

details  - 对于不能自动发现的设备,采取直接配置的方式

miIO-discovery获取token与控制  port 54321

miIO协议:设备和米家app在同一局域网下使用的加密专有网络协议,这个被称之为miIO协议。该协议基于UDP,使用54321端口进行通信。


具体功能见github地址:
https://github.com/rytilahti/python-miio


将小米设备配置到HomeAssistant

进入.HomeAssistant目录,编辑configuration.yaml,添加小米网关和Wi-Fi插座的配置参数,token为按照上文你获取到的字符串:

switch:                                     #小米插座配置参数
  - platform: xiaomi_miio
    name: Xiaomi Mi Smart Power Strip #设备名称
    host: 192.168.42.17                  #设备IP
token: YOUR_TOKEN                    #设备密钥
xiaomi_aqara:                             #小米网关配置参数
  gateways:
    - mac: DEVICE_MAC                     #设备mac
      key: YOUR_TOKEN                     #设备密钥
配置文件修改完成后重启hass,再次访问HomeAssistant主页看到新增Xiaomi Mi Smart Power Strip(配置文件里面的name字段)和GatewayLight设备,这就证明配置完成,点击对应的控制按钮就可以控制该设备了。




















0
2 年 前
#10263 引用
1
0
2 年 前
#10280 引用

Xiaomi MIot raw

樓主有寫到 因為他是 Flok Syssi 大神的 Resposit 後修改的

Syssi

xiaomi_miio_raw

https://github.com/syssi/xiaomi_raw

作者的帖子在:

https://bbs.hassbian.com/thread-11749-5-1.html

All-in-one & Easy-to-use. Integrate all your Xiaomi Smart Home - with a single integration and NO YAML files - into Home Assistant. (by ha0y)

非官方集成

插件地址:xiaomi_miot_raw
https://github.com/ha0y/xiaomi_miot_raw
详细使用说明:bbs.hassbian.com
https://bbs.hassbian.com/thread-12007-1-1.html

直接hacs添加xiaomi miot,就能添加米家所有设备,这个小夜灯运动检测、光度检测都能用,还能添加到HomeKit.

Xiaomi MIot raw 这个插件integration。任何人都可以把自己的小米全家桶加入HASS,唯一要做的就是在插件里输入自己的小米ID和密码,然后插件会自动扫描小米家的所有的符合MIot标准的设备接入HA,然后我们点几下鼠标就可以创造新的实体entity。

本插件通过登录小米账号,可以获取到账号下所有支持miot云端协议的智能设备,可以将绝大多数米家智能设备(包括蓝牙、蓝牙 Mesh 和 ZigBee 设备)接入到HomeAssistant之中



优点:简单方便、支持控制小爱音箱、支持红外设备生成实体

缺点:比较依赖云端、大部分设备断网不可用,作者比较忙




用xiaomi miot接入了,创建了自动化,发现使用体验很差,很多次触发没反应

MIoT 协议是小米智能家居从 2018 年起推行的智能设备通信协议规范,此后凡是已接入米家的设备均可通过此协议进行通信。

此插件按照 MIoT 协议规范与米家设备或小米服务器通信,实现对设备的状态读取及控制。

通过本插件,已接入米家的智能设备均可快速高效地接入 Home Assistant,而无关设备的具体型号。

本插件具有本地(局域网)和云端两种工作方式。两种方式结合,可以接入绝大多数米家智能设备(包括蓝牙、蓝牙 Mesh 和 ZigBee 设备)。

由于 MIoT 协议具有极强的通用性,已接入米家的智能设备均可通过此插件快速高效地接入 Home Assistant,而无关设备的具体型号。

本插件运行方式默认为本地接入(局域网读取/控制),延迟极低。
对于不支持本地读取的设备,支持 2 种云端接入(云端读取本地控制/云端读取云端控制)。



以前的是miio现在都是miot协议,2018年后推出的基本都改成miot协议。这个插件还有个好处就是里面有个一键抓取所有token的脚本



https://github.com/ha0y/xiaomi_miot_raw/blob/master/config_example/light.yaml

light:
  - platform: xiaomi_miot_raw
    name: 客厅灯
    host: 192.168.0.11
    token: c5xxxxxxxxxxxxxxxxxxxxxxxxxxxxa7
    mapping:
      switch_status:
        siid: 2
        piid: 1
      brightness:
        siid: 2
        piid: 2
      color_temperature:
        siid: 2
        piid: 3
      # color:    #支持调色灯
      #   siid: 2
      #   piid: 3
    params:
      switch_status:
        power_on: True
        power_off: False
      brightness:
        value_range: [1, 100, 1]
      color_temperature:
        value_range: [3000, 6400, 1]
    scan_interval: 10




0
2 年 前
#10281 引用
1
0
2 年 前
#11322 引用

1
0