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.44k stars 342 forks source link

BLE lock automation failed after upgrading to 1.5.0 #469

Closed hellkun closed 3 years ago

hellkun commented 3 years ago

I've a BLE lock (Loock S30), I used its action (to_state: lock) as a trigger in one of my automations, however, it stops working after upgrading to 1.5.0.

The log seems alright, like:

2021-09-22 19:06:54  DEBUG    gateway3      10.0.10.32 | MQTT | ble/cc86ec7f4e59 b'{"lock":1,"opening":0,"battery":96,"action":"lock","action_id":0,"method_id":2,"message":"Unlock outside the door","method":"biological","key_id":0,"error":null,"timestamp":"2021-09-22T19:06:05"}'

But, according to the trace of the automation, the new to_state is "key_id", as well as the 'action' in its attributes, which seems weird, I guess it's the problem which stops my automation working. The trace are shown below:

this:
  entity_id: automation.wan_shang_cong_wai_bu_kai_men_shi_kai_deng
  state: 'on'
  attributes:
    last_triggered: '2021-09-22T11:06:57.553525+00:00'
    mode: single
    current: 0
    id: '1628175774547'
    friendly_name: 晚上从外部开门时开灯
  last_changed: '2021-09-22T11:24:48.174828+00:00'
  last_updated: '2021-09-22T11:24:48.174828+00:00'
  context:
    id: 810b4e5389350c07d062f5884eb3901c
    parent_id: null
    user_id: null
trigger:
  id: '0'
  idx: '0'
  platform: state
  entity_id: sensor.cc86ec7f4e59_action
  from_state:
    entity_id: sensor.cc86ec7f4e59_action
    state: ''
    attributes:
      action: key_id
      action_id: 1
      key_id: '0x200100ff'
      message: Match failed
      friendly_name: 鹿客全自动推拉门锁S30 Action
      icon: mdi:bell
    last_changed: '2021-09-22T11:42:05.493337+00:00'
    last_updated: '2021-09-22T11:42:05.493337+00:00'
    context:
      id: df8c4209d6460c17b6b03256cd99c509
      parent_id: null
      user_id: null
  to_state:
    entity_id: sensor.cc86ec7f4e59_action
    state: key_id
    attributes:
      action: key_id
      action_id: 0
      method_id: 2
      message: Unlock outside the door
      method: biological
      key_id: 2
      error: null
      timestamp: '2021-09-22T19:41:17'
      friendly_name: 鹿客全自动推拉门锁S30 Action
      icon: mdi:bell
    last_changed: '2021-09-22T11:42:08.156788+00:00'
    last_updated: '2021-09-22T11:42:08.156788+00:00'
    context:
      id: 1b5800f6ee3d8e63cde9fa0af0a01294
      parent_id: null
      user_id: null
hoangtridung commented 3 years ago

The same problem with Aqara smartlock N100. Only with LOCK event, the DOOR event is good

AlexxIT commented 3 years ago

Sorry. Problem from this commit https://github.com/AlexxIT/XiaomiGateway3/commit/0dd5b78c652905e9c6792eaa656c11650c519c54

dscao commented 3 years ago

sensor.py line 324: modify: elif k in ('key_id', 'lock_control', 'lock_state'): to: elif k in ('lock_control', 'lock_state'): Then it's OK.

hellkun commented 3 years ago

I could confirm this is fixed in 1.5.1, so I'm closing it. Thanks for your great work, @AlexxIT