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

 找回密码
 立即注册
查看: 1830|回复: 23

[插件集成] 小米智能门锁2指静脉版接入ha

[复制链接]

2

主题

21

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
221
HASS币
0
发表于 2024-11-7 07:53:39 | 显示全部楼层 |阅读模式
本帖最后由 deshing 于 2024-11-24 12:25 编辑

最新代码在8楼

开始操作
需要安装插件Xiaomi Gateway 3
AlexxIT/XiaomiGateway3: Home Assistant custom component for control Xiaomi Multimode Gateway (aka Gateway 3), Xiaomi Multimode Gateway 2, Aqara Hub E1 on default firmwares over LAN (github.com)

在/homeassistant/
创建文件xiaomi_gateway3.py

将代码写入
from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
    # 门锁参数资料 https://home.miot-spec.com/spec/xiaomi.lock.b03
    # 参考其它的门锁 6017: ["Xiaomi", "Face Recognition Smart Door Lock", "XMZNMS09LM", "lumi.lock.mcn002"] 
    # https://github.com/AlexxIT/XiaomiGateway3/blob/master/custom_components/xiaomi_gateway3/core/devices.py
    # https://home.miot-spec.com/spec/lumi.lock.mcn002
    
    17601: ["Xiaomi", "Xiaomi Smart Door Lock 2 (Finger Vein Unlock)", "xiaomi.lock.b03"],
    "spec": [
        
        # action sensors 传感器
        BaseConv("action", "sensor"),
        
        # battery 电池
        BaseConv("battery", "sensor", mi="4.p.1003"),

        # The door lock status 门开/关状态
        MapConv("lock", "binary_sensor", mi="3.p.1021", map={
            1: False,
            2: True, 
            17: False, 
            33: False, 
            49: False,
            18: True, 
            34: False, 
            50: False}),
        
        # Door status 门状态
        MapConv("door", "sensor", mi="3.p.1021", map={
            1: "Locked",
            2: "Unlocked",
            3: "Door_Closed_Properly_After_Left_Ajar",
            4: "Door_Was_Ajar",
            5: "Leaving_The_Door_Open_Timed_Out",
            6: "Door_Not_Closed_Well",
            17: "Locked",
            33: "Locked",
            49: "Locked",
            18: "Unlocked",
            34: "Unlocked",
            50: "Unlocked",
            19: "Door_Closed_Properly_After_Left_Ajar",
            35: "Door_Closely_Properly_After_Left_Ajar",
            51: "Door_Closed_Properly_After_Left_Ajar",
            20: "Door_Was_Ajar",
            36: "Door_Was_Ajar",
            52: "Door_Was_Ajar",
            21: "Leaving_The_Door_Open_Timed_Out",
            37: "Leaving_The_Door_Open_Timed_Out",
            53: "Leaving_The_Door_Open_Timed_Out",
            22: "Door_Not_Closed_Well",
            38: "Door_Not_Closed_Well",
            54: "Door_Not_Closed_Well"}),
        
        # Operation Method 开锁方式
        MapConv("Operation_Method", "sensor", mi="2.e.1020.p.2", map = {
            1: "Smart_Device",          # Mobile Phone: 智能设备解锁
            2: "Biometric",             # Finger Print: 生物识别(指纹)
            3: "PIN/Password",          # PassWord: 密码认证
            4: "Contactless",           # NFC: 非接触式认证
            5: "Physical_Key",          # Lock Key: 物理钥匙
            6: "OTP",                   # One Time Password: 一次性密码
            7: "Cyclic_Code",           # Periodic Password: 周期性密码
            8: "Emergency_Override",    # Coerce: 强制开锁机制(紧急情况下)
            9: "Interior_Unlock",       # Button Unlock Inside: 内部按钮解锁
            10: "Vein_Recognition"}),   # Finger Vein: 指静脉识别
        
        # Operation ID 开锁ID
        BaseConv("Operation_ID", "sensor", mi="2.e.1020.p.3"),
        
        # Abnormal Condition 异常状态
        ConstConv("action", mi="2.e.1007", value="error"),
        BaseConv("error_id", mi="2.e.1007.p.1"),
        MapConv("abnormal_condition", mi="2.e.1007.p.1", map={
            1: "Frequent_Unlocking_Failed_By_Multiple_Methods",
            2: "Door_Lock_Was_Damaged",
            3: "Door_Lock_Was_Reset",
            4: "Door_Lock_Batteries_Are_Low",
            5: "Door_Lock_Batteries_Are_Nearly_Depleted",
            6: "Unlock_From_Inside_After_Leaving_Home",
            7: "Door_Was_Ajar",
            9: "Leaving_The_Door_Open_Timed_Out",
            10: "Door_Closed_Properly_After_Left_Ajar",
            11: "The_Door_Is_Not_Closed_Well",
            12: "Unlock_Exception"}),
        BaseConv("timestamp", mi="2.e.1007.p.4"),

        # lock action 门锁执行动作
        MapConv("Lock Action", "sensor", mi="2.e.1020.p.6", map={
            1: "Lock",
            2: "Unlock",
            3: "Locked_From_Inside",
            4: "Released_Lock_From_Inside",
            5: "Enabled_Child_Lock",
            6: "Disabled_Child_Lock",
            7: "Enable_The_Away_From_Home_Mode",
            8: "Disable_The_Away_From_Home_Mode",
            9: "Close_The_Door",
            10: "Enabled_Child_Lock_And_From_Inside",
            11: "Disabled_Child_Lock_And_From_Inside"}),
        
        # Operation Position 哪里开门
        MapConv("position", "sensor", mi="2.e.1020.p.5", map={1: "Indoor", 2: "OutDoor"}),
        
        # doorbell action 门铃
        ConstConv("action", mi="5.e.1006", value="doorbell"),
        BaseConv("timestamp", mi="5.e.1006.p.1"),
    ],
}] + DEVICES








重启ha
完成

2024.11.12 修改了 BaseConv("timestamp", mi="5.e.1006.p.4"), 改为 BaseConv("timestamp", mi="5.e.1006.p.1"),

以下更新内容 详细请看8楼
2024.11.12 修改的新代码,把doorbell单独拎出来成一个实体

2024.11.14 发现代码写多余了一个doorbell 实体,已删除
2024.11.24 18楼有个小米智能门锁2 的代码,不带指静脉的版本



xiaomi_gateway3.rar

1.66 KB, 下载次数: 11

评分

参与人数 3金钱 +42 收起 理由
隔壁的王叔叔 + 12 感谢楼主分享!
tianzhuang55 + 10 论坛有你更精彩!
natic + 20 感谢楼主分享!

查看全部评分

回复

使用道具 举报

24

主题

739

帖子

3874

积分

论坛元老

Rank: 8Rank: 8

积分
3874
金钱
3130
HASS币
20
发表于 2024-11-7 08:50:09 | 显示全部楼层
我有涂鸦的zigbee锁,一直用的涂鸦网关,能写这种配置文件,然后接入到小米多模网关2里吗?
回复

使用道具 举报

2

主题

21

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
221
HASS币
0
 楼主| 发表于 2024-11-7 09:04:12 | 显示全部楼层
ms2 发表于 2024-11-7 08:50
我有涂鸦的zigbee锁,一直用的涂鸦网关,能写这种配置文件,然后接入到小米多模网关2里吗? ...

你那是涂鸦,我这个是小米的,没办法
回复

使用道具 举报

24

主题

739

帖子

3874

积分

论坛元老

Rank: 8Rank: 8

积分
3874
金钱
3130
HASS币
20
发表于 2024-11-7 11:54:24 | 显示全部楼层
deshing 发表于 2024-11-7 09:04
你那是涂鸦,我这个是小米的,没办法

我意思是小米多模网关2不是支持第三方的zigbee吗,可不可以通过写这种代码,接入到多模网关2里
回复

使用道具 举报

2

主题

21

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
221
HASS币
0
 楼主| 发表于 2024-11-7 16:53:29 | 显示全部楼层
ms2 发表于 2024-11-7 11:54
我意思是小米多模网关2不是支持第三方的zigbee吗,可不可以通过写这种代码,接入到多模网关2里 ...

你要是连得上或许可以,但是那个没整过不知道。行不行
回复

使用道具 举报

32

主题

285

帖子

1825

积分

金牌会员

Rank: 6Rank: 6

积分
1825
金钱
1540
HASS币
0
发表于 2024-11-7 23:22:15 | 显示全部楼层
请问接入以后可以有出现哪些实体可以拿来做联动使用?
回复

使用道具 举报

2

主题

21

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
221
HASS币
0
 楼主| 发表于 2024-11-8 07:21:24 | 显示全部楼层
本帖最后由 deshing 于 2024-11-8 07:32 编辑
justion 发表于 2024-11-7 23:22
请问接入以后可以有出现哪些实体可以拿来做联动使用?

原本米家,通过多模网关,没有中枢网关那么将没办法本地自动化,接入ha可以,然后米家那边可以做到的自动化,绝大多数可以在ha里实现
这里这个锁这里面有的我都收录了小米智能门锁 2 指静脉版 - 产品规格 - Xiaomi Miot Spec (miot-spec.com)
回复

使用道具 举报

2

主题

21

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
221
HASS币
0
 楼主| 发表于 2024-11-12 11:47:44 | 显示全部楼层
本帖最后由 deshing 于 2024-11-14 15:41 编辑

2024.11.12 修改的新代码,把doorbell单独拎出来成一个实体
2024.11.14 发现代码写多余了一个doorbell 实体,已删除

from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
    # 门锁参数资料 https://home.miot-spec.com/spec/xiaomi.lock.b03
    # 参考其它的门锁 6017: ["Xiaomi", "Face Recognition Smart Door Lock", "XMZNMS09LM", "lumi.lock.mcn002"]
    # https://github.com/AlexxIT/XiaomiGateway3/blob/master/custom_components/xiaomi_gateway3/core/devices.py
    # https://home.miot-spec.com/spec/lumi.lock.mcn002
   
    17601: ["Xiaomi", "Xiaomi Smart Door Lock 2 (Finger Vein Unlock)", "xiaomi.lock.b03"],
    "spec": [
        
        # action sensors 传感器
        BaseConv("action", "sensor"),
        
        # battery 电池
        BaseConv("battery", "sensor", mi="4.p.1003"),

        # The door lock status 门开/关状态
        MapConv("lock", "binary_sensor", mi="3.p.1021", map={
            1: False,
            2: True,
            17: False,
            33: False,
            49: False,
            18: True,
            34: False,
            50: False}),
        
        # Door status 门状态
        MapConv("door", "sensor", mi="3.p.1021", map={
            1: "Locked",
            2: "Unlocked",
            3: "Door_Closed_Properly_After_Left_Ajar",
            4: "Door_Was_Ajar",
            5: "Leaving_The_Door_Open_Timed_Out",
            6: "Door_Not_Closed_Well",
            17: "Locked",
            33: "Locked",
            49: "Locked",
            18: "Unlocked",
            34: "Unlocked",
            50: "Unlocked",
            19: "Door_Closed_Properly_After_Left_Ajar",
            35: "Door_Closely_Properly_After_Left_Ajar",
            51: "Door_Closed_Properly_After_Left_Ajar",
            20: "Door_Was_Ajar",
            36: "Door_Was_Ajar",
            52: "Door_Was_Ajar",
            21: "Leaving_The_Door_Open_Timed_Out",
            37: "Leaving_The_Door_Open_Timed_Out",
            53: "Leaving_The_Door_Open_Timed_Out",
            22: "Door_Not_Closed_Well",
            38: "Door_Not_Closed_Well",
            54: "Door_Not_Closed_Well"}),
        
        # Operation Method 开锁方式
        MapConv("Operation_Method", "sensor", mi="2.e.1020.p.2", map = {
            1: "Smart_Device",          # Mobile Phone: 智能设备解锁
            2: "Biometric",             # Finger Print: 生物识别(指纹)
            3: "PIN/Password",          # PassWord: 密码认证
            4: "Contactless",           # NFC: 非接触式认证
            5: "Physical_Key",          # Lock Key: 物理钥匙
            6: "OTP",                   # One Time Password: 一次性密码
            7: "Cyclic_Code",           # Periodic Password: 周期性密码
            8: "Emergency_Override",    # Coerce: 强制开锁机制(紧急情况下)
            9: "Interior_Unlock",       # Button Unlock Inside: 内部按钮解锁
            10: "Vein_Recognition"}),   # Finger Vein: 指静脉识别
        
        # Operation ID 开锁ID
        BaseConv("Operation_ID", "sensor", mi="2.e.1020.p.3"),
        
        # Abnormal Condition 异常状态
        # abnormal_condition,error_id 都会显示在action实体的属性里面。
        # error_id和abnormal_condition 对应的是各种异常状态
        
        ConstConv("action", mi="2.e.1007", value="error"),
        BaseConv("error_id", mi="2.e.1007.p.1"),
        MapConv("abnormal_condition", mi="2.e.1007.p.1", map={
            1: "Frequent_Unlocking_Failed_By_Multiple_Methods",
            2: "Door_Lock_Was_Damaged",
            3: "Door_Lock_Was_Reset",
            4: "Door_Lock_Batteries_Are_Low",
            5: "Door_Lock_Batteries_Are_Nearly_Depleted",
            6: "Unlock_From_Inside_After_Leaving_Home",
            7: "Door_Was_Ajar",
            9: "Leaving_The_Door_Open_Timed_Out",
            10: "Door_Closed_Properly_After_Left_Ajar",
            11: "The_Door_Is_Not_Closed_Well",
            12: "Unlock_Exception"}),
        BaseConv("timestamp", mi="2.e.1007.p.4"),

        # lock action 门锁执行动作
        MapConv("Lock Action", "sensor", mi="2.e.1020.p.6", map={
            1: "Lock",
            2: "Unlock",
            3: "Locked_From_Inside",
            4: "Released_Lock_From_Inside",
            5: "Enabled_Child_Lock",
            6: "Disabled_Child_Lock",
            7: "Enable_The_Away_From_Home_Mode",
            8: "Disable_The_Away_From_Home_Mode",
            9: "Close_The_Door",
            10: "Enabled_Child_Lock_And_From_Inside",
            11: "Disabled_Child_Lock_And_From_Inside"}),
        
        # Operation Position 哪里开门
        MapConv("position", "sensor", mi="2.e.1020.p.5", map={1: "Indoor", 2: "OutDoor"}),
        
        # doorbell action 门铃
        BaseConv("doorbell", "sensor"),
               
                #BaseConv("doorbell", mi="5.e.1006.p.1"), 这条代码我也不知道咋整
                #doorbell 实体ha是个一串数字很正常,因为我想不到啥好办法,直接获取了按门铃的时间戳。
                #时间戳每次的按门铃时间都不一样,保证不重复,实体数据就有刷新
        #ConstConv("action3", mi="5.e.1006", value="doorbell"),
        BaseConv("doorbell", mi="5.e.1006.p.1"),
    ],
}] + DEVICES




2024.11.14的xiaomi_gateway3.rar

1.93 KB, 下载次数: 12

回复

使用道具 举报

0

主题

3

帖子

40

积分

新手上路

Rank: 1

积分
40
金钱
37
HASS币
0
发表于 2024-11-12 18:06:21 | 显示全部楼层
请问小米M20门锁能接入吗
回复

使用道具 举报

2

主题

100

帖子

785

积分

高级会员

Rank: 4

积分
785
金钱
685
HASS币
0
发表于 2024-11-13 00:47:47 | 显示全部楼层
本帖最后由 invincible 于 2024-11-13 00:51 编辑

最近搞了个云米门锁型号viomi-lbt12a,参照大佬的在改,还是能看得懂的,但是发现我这款型号的描述文件里有actions出现了,一般都只有events和properties的,请教大佬知道怎么处理吗https://miot-spec.org/miot-spec- ... A038:viomi-lbt12a:1  如第558行

            "actions": [
                {
                    "iid": 1,
                    "type": "urn:miot-spec-v2:action:ble-unlock:00002894:viomi-lbt12a:1",
                    "description": "Ble Unlock",
                    "in": [
                        4
                    ],
                    "out": []
                }
            ],


回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-30 01:32 , Processed in 1.115202 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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