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
https://github.com/AlexxIT/Blog
MIT License
2.47k stars 347 forks source link

There is a problem with smart lock debugging #1432

Open GavinIves opened 2 months ago

GavinIves commented 2 months ago

I use the latest HA and Xiaomigateway. When I want to debug a door lock, I find that the device seems to send me some data. I want to know if it is a plugin bug or just like that. I have a lock model Loock Smart Lock V5 Max Website: https://home.miot-spec.com/spec/loock.lock.fcl201 I manually configured the converter. But I found that the door status will never change. So I turned on the debug mode and found that the lock did not seem to send me the door status, but everything was displayed normally in the Mijia APP

The converter is as follows

{
    9877: ["Loock", "Loock Smart Lock V5 Max", "FCL201"],
    "spec": [
        BaseConv("action", "sensor"),
        BaseConv("key_id", mi="2.e.1020.p.4"),
        MapConv("method", "sensor", mi="2.e.1020.p.2", map={
            1: "mobile", 2: "fingerprint", 3: "password", 4: "nfc", 5: "face", 6: "Finger Vein", 
            7: "Palm Print", 8: "key", 9: "one_time_password", 10: "periodic_password", 
            11: "Homekit", 12: "coerce", 13: "Two Step Verification", 14: "Turntable", 
            15: "manual", 16: "auto"
        }),
        MapConv("lock_action", "sensor", mi="2.e.1020.p.3", map={
            1: "lock", 2: "unlock", 3: "lock_outside", 4: "lock_inside",
            5: "unlock_inside", 6: "enable_child_lock", 7: "disable_child_lock",
            8: "enable_away", 9: "disable_away"
        }),
        MapConv("door_state", "sensor", mi="3.p.1021", map={
            16: 'Locked',
            20: 'Locked',
            24: 'Locked',
            28: 'Locked',
            32: 'Unlocked',
            36: 'Unlocked',
            40: 'Unlocked',
            44: 'Unlocked',
            48: 'Leaving The Door Open Timed Out',
            52: 'Leaving The Door Open Timed Out',
            56: 'Leaving The Door Open Timed Out',
            60: 'Leaving The Door Open Timed Out',
            64: 'Door Was Ajar',
            68: 'Door Was Ajar',
            72: 'Door Was Ajar',
            76: 'Door Was Ajar'
        }),
        MapConv("abnormal_type", "sensor", mi="2.e.1020.p.6", map={
            1: "Frequent Unlocking Failed By Multiple Methods", 
            2: "Frequent Unlocking Failed By Password", 
            3: "Frequent Unlocking Failed By Fingerprint", 
            4: "Frequent Unlocking Failed By NFC", 
            5: "Frequent Unlocking Failed By Face", 
            6: "Frequent Unlocking Failed By Palmprint", 
            7: "Frequent Unlocking Failed By Finger Vein", 
            8: "Frequent Unlocking Failed By Key", 
            9: "Door Lock Was Damaged", 
            10: "Locked Unsuccessfully", 
            11: "Unlock From Inside After Leaving Home", 
            12: "Door Lock Was Reset", 
            13: "Foreign Object Detected In The Keyhole", 
            14: "Key Was Not Removed", 
            15: "Door Lock Fingerprint Sensor Error", 
            16: "Door Lock Mechanical Failure", 
            17: "Door Lock Main Part Failure", 
            18: "The Lithium Battery Temperature Is Too High", 
            19: "Large Batteries Are Low", 
            20: "Small Batteries Are Low", 
            21: "Large And Small Batteries Are Low", 
            22: "Large And Small Deplete", 
            23: "Leaving The Door Open Timed Out", 
            24: "Door Was Ajar", 
            25: "Door Was Opened Forcefully", 
            26: "Small Batteries Are Nearly Depleted", 
            27: "Small Batteries Are Nearly Depleted And Large Batteries Low", 
            28: "Large Batteries Are Nearly Depleted", 
            29: "Large Batteries Are Nearly Depleted And Small Batteries Low", 
            30: "Large Batteries Are Removed", 
            31: "Large Batteries Are Inserted", 
            32: "Small Batteries Are Removed", 
            33: "Small Batteries Are Inserted", 
            34: "Battery Low The Cat Eye Function And The Door Screen Are Suspended", 
            35: "Ultrasonic Sensitivity Decreased"
        }),
        MapConv("position", "sensor", mi="2.e.1020.p.1", map={
            1: "indoor", 2: "outdoor", 3: "not tell indoor or outdoor"
        }),
        BaseConv("lock_timestamp", "sensor", mi="2.e.1020.p.5"),  # lock timestamp

        # doorbell
        ConstConv("action", mi="5.e.1006", value="doorbell"),
        BaseConv("doorbell_timestamp", "sensor", mi="5.e.1006.p.1"),  # doorbell timestamp

        # battery sensor
        BaseConv("battery", "sensor", mi="4.p.1003"),
        BaseConv("changing", "sensor", mi="4.p.1034"),
    ],
}

The log is as follows

2024-08-28 20:10:27.256 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.10.123.2.8] {'topic': 'central/report', 'data': b'{"id":1860586428,"_to":128,"type":6,"method":"event_occured","params":{"did":"1064843091","siid":2,"eiid":1020,"tid":79,"arguments":[{"piid":1,"value":3},{"piid":2,"value":15},{"piid":3,"value":1},{"piid":4,"value":0},{"piid":5,"value":1724847027}]}}'}
2024-08-28 20:10:27.256 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.10.123.2.8] {'uid': '1e15f98f559c', 'did': '1064843091', 'msg': 'on_report', 'data': {'position': 'not tell indoor or outdoor', 'method': 'manual', 'lock_action': 'lock', 'key_id': 0, 'lock_timestamp': 1724847027}}
2024-08-28 20:10:27.359 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.10.123.2.8] {'topic': 'central/report', 'data': b'{"id":2015708429,"type":6,"method":"event_occured","params":{"did":"1064843091","siid":2,"eiid":1020,"tid":79,"arguments":[{"piid":1,"value":3},{"piid":2,"value":15},{"piid":3,"value":1},{"piid":4,"value":0},{"piid":5,"value":1724847027}]}}'}
2024-08-28 20:10:27.945 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.10.123.2.8] {'topic': 'miio/report', 'data': b'{"id":786822287,"method":"_async.stat","params":{"version":1,"btstat_props":[{"did":"1130635986","siid":2,"aiid":0,"piid":1,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":30000,"cost":30000,"ret":0,"result":-2},{"did":"1130635986","siid":3,"aiid":0,"piid":3,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":30200,"cost":30000,"ret":0,"result":-2},{"did":"1130635986","siid":2,"aiid":0,"piid":5,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":30400,"cost":30000,"ret":0,"result":-2},{"did":"1130635986","siid":2,"aiid":0,"piid":3,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":30600,"cost":30000,"ret":0,"result":-2}]}}'}
2024-08-28 20:10:28.064 WARNING (MainThread) [homeassistant.components.humidifier] Updating xiaomi_miot humidifier took longer than the scheduled update interval 0:00:01
2024-08-28 20:10:28.094 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.10.123.2.8] {'topic': 'miio/report_ack', 'data': b'{"id":786822287,"result":"ok"}'}
2024-08-28 20:10:28.485 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.10.123.2.8] {'topic': 'miio/report', 'data': b'{"id":1156056288,"method":"_async.stat","params":{"version":1,"btstat_props":[{"did":"1130635986","siid":2,"aiid":0,"piid":4,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":30800,"cost":30000,"ret":0,"result":-2},{"did":"1130635986","siid":2,"aiid":0,"piid":2,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":31000,"cost":30000,"ret":0,"result":-2},{"did":"1130635986","siid":3,"aiid":0,"piid":2,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":31200,"cost":30000,"ret":0,"result":-2},{"did":"1130635986","siid":3,"aiid":0,"piid":4,"control_type":1,"from":"","rpc_addr":0,"control_times":1,"total":31400,"cost":30000,"ret":0,"result":-2}]}}'}

home-assistant_2024-08-28T12-10-44.186Z.log

AlexxIT commented 2 months ago

Many locks doesn't have statuses. They only have events. Event is an action in some moment. Events only fire if something have changed.

GavinIves commented 2 months ago

But I didn't find the corresponding action in the log. When I opened the door, there was no door opening action. Is my debugging method wrong?

AlexxIT commented 2 months ago

Your method ok. If you can see event in MiHome and can't see event in Hass logs - I have never heard about this situation for 4 years of developing this component.

GavinIves commented 2 months ago

I don't know if it has anything to do with my homekit connection because I saw someone with the same lock as mine, but he can display the door status while I can't. We both use the same converter. url Can you help me check the log? There are indeed only some statuses in my log. The following are the door lock related logs I selected from the log.

2024-08-28 20:10:27.256 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.10.123.2.8] {'topic': 'central/report', 'data': b'{"id":1860586428,"_to":128,"type":6,"method":"event_occured","params":{"did":"1064843091","siid":2,"eiid":1020,"tid":79,"arguments":[{"piid":1,"value":3},{"piid":2,"value":15},{"piid":3,"value":1},{"piid":4,"value":0},{"piid":5,"value":1724847027}]}}'}
2024-08-28 20:10:27.256 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.10.123.2.8] {'uid': '1e15f98f559c', 'did': '1064843091', 'msg': 'on_report', 'data': {'position': 'not tell indoor or outdoor', 'method': 'manual', 'lock_action': 'lock', 'key_id': 0, 'lock_timestamp': 1724847027}}
2024-08-28 20:10:27.359 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.10.123.2.8] {'topic': 'central/report', 'data': b'{"id":2015708429,"type":6,"method":"event_occured","params":{"did":"1064843091","siid":2,"eiid":1020,"tid":79,"arguments":[{"piid":1,"value":3},{"piid":2,"value":15},{"piid":3,"value":1},{"piid":4,"value":0},{"piid":5,"value":1724847027}]}}'}
AlexxIT commented 2 months ago

As I can see - event decoded without errors

{
    "id": 1860586428,
    "_to": 128,
    "type": 6,
    "method": "event_occured",
    "params": {
        "did": "1064843091",
        "siid": 2,
        "eiid": 1020,
        "tid": 79,
        "arguments": [
            {
                "piid": 1,
                "value": 3 // position: not tell indoor or outdoor
            },
            {
                "piid": 2,
                "value": 15 // method: manual
            },
            {
                "piid": 3,
                "value": 1 // lock_action: lock
            },
            {
                "piid": 4,
                "value": 0 // key_id: 0
            },
            {
                "piid": 5,
                "value": 1724847027 // lock_timestamp: 1724847027
            }
        ]
    }
}
GavinIves commented 2 months ago

I checked and it is the same, but I feel that it sometimes misses data. For example, sometimes when I open the door, it still shows locked, but the Mijia app shows that the door is open. So I suspect that Mijia is getting other data because Mijia is always accurate, but sometimes it misses data.

AlexxIT commented 2 months ago

Do you have other BLE gateways?

GavinIves commented 2 months ago

Sorry, I don't have one. I want to know if it is possible, for example, that the message is not sent through the gateway but through wifi because this is a lock that works with wifi and bluetooth.

AlexxIT commented 2 months ago

I think it can be possible. You can try to block internet for your lock if your router can do this.

gx19970920 commented 2 months ago

I checked and it is the same, but I feel that it sometimes misses data. For example, sometimes when I open the door, it still shows locked, but the Mijia app shows that the door is open. So I suspect that Mijia is getting other data because Mijia is always accurate, but sometimes it misses data.

请问您的v5max现在正常工作了吗?您解决这个问题了吗

GavinIves commented 2 months ago

没有依旧无效 放弃了

gx19970920 commented 2 months ago

没有依旧无效 放弃了

好的谢谢,我再找找方法,如果有效的话我在这回复