GithubHelp home page GithubHelp logo

hasscc / meiju Goto Github PK

View Code? Open in Web Editor NEW
73.0 5.0 5.0 305 KB

Midea Meiju (美的美居) For HomeAssistant

License: Apache License 2.0

Python 4.50% Lua 95.50%
meiju midea custom-component home-assistant iot

meiju's Issues

如何适配未支持的美的设备?

首先在这里感谢 @mac-zhou @blindlight86 @vividmuse 等各位大佬对美的美的设备协议和美居APP接口的不懈努力,此插件的只要功能即将美的设备的读写命令通过yaml转换为HA实体。美的设备的读写命令是通过字节(byte)数组传输的,因此适配美的设备需要一点编程基础。

当前阶段,本插件仅支持yaml配置,后续会支持通过UI集成

  1. Yaml配置
    # configuration.yaml
    meiju:
      # 单个账号
      username: 18866668888 # 美居APP账号
      password: abcdefghijk # 美居APP密码
      devices: # 设备列表
        - device_id: 160123456789001 # 设备ID
          host: 192.168.1.101        # 设备IP
        - device_id: 160123456789002
          host: 192.168.1.102
      # 多个账号
      accounts:
        - username: 18866668881 # 账号1
        - username: 18866668882 # 账号2
          devices: # 设备列表
    customizes: # 设备自定义
  2. customizes: 根据设备类型或SN8(型号)为设备解析命令成HA实体的配置,类似于HA的template,可以为设备添加不同类型的实体以展示状态和控制设备
    • get_extra: {10: 0x31} 配置查询状态命令索引为10的byte值为0x31,部分设备为0x03或其他
    • set_extra: {10: 0x21} 配置控制设备命令索引为10的byte值为0x21
    • sensors: 添加sensor传感器实体
      • byte: 11 表示该实体的状态在状态byte数组的第12位上(索引为11)
      • dict: 字典或数组,映射状态值
      • state_template: 实体状态模板
      • attrs_template: 实体属性模板,返回字典
      • 上述选项其他实体通用
    • binary_sensors: 添加二元传感器实体,同sensors
      • state_template: 实体状态模板,返回布尔
    • switches: 添加开关实体
      • on_value: 0x01 byte位上的值等于此值时表示开
      • off_value: 0x00 byte位上的值等于此值时表示关
      • on_extra: 打开时设置额外的byte数据,字典类型
      • off_extra: 关闭时设置额外的byte数据,字典类型
    • selects: 添加下拉选择实体,如:模式
      • set_extra: 选中选项时设置额外的byte数据
      • options: 下拉选项,字典类型,key为byte位上的值
        • value为字符串时,表示显示的选项名称
        • name: 选项名称
        • extra: 选中时额外的byte数据,字典类型
    • numbers: 添加数值实体,如:目标温度
      • max: 最大值
      • min: 最小值
      • step: 步长,默认1
  3. Lua脚本为美居APP编解码设备命令的程序,在lua脚本中可以找到每个设备属性/功能对应的byte位是多少,以及值的含义
    • 通过meiju.get_lua服务获取设备的lua脚本
    • 通过vscode或其他IDE格式化lua代码,插件的lua目录下有常用设备的lua
    • 分析lua文件中各byte位的含义,不同设备的lua规范不一致,因此需要有编程基础
      • byte数组的前10位(索引0-9)为头信息,其中第10位(索引为9)为命令类型(0x02控制 0x03读取)
      • byte数组的第11位(索引10)为请求/响应类型,各设备可能不一样,参考get_extra set_extra
      • 第12位开始通常为各属性或功能的值,部分lua会把头信息移除,因此这些lua中命令body的起始索引是从1或0开始
      • lua文件中可能会根据设备的具体型号来使用不同的byte值,通常使用设备的modelNumbersn8来区分,这两种型号可以在info实体的属性中找到
  4. JS插件为美居APP中设备控制页面的代码,在js插件代码中可以找到不同型号的设备有哪些功能及选项,比如有哪些模式。
  5. 目前该自定义插件仍在开发中,主要开发工作为将lua及js中的命令通过yaml转换成HA实体。由于个人精力的原因,适配不同设备是个漫长的过程,希望有编程能力的同学可以参考以上内容和device_customizes.yaml一起参与适配。

当前版本提示调用业务系统异常

在我的HomeAssistant中使用该插件添加美的JSQ30-MJ3热水器时程序出现错误,提示

Logger: homeassistant.setup
Source: setup.py:288
First occurred: 15:36:12 (1 occurrences)
Last logged: 15:36:12

Error during setup of component meiju
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 288, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/meiju/__init__.py", line 100, in async_setup
    await acc.update_devices(cfg.get(CONF_DEVICES) or [])
  File "/config/custom_components/meiju/__init__.py", line 505, in update_devices
    await dvc.auth_device()
  File "/config/custom_components/meiju/__init__.py", line 632, in auth_device
    token, key = await self.hass.async_add_executor_job(self.account.cloud.gettoken, udpid)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/msmart/cloud.py", line 190, in gettoken
    response = self.api_request(
               ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/msmart/cloud.py", line 109, in api_request
    self.handle_api_error(int(response['code']), response['msg'])
  File "/usr/local/lib/python3.11/site-packages/msmart/cloud.py", line 275, in handle_api_error
    handler()
  File "/usr/local/lib/python3.11/site-packages/msmart/cloud.py", line 261, in throw
    raise ValueError(error_code, message)
ValueError: (40404, '调用业务系统异常(访问地址不存在) [no Route matched with those values]')

用户名和密码检查是正确的,也有热水器信息返回。

此错误来自自定义集成。

Logger: custom_components.meiju
Source: custom_components/meiju/__init__.py:496
Integration: Midea Meiju (documentation, issues)
First occurred: 15:36:12 (1 occurrences)
Last logged: 15:36:12

211106239999999, e3, 51109999, 0000E353151101719181712000357YX4,0000, 204, 燃气热水器

尝试连接代码中的地址,该网址返回内容和错误提示一样
{"msg":"调用业务系统异常(访问地址不存在) [no Route matched with those values]","code":40404}
怀疑美的更改了业务网址导致该故障发生,期待作者大大看一下。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.