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.48k stars 349 forks source link

The problem of identifying locks as door #1297

Closed Mcui7 closed 8 months ago

Mcui7 commented 8 months ago

Hi, my Aqara N200 lock (ZNMS17LM) has been identified as a door, and I am unable to determine whether the door is opening inward or outward. Is there a way for him to recognize it as a lock?

Xiaomi Multimode Gateway (CN) -ZNDMWG03LM Firmwares 1.5.4_0090

I tried unlock inside the door, unlock outside the door, and lifting the door handle. But it still shows as door. And there are only two states : Door is open or Door is closed But in miot, it can be seen that there are inside and outside

AlexxIT commented 8 months ago

Show device diagnostics

Mcui7 commented 8 months ago

Show device diagnostics

{
  "home_assistant": {
    "installation_type": "Home Assistant Container",
    "version": "2023.12.1",
    "dev": false,
    "hassio": false,
    "virtualenv": false,
    "python_version": "3.11.6",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Asia/Shanghai",
    "os_name": "Linux",
    "os_version": "4.4.302+",
    "run_as_root": true
  },
  "custom_components": {
    "xiaomi_gateway3": {
      "version": "3.3.6",
      "requirements": [
        "zigpy>=0.44.1"
      ]
    },
    "xiaomi_miot": {
      "version": "0.7.15",
      "requirements": [
        "construct>=2.10.56",
        "python-miio>=0.5.6",
        "micloud>=0.3"
      ]
    },
    "hacs": {
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    }
  },
  "integration_manifest": {
    "domain": "xiaomi_gateway3",
    "name": "Xiaomi Gateway 3",
    "codeowners": [
      "@AlexxIT"
    ],
    "config_flow": true,
    "dependencies": [
      "http"
    ],
    "documentation": "https://github.com/AlexxIT/XiaomiGateway3",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/AlexxIT/XiaomiGateway3/issues",
    "requirements": [
      "zigpy>=0.44.1"
    ],
    "version": "3.3.6",
    "is_built_in": false
  },
  "data": {
    "version": "6a494ae",
    "options": {
      "host": "***",
      "token": "***",
      "key": "CLzUi8SFG4Jotimt"
    },
    "errors": [],
    "device": {
      "type": "ble",
      "model": 1695,
      "fw_ver": null,
      "available": true,
      "decode_time": 30,
      "entities": {
        "action": "",
        "battery": {
          "state": "50",
          "value": 50
        },
        "contact": "off"
      },
      "gateways": [
        "54ef44cf1323"
      ],
      "unique_id": "f9479ba37cdc"
    },
    "logger": [
      {
        "ts": "2024-03-07T23:16:21.889",
        "type": "decode_mibeacon",
        "value": {
          "eid": 4106,
          "edata": "3244DAE965"
        }
      },
      {
        "ts": "2024-03-07T23:16:52.884",
        "type": "decode_mibeacon",
        "value": {
          "eid": 4106,
          "edata": "3263DAE965"
        }
      },
      {
        "ts": "2024-03-07T23:17:23.887",
        "type": "decode_mibeacon",
        "value": {
          "eid": 4106,
          "edata": "3282DAE965"
        }
      },
      {
        "ts": "2024-03-07T23:17:54.891",
        "type": "decode_mibeacon",
        "value": {
          "eid": 4106,
          "edata": "32A1DAE965"
        }
      },
      {
        "ts": "2024-03-07T23:18:25.892",
        "type": "decode_mibeacon",
        "value": {
          "eid": 4106,
          "edata": "32C0DAE965"
        }
      },
      {
        "ts": "2024-03-07T23:18:56.894",
        "type": "decode_mibeacon",
        "value": {
          "eid": 4106,
          "edata": "32DFDAE965"
        }
      },
      {
        "ts": "2024-03-07T23:19:27.886",
        "type": "decode_mibeacon",
        "value": {
          "eid": 4106,
          "edata": "32FEDAE965"
        }
      }
    ]
  }
}
Mcui7 commented 8 months ago

The N200 device driver is defined as a door. Can it be changed to a lock to facilitate the identification of internal and external door openings

Mcui7 commented 8 months ago

I have read this page, tried to add the converter: Aqara N200

DEVICES = [{
    1695: ["Aqara", "Door Lock N200", "ZNMS17LM"],
    "spec": [
        Converter("door", "sensor", mi="3.p.2"),
        Converter("lock", "binary_sensor",  mi="2.p.1"),
    ],
}] + DEVICES

The status of the lock has always been unknown image

Mcui7 commented 8 months ago

Should I try changingConverter("lock", "binary_sensor", mi="2.p.1") to LockConv("lock", "binary_sensor", mi="2.p.1")? I am not at home right now, so I cannot try it directly. That's why I'm asking first.

AlexxIT commented 8 months ago

Have you read? https://github.com/AlexxIT/XiaomiGateway3/wiki/Handle-BLE-Locks

PS. I think your lock very old and doesn't support miot specs

Mcui7 commented 8 months ago

Yes, I have read https://github.com/AlexxIT/XiaomiGateway3/wiki/Handle-BLE-Locks. This lock was purchased in 2021, so it doesn't seem too old, right? However, there are indeed few properties visible in miot...

Because I work with Java, reading Python code is a bit challenging for me. I thought it was necessary to first map out the Lock device and then identify the status based on the corresponding action_id.

AlexxIT commented 8 months ago

Check this link https://home.miot-spec.com/s/lumi.lock.bzacn1 Lock from 2019 year. It sends data as events, not states.

Mcui7 commented 8 months ago

Alright, it seems there isn't a way to add integration directly. I'll think of another way to work around this; Thank you for the assistance provided.