29 Star 267 Fork 66

Alone / hass-xiaomi-miot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

version releases stars issues HACS

Xiaomi Miot For HomeAssistant

English | 简体中文

MIoT-Spec 是小米IoT平台根据硬件产品的联网方式、产品功能的特点、用户使用场景的特征和用户对硬件产品使用体验的要求,设计的描述硬件产品功能定义的标准规范。

本插件利用了miot协议的规范,可将小米设备自动接入HomeAssistant,目前已支持大部分小米米家智能设备。且该插件支持HA后台界面集成,无需配置yaml即可轻松将小米设备接入HA。

hass-xiaomi-miot-configs

常见问题

安装/更新

方法1: HACS

  • 首次安装

    HACS > 集成 > ➕ 浏览并下载存储库 > Xiaomi Miot Auto > 下载此存储库

  • 升级插件

    HACS > 集成 > Xiaomi Miot Auto > 更新 / 重新下载

方法2: 通过SambaSFTP手动安装

下载并复制custom_components/xiaomi_miot文件夹到HA根目录下的custom_components文件夹

方法3: 通过SSHTerminal & SSH加载项执行一键安装命令

wget -O - https://get.hacs.vip | DOMAIN=xiaomi_miot bash -

方法4: shell_command服务

  1. 复制下面的代码到HA配置文件configuration.yaml
    shell_command:
      update_xiaomi_miot: |-
        wget -O - https://get.hacs.vip | DOMAIN=xiaomi_miot bash -
  2. 重启HA使配置生效
  3. 在HA开发者工具中调用此服务service: shell_command.update_xiaomi_miot
  4. 再次重启HA使新版插件生效

视频教程

配置

⚙️ 配置 > 设备与服务 > 🧩 集成 > ➕ 添加集成 > 🔍 搜索 Xiaomi Miot Auto

或者点击: 添加集成

账号集成 (Add devices using Mi Account):

自v0.4.4版本开始,插件新增支持账号集成时选择连接设备的模式:

  • 自动模式:插件定期更新支持本地miot协议的设备,并自动将用户筛选的设备中符合条件的型号使用本地连接(推荐)
  • 本地模式:集成配置所筛选的设备都将使用本地连接,如勾选了不支持本地miot协议的设备将不可用
  • 云端模式:集成配置所筛选的设备都将使用云端连接,建议旧版miio、蓝牙、ZigBee设备使用

本地集成 (Add device using host/token):

通过host/token接入设备,适用于在局域网环境下支持miot协议的设备

配置云端模式:

通过token集成的设备开启云端模式

# configuration.yaml
xiaomi_miot:
  username: xiaomi_username
  password: xiaomi_password
  # server_country: cn # 小米云服务器位置: cn(默认), de, i2, ru, sg, tw, us
  # http_timeout: 15   # 请求小米接口的超时时间(秒)

⚙️ 配置 > 设备与服务 > 🧩 集成 > Xiaomi Miot Auto > 选项 > ☑️ 开启云端模式

配置翻译词典:

可以通过配置文件将大部分miot属性的选项描述(如:模式、风速等)翻译成你想要的语言,当然也欢迎你贡献你的词典给其他人👏🏻。

# configuration.yaml
xiaomi_miot:
  language: zh # 使用内置词典,目前仅支持`zh`
  # https://github.com/al-one/hass-xiaomi-miot/blob/master/custom_components/xiaomi_miot/core/translation_languages.py
  translations:
    # 全局词典,对所有实体生效
    idle: '空闲'
    busy: '工作中'
    # 指定风扇模式的词典
    fan.mode:
      straight wind: '直吹模式'
      natural wind: '自然风'
    # 指定洗衣机烘干模式的词典
    washer.drying_level:
      moist: '微湿'
      extra: '特干'

自定义实体

# configuration.yaml
homeassistant:
  customize: !include customize.yaml

# 通过设备型号自定义
xiaomi_miot:
  # https://github.com/al-one/hass-xiaomi-miot/blob/master/custom_components/xiaomi_miot/core/device_customizes.py
  device_customizes:
    chuangmi.plug.212a01:
      miot_local: true
      chunk_properties: 7


# 通过父实体自定义
# customize.yaml
domain.your_entity_id:
  miot_local: true        # 使用本地模式 (通过账号接入的设备)
  miot_cloud: true        # 为该实体开启云端模式 (read, write, action)
  miot_cloud_write: true  # 仅写属性使用云端模式
  miot_cloud_action: true # 仅action使用云端模式
  check_lan: true         # 云端模式下检查设备在局域网是否可用
  miio_properties: power,battery # 获取miio属性到实体的属性中
  miio_cloud_props: prop.power,event.dev_online

# 自定义子实体
domain.parent_entity_id:
  sensor_properties: temperature,humidity,illumination # Miot属性
  binary_sensor_properties: is_volume_muted,any_boolen_property
  switch_properties: on,power
  number_properties: volume
  select_properties: mode
  fan_properties: mode,fan_level
  cover_properties: motor_control

light.your_entity_id:
  color_temp_reverse: false # 反转色温(需重载集成配置)
  yeelight_smooth_on:  2000 # 毫秒 (仅支持本地接入的易来灯)
  yeelight_smooth_off: 3000 # 毫秒 (仅支持本地接入的易来灯)

climate.your_entity_id:
  bind_sensor: sensor.temperature_entity,sensor.humidity_entity # 绑定传感器实体

camera.your_entity_id:
  video_attribute: 1   # https://github.com/al-one/hass-xiaomi-miot/issues/11#issuecomment-773054167
  keep_streaming: true # 持续更新流地址

cover.your_entity_id:
  closed_position: 5     # 当实体位置值小于等于此值时为关闭状态
  deviated_position: 2   # 位置偏差值 2% -> 0%, 98% -> 100%
  motor_reverse: true    # 反转电机状态(需重载集成配置)
  position_reverse: true # 反转电机进程(需重载集成配置)
  open_texts: 打开,升
  close_texts: 关闭,降

media_player.mitv_entity_id:
  bind_xiaoai: media_player.xiaoai_entity_id # 绑定小爱音箱以打开电视
  turn_off_screen: true   # 关闭电视/投影时发送熄屏指令
  screenshot_compress: 20 # 指定电视/投影屏幕截图的压缩率 默认为50%,100时质量最高
  sources_via_apps: 桌面,米家,百度网盘,设置 # 将电视内的APP添加到输入源列表
  sources_via_keycodes: menu,enter,back # 将电视遥控按键添加到输入源列表
  mitv_lan_host: 192.168.31.66 # 指定小米电视的局域网IP

domain.your_entity_id_xxxx:
  interval_seconds: 30 # 每次更新状态间隔秒数(需重载集成配置)
  chunk_properties: 10 # 单次查询设备属性的最大个数(LAN)
  reverse_state: true  # 反转开关状态(仅作用于Binary Sensor)

过滤实体属性

过多的实体属性会导致你的HA数据库变得很庞大,如果某些实体属性对你没有用处,你可以配置exclude_state_attributes来忽略它们

# configuration.yaml
xiaomi_miot:
  exclude_state_attributes:
    - miot_type
    - stream_address
    - motion_video_latest

YAML配置重载

本插件支持配置重载(修改YAML配置后无需重启HomeAssistant):

🔨 开发者工具 > YAML 重载 > 配置重载 > 🔍 重载 XIAOMI MIOT AUTO

支持的设备

不支持的设备

本插件使用轮询的方式获取设备状态,因此无法实时监听部分设备的事件

服务

xiaomi_miot.set_property

service: xiaomi_miot.set_property
data:
  entity_id: camera.isa_hlc7_xxxx
  field: camera_control.on
  value: true

xiaomi_miot.set_miot_property

service: xiaomi_miot.set_miot_property
data:
  entity_id: camera.isa_hlc7_xxxx
  siid: 2
  piid: 1
  value: true

xiaomi_miot.get_properties

service: xiaomi_miot.get_properties
data:
  entity_id: camera.isa_hlc7_1ab7
  mapping:
    - siid: 2
      piid: 1
    - siid: 3
      piid: 2
  update_entity: true # 更新实体状态属性
  throw: true # 在HA通知中显示结果

触发事件 xiaomi_miot.got_miot_properties

xiaomi_miot.call_action

service: xiaomi_miot.call_action
data:
  entity_id: vacuum.dreame_p2259_entity_id
  siid: 4 # vacuum-extend
  aiid: 1 # start-clean
  params:
    - 18 # piid: 1 - work-mode
    - '{"selects":[[7,1,0,2,1]]}' # piid: 10 - clean-extend-data
  throw: true # 在HA通知中显示结果

触发事件 xiaomi_miot.call_miot_action

xiaomi_miot.send_command

service: xiaomi_miot.send_command
data:
  entity_id: switch.your_entity_id
  method: set_power
  params:
    - on
  throw: true # 在HA通知中显示结果

触发事件 xiaomi_miot.send_miio_command

xiaomi_miot.get_token

service: xiaomi_miot.get_token
data:
  name: Light # 米家中的设备名称关键词或IP、型号

xiaomi_miot.intelligent_speaker

service: xiaomi_miot.intelligent_speaker
data:
  entity_id: media_player.xiaoai_lx04_xxxx
  text: Turn on the light
  execute: true # 执行指令
  silent: true  # 静默执行

xiaomi_miot.xiaoai_wakeup

service: xiaomi_miot.xiaoai_wakeup
data:
  entity_id: media_player.xiaoai_lx04_xxxx

xiaomi_miot.renew_devices

service: xiaomi_miot.renew_devices
data:
  username: 80001234 # 小米账号ID/登录邮箱/手机号

触发事件 xiaomi_miot.renew_devices

xiaomi_miot.request_xiaomi_api

service: xiaomi_miot.request_xiaomi_api
data:
  entity_id: sensor.your_entity_id
  api: /v2/plugin/fetch_plugin
  data:
    latest_req:
      api_version: 10070
      plugins:
        - model: brand.device.model

触发事件 xiaomi_miot.request_xiaomi_api

查看更多服务

调试

获取实体状态属性

🔨 开发者工具 > ℹ️ 状态 > 🔍 筛选实体

获取调试日志

# 使用HA服务 (无需重启)
service: logger.set_level
data:
  custom_components.xiaomi_miot: debug

# 或者修改 configuration.yaml (需重启)
logger:
  default: warning
  logs:
    custom_components.xiaomi_miot: debug

⚙️ 配置 > ⚙️ 系统 > ✍️ 日志

交流

获取 miio token

  • 使用HomeAssistant服务

    1. 打开HomeAssistant服务工具
    2. 选择服务xiaomi_miot.get_token,输入设备名称关键词
    3. 在HA通知列表中找到token
  • 使用@vevsvevs修改版的米家

    1. 下载APK СКАЧАТЬ ВЕРСИЮ 6.x.x 并安装
    2. 打开米家APP > 我的 > 实验室功能
    3. 打开Write custom log filesEnable app's debug mode
    4. 重启APP后在vevs/logs/misc/devices.txt文件中找到token

鸣谢

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

自动集成小米/米家设备到HomeAssistant开源智能家居系统,支持WiFi、蓝牙、ZIgBee等设备 展开 收起
Python 等 2 种语言
Apache-2.0
取消

发行版 (7)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/al-one/hass-xiaomi-miot.git
git@gitee.com:al-one/hass-xiaomi-miot.git
al-one
hass-xiaomi-miot
hass-xiaomi-miot
master

搜索帮助