『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
楼主: zhf883680

[基础教程] Xiaomi Gateway 3添加不在支持列表中的设备

  [复制链接]

2

主题

21

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
221
HASS币
0
发表于 2024-5-19 16:15:36 | 显示全部楼层
deshing 发表于 2024-5-19 15:23
大佬我的也是这款,我在config创建了xiaomi_gateway3.py 用了您发的代码,然后重启没办法使用?请问您的可 ...

已经解决了,我的这个是diy的米家寄存器,会识别成SZGL智能感应开关四键Mesh版,可以参考这个方法
from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
     15418: ["LeMesh", "Mesh Switch", "lemesh.switch.sw4a02"],
    "spec": [
        BaseConv("channel_1", "switch", mi="2.p.1"),
        BaseConv("channel_2", "switch", mi="3.p.1"),
        BaseConv("channel_3", "switch", mi="4.p.1"),
        BaseConv("channel_4", "switch", mi="12.p.1"),
        BaseConv("channel_5", "switch", mi="5.p.1"),
    ],
}] + DEVICES
回复

使用道具 举报

2

主题

103

帖子

871

积分

高级会员

Rank: 4

积分
871
金钱
768
HASS币
0
发表于 2024-5-19 22:08:12 | 显示全部楼层
deshing 发表于 2024-5-19 15:23
大佬我的也是这款,我在config创建了xiaomi_gateway3.py 用了您发的代码,然后重启没办法使用?请问您的可 ...

改了下,用这个

from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
     15418: ["LeMesh", "Mesh Switch", "lemesh.switch.sw4a02"],
    "spec": [
        BaseConv("channel_1", "switch", mi="2.p.1"),
        BaseConv("channel_2", "switch", mi="3.p.1"),
        BaseConv("channel_3", "switch", mi="4.p.1"),
        BaseConv("channel_4", "switch", mi="12.p.1"),
        BaseConv("channel_5", "switch", mi="5.p.1"),
        MapConv("power_on_state_1", "select", mi="2.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("power_on_state_2", "select", mi="3.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("power_on_state_3", "select", mi="4.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("power_on_state_4", "select", mi="12.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("wireless_1", "select", mi="2.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("wireless_2", "select", mi="3.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("wireless_3", "select", mi="4.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("wireless_4", "select", mi="12.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("mode", "select", mi="8.p.1", map={1: "Top Speed Mode", 2: "Standard Mode"}),
        BaseConv("action", "sensor", entity=ENTITY_DISABLED),
        ConstConv("action", mi="14.e.1", value=BUTTON_1_SINGLE),
        ConstConv("action", mi="14.e.2", value=BUTTON_1_DOUBLE),
        ConstConv("action", mi="14.e.3", value=BUTTON_1_HOLD),
        ConstConv("action", mi="15.e.1", value=BUTTON_2_SINGLE),
        ConstConv("action", mi="15.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="15.e.3", value=BUTTON_2_HOLD),
        ConstConv("action", mi="16.e.1", value=BUTTON_3_SINGLE),
        ConstConv("action", mi="16.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="16.e.3", value=BUTTON_3_HOLD),
        ConstConv("action", mi="17.e.1", value=BUTTON_4_SINGLE),
        ConstConv("action", mi="17.e.2", value="button_4_double"),
        ConstConv("action", mi="17.e.3", value=BUTTON_4_HOLD),
    ],
}] + DEVICES
回复

使用道具 举报

4

主题

101

帖子

482

积分

中级会员

Rank: 3Rank: 3

积分
482
金钱
381
HASS币
0
发表于 2024-5-21 17:17:41 | 显示全部楼层
本帖最后由 louwu 于 2024-5-21 17:30 编辑
flyibeat 发表于 2024-4-11 17:53
除了import路径要改外,之前引用的converter命名也要对应改,整个文件内不能出现错误,否则该文件全部不 ...

请教一下,多个自定义设备如何写,举个栗子
from custom_components.xiaomi_gateway3.core.devices import * 
DEVICES = [{
    8553: ["LianXun", "Smart Switch 8-key Mesh", "lxun.switch.sw08"],
    "spec": [
        BaseConv("switch_1", "switch", mi="2.p.1"),
    ],
}] + DEVICES
DEVICES = [{
    8888: ["LianXun", "Smart Switch 8-key Mesh", "lxun.switch.sw08"],
    "spec": [
        BaseConv("switch_1", "switch", mi="2.p.1"),
    ],
}] + DEVICES

回复

使用道具 举报

2

主题

21

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
221
HASS币
0
发表于 2024-5-21 21:35:24 | 显示全部楼层
louwu 发表于 2024-5-21 17:17
请教一下,多个自定义设备如何写,举个栗子

你这样是可以用的,我测试了
回复

使用道具 举报

4

主题

144

帖子

1297

积分

金牌会员

Rank: 6Rank: 6

积分
1297
金钱
1153
HASS币
0
发表于 2024-5-22 09:15:26 | 显示全部楼层
louwu 发表于 2024-5-21 17:17
请教一下,多个自定义设备如何写,举个栗子
from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
    10356: ["ZiQing", "ZiQing Presence Sensor Lite", "IZQ-24"],
    "spec": [
        MapConv("occupancy_status", "sensor", mi="2.p.1", map={0: "无人存在", 1: "有人进入", 2: "有人微动", 3: "有人静态", 4: "有人接近", 5: "有人远离"}),
        BoolConv("occupancy", "binary_sensor", mi="2.p.1"),
        MathConv("no_one_determine_time", "number", mi="2.p.2", min=0, max=10000),
        MathConv("has-someone-duration", "sensor", mi="2.p.3"),
        MathConv("no-one-duration", "sensor", mi="2.p.4"),
        MathConv("illuminance", "sensor", mi="2.p.5", min=0, max=65535),
        MathConv("distance", "sensor", mi="2.p.6", multiply=0.01),
        BaseConv("led", "switch", mi="3.p.1"),
        MathConv("detect_range", "number", mi="3.p.2", min=0, max=8),
        BaseConv("pir", "switch", mi="3.p.3"),
    ],    
}, {
    6461: ["PTX", "Smart Curtain Motor", "CM82TN"],
    "spec": [
        MapConv("motor", "cover", mi="2.p.1", map={0: "stop", 1: "open", 2: "close"}),
        BaseConv("target_position", mi="2.p.2"),
        CurtainPosConv("position", mi="2.p.3"),
        BaseConv("motor_reverse", "switch", mi="2.p.4"),
    ],
    "ttl": "7d"
}] + DEVICES
以上为举例
回复

使用道具 举报

4

主题

101

帖子

482

积分

中级会员

Rank: 3Rank: 3

积分
482
金钱
381
HASS币
0
发表于 2024-5-23 09:32:36 | 显示全部楼层

非常感谢,就是}, {这几个符号没搞清楚
回复

使用道具 举报

4

主题

101

帖子

482

积分

中级会员

Rank: 3Rank: 3

积分
482
金钱
381
HASS币
0
发表于 2024-5-23 09:59:17 | 显示全部楼层

最后这个"ttl": "7d"是什么意思
回复

使用道具 举报

4

主题

101

帖子

482

积分

中级会员

Rank: 3Rank: 3

积分
482
金钱
381
HASS币
0
发表于 2024-5-23 10:05:45 | 显示全部楼层
本帖最后由 louwu 于 2024-5-23 10:12 编辑
终于可以用了
<blockquote>from custom_components.xiaomi_gateway3.core.devices import * 

回复

使用道具 举报

4

主题

101

帖子

482

积分

中级会员

Rank: 3Rank: 3

积分
482
金钱
381
HASS币
0
发表于 2024-5-23 10:13:15 | 显示全部楼层
from custom_components.xiaomi_gateway3.core.devices import * 

DEVICES = [{
    8553: ["Lemesh", "8 键智能复合开关 mesh 版", "lemesh.switch.sw8a01"],
    "spec": [
        BaseConv("switch_1", "switch", mi="2.p.1"),
        BaseConv("switch_2", "switch", mi="3.p.1"),
        BaseConv("switch_3", "switch", mi="4.p.1"),
        BaseConv("switch_4", "switch", mi="12.p.1"),
        MapConv("backlight", "select", mi="5.p.1", map={0: "off", 1: "on"}),
        BaseConv("action", "sensor"),
        ConstConv("action", mi="13.e.1", value=BUTTON_1_SINGLE),
        ConstConv("action", mi="14.e.1", value=BUTTON_2_SINGLE),
        ConstConv("action", mi="15.e.1", value=BUTTON_3_SINGLE),
        ConstConv("action", mi="16.e.1", value=BUTTON_4_SINGLE),
        ConstConv("action", mi="13.e.2", value=BUTTON_1_DOUBLE),
        ConstConv("action", mi="14.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="15.e.2", value=BUTTON_3_DOUBLE),
        ConstConv("action", mi="16.e.2", value=BUTTON_4_DOUBLE),
        ConstConv("action", mi="13.e.3", value=BUTTON_1_HOLD),
        ConstConv("action", mi="14.e.3", value=BUTTON_2_HOLD),
        ConstConv("action", mi="15.e.3", value=BUTTON_3_HOLD),
        ConstConv("action", mi="16.e.3", value=BUTTON_4_HOLD),
        ConstConv("action", mi="17.e.1", value="button_5_single"),
        ConstConv("action", mi="18.e.1", value="button_6_single"),
        ConstConv("action", mi="19.e.1", value="button_7_single"),
        ConstConv("action", mi="20.e.1", value="button_8_single"),
        ConstConv("action", mi="17.e.2", value="button_5_double"),
        ConstConv("action", mi="18.e.2", value="button_6_double"),
        ConstConv("action", mi="19.e.2", value="button_7_double"),
        ConstConv("action", mi="20.e.2", value="button_8_double"),
        ConstConv("action", mi="17.e.3", value="button_5_hold"),
        ConstConv("action", mi="18.e.3", value="button_6_hold"),
        ConstConv("action", mi="19.e.3", value="button_7_hold"),
        ConstConv("action", mi="20.e.3", value="button_8_hold"),
    ],
},{
    14470: ["Lemesh", "情景 Mesh 一键开关 Pro", "lemesh.switch.sw1f01"],
    "spec": [
        BaseConv("switch_1", "switch", mi="2.p.1"),
        MapConv("backlight", "select", mi="5.p.1", map={0: "off", 1: "on"}),
        BaseConv("action", "sensor"),
        ConstConv("action", mi="13.e.1", value=BUTTON_1_SINGLE),
        ConstConv("action", mi="13.e.2", value=BUTTON_1_DOUBLE),
        ConstConv("action", mi="13.e.3", value=BUTTON_1_HOLD),
    ],
},{
    14469: ["Lemesh", "情景 Mesh 二键开关 Pro", "lemesh.switch.sw2f01"],
    "spec": [
        BaseConv("switch_1", "switch", mi="2.p.1"),
        BaseConv("switch_2", "switch", mi="3.p.1"),
        MapConv("backlight", "select", mi="5.p.1", map={0: "off", 1: "on"}),
        BaseConv("action", "sensor"),
        ConstConv("action", mi="13.e.1", value=BUTTON_1_SINGLE),
        ConstConv("action", mi="14.e.1", value=BUTTON_2_SINGLE),
        ConstConv("action", mi="13.e.2", value=BUTTON_1_DOUBLE),
        ConstConv("action", mi="14.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="13.e.3", value=BUTTON_1_HOLD),
        ConstConv("action", mi="14.e.3", value=BUTTON_2_HOLD),
    ],
},{
    14468: ["Lemesh", "情景 Mesh 三键开关 Pro", "lemesh.switch.sw3f01"],
    "spec": [
        BaseConv("switch_1", "switch", mi="2.p.1"),
        BaseConv("switch_2", "switch", mi="3.p.1"),
        BaseConv("switch_3", "switch", mi="4.p.1"),
        MapConv("backlight", "select", mi="5.p.1", map={0: "off", 1: "on"}),
        BaseConv("action", "sensor"),
        ConstConv("action", mi="13.e.1", value=BUTTON_1_SINGLE),
        ConstConv("action", mi="14.e.1", value=BUTTON_2_SINGLE),
        ConstConv("action", mi="15.e.1", value=BUTTON_3_SINGLE),
        ConstConv("action", mi="13.e.2", value=BUTTON_1_DOUBLE),
        ConstConv("action", mi="14.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="15.e.2", value=BUTTON_3_DOUBLE),
        ConstConv("action", mi="13.e.3", value=BUTTON_1_HOLD),
        ConstConv("action", mi="14.e.3", value=BUTTON_2_HOLD),
        ConstConv("action", mi="15.e.3", value=BUTTON_3_HOLD),
    ],
},{
    14460: ["Lemesh", "情景 Mesh 四键开关 Pro", "lemesh.switch.sw4f01"],
    "spec": [
        BaseConv("switch_1", "switch", mi="2.p.1"),
        BaseConv("switch_2", "switch", mi="3.p.1"),
        BaseConv("switch_3", "switch", mi="4.p.1"),
        BaseConv("switch_4", "switch", mi="12.p.1"),
        MapConv("backlight", "select", mi="5.p.1", map={0: "off", 1: "on"}),
        BaseConv("action", "sensor"),
        ConstConv("action", mi="13.e.1", value=BUTTON_1_SINGLE),
        ConstConv("action", mi="14.e.1", value=BUTTON_2_SINGLE),
        ConstConv("action", mi="15.e.1", value=BUTTON_3_SINGLE),
        ConstConv("action", mi="16.e.1", value=BUTTON_4_SINGLE),
        ConstConv("action", mi="13.e.2", value=BUTTON_1_DOUBLE),
        ConstConv("action", mi="14.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="15.e.2", value=BUTTON_3_DOUBLE),
        ConstConv("action", mi="16.e.2", value=BUTTON_4_DOUBLE),
        ConstConv("action", mi="13.e.3", value=BUTTON_1_HOLD),
        ConstConv("action", mi="14.e.3", value=BUTTON_2_HOLD),
        ConstConv("action", mi="15.e.3", value=BUTTON_3_HOLD),
        ConstConv("action", mi="16.e.3", value=BUTTON_4_HOLD),
    ],
}] + DEVICES
回复

使用道具 举报

4

主题

101

帖子

482

积分

中级会员

Rank: 3Rank: 3

积分
482
金钱
381
HASS币
0
发表于 2024-5-23 10:17:36 | 显示全部楼层
原先抄了8键的代码,现在改了之后还是多出来其他几个不可用的按键,如何删除 D99052E3-7243-4e2a-9489-ECB8772122A5.png

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-28 17:26 , Processed in 1.042918 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表