elric91 / homeassistant_zigate

Custom components for Home Assistant
MIT License
22 stars 5 forks source link

Aqara button #20

Open RiRomain opened 6 years ago

RiRomain commented 6 years ago

As of now, it's not possible to use all the function of the aqara push button.

Either it's configured as a sensor and the single click doesn't work.

sensor:
  - platform: zigate
    name: 'aqara_push_button'
    address: 401501
    default_state: 'state'

Or as a toggle switch and the multi click doesn't work

switch:
  - platform: zigate
    name: 'aqara_push_button'
    address: f5c901
    autotoggle_delay: 2
    default_state: 'state'
    type: 'toggle'

As a sensor, the single click doesn't work because the state is set from Closed/Taken off/Press back to Open/Release button too fast for home-assistant to see the state change.

I added a log entry in function update_attributes and in function state to make this behavior easy to recognize. In update_attributes, we make a call to self.schedule_update_ha_state but the state updates all happened after the attributes have already been reset to Open/Release button

2018-04-07 14:12:23 DEBUG (MainThread) [zigate] --------------------------------------
2018-04-07 14:12:23 DEBUG (MainThread) [zigate] RESPONSE 8102 : Attribute Report / Response
2018-04-07 14:12:23 INFO (MainThread) [zigate]   * General: On/Off
2018-04-07 14:12:23 INFO (MainThread) [zigate]   * Closed/Taken off/Press
2018-04-07 14:12:23 INFO (MainThread) [zigate]   FROM ADDRESS      : b'4015'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Source EndPoint : b'01'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Cluster ID      : b'0006'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute ID    : b'0000'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute type  : b'10'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute size  : 1
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute data  : b'00'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   # encoded : b'018102120210021e6e2a4015021102100216021002100210100210021102108a03'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   # decoded : 0181 02 00 0E 6E 2A 40 15 01 00 06 00 00 00 10 00 01 00 8A03
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   (@timestamp : 14:12:23)
2018-04-07 14:12:23 WARNING (SyncWorker_3) [custom_components.sensor.zigate] Property update: last seen: 2018-04-07 14:12:23
2018-04-07 14:12:23 WARNING (SyncWorker_4) [custom_components.sensor.zigate] Property update: state: on-press
2018-04-07 14:12:23 DEBUG (MainThread) [zigate] --------------------------------------
2018-04-07 14:12:23 DEBUG (MainThread) [zigate] RESPONSE 8102 : Attribute Report / Response
2018-04-07 14:12:23 INFO (MainThread) [zigate]   * General: On/Off
2018-04-07 14:12:23 INFO (MainThread) [zigate]   * Open/Release button
2018-04-07 14:12:23 INFO (MainThread) [zigate]   FROM ADDRESS      : b'4015'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Source EndPoint : b'01'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Cluster ID      : b'0006'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute ID    : b'0000'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute type  : b'10'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute size  : 1
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   - Attribute data  : b'01'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   # encoded : b'018102120210021e6f2a4015021102100216021002100210100210021102118a03'
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   # decoded : 0181 02 00 0E 6F 2A 40 15 01 00 06 00 00 00 10 00 01 01 8A03
2018-04-07 14:12:23 DEBUG (MainThread) [zigate]   (@timestamp : 14:12:23)
2018-04-07 14:12:23 WARNING (SyncWorker_5) [custom_components.sensor.zigate] Property update: last seen: 2018-04-07 14:12:23
2018-04-07 14:12:23 WARNING (SyncWorker_2) [custom_components.sensor.zigate] Property update: state: off-release
2018-04-07 14:12:23 WARNING (MainThread) [custom_components.sensor.zigate] Returning state
2018-04-07 14:12:23 WARNING (MainThread) [custom_components.sensor.zigate] Returning state
2018-04-07 14:12:23 WARNING (MainThread) [custom_components.sensor.zigate] Returning state
2018-04-07 14:12:23 WARNING (MainThread) [custom_components.sensor.zigate] Returning state

I've tried to modify update_attributes to call schedule_update_ha_state(True) instead of schedule_update_ha_state() and therefore force the update. But without success.

schedule_update_ha_state(force_refresh=False)[source] Schedule an update ha state change task.

Is there another way to force Home-Assistant to register this very short state change? Or what is the best way to handle those push button?

elric91 commented 6 years ago

Multi click is normally handled by the button itself and should send a cluster : 0006/ attribute : 8000 event (not 0006/0000) as in your example (so one event only, and you should have the number of clicks in the attribute data').

Can you confirm that you have no event 0006 / 8000 in your log ?

RiRomain commented 6 years ago

Multi click is recognised, the problem is that the single click is not recognize when configured as a sensor. The pressed and released signal arriving too fast after another.

RiRomain commented 6 years ago

I'll add the multi click log entry tomorrow:-)

mvdkleijn commented 6 years ago

@RiRomain is this still an issue and does it also affect the round v1 xiaomi buttons? I've got single click working as a toggle, but would like to be able to use both single and multi click.

RiRomain commented 6 years ago

Yes, it's still an issue. Mine is the square aqara button.