Yoda-x/ha-zha-new

Issue with WXKG01LM

Closed this issue · 7 comments

Hi,
I managed to connect the buttons and it showed up as
binary_sensor.binary_sensor_lumi_lumi_sensor_switch_032697bd_1_on_off

Issues I am facing is that single or double press does not work. Only triple presses works but even then it takes somewhere between 2-20 seconds to work. I am testing the button using a simple appdaemon script to listen for events from the buttons.
self.listen_state(self.test_button,"binary_sensor.binary_sensor_lumi_lumi_sensor_switch_032697bd_1_on_off")

# Function to test button
def test_button(self, *kwargs):
    self.log("Button Pressed.....")

I have the logger setup the following way-

logger:
  default: warning
logs:
  zigpy: debug
  custom_components.zha_new: debug

zigbee.db here

When button is pressed, I don't see anything related to this entity in the log. Just repetitions of the events below:

2019-06-20 22:49:08 DEBUG (MainThread) [zigpy.zcl] [0x5922:1:0x0000] ZCL request 0x000a: [[<Attribute attrid=65281 value=<zigpy.zcl.foundation.TypeValue object at 0x7fb38a089438>>]]
2019-06-20 22:49:08 DEBUG (MainThread) [zigpy.zcl] [0x5922:1:0x0000] Attribute report received: 65281=b'\x01!\xe5\x0b\x03(\x15\x04!\xa8\x13\x05!\x12\x00\x06$\x01\x00\x00\x00\x00\x08!\x04\x02\n!\x00\x00d\x10\x00'
2019-06-20 22:49:08 DEBUG (MainThread) [custom_components.zha_new.cluster_handler] Attribute report received on cluster [0x0000:65281:]=b'\x01!\xe5\x0b\x03(\x15\x04!\xa8\x13\x05!\x12\x00\x06$\x01\x00\x00\x00\x00\x08!\x04\x02\n!\x00\x00d\x10\x00'
2019-06-20 22:50:07 DEBUG (MainThread) [zigpy.application] neighbors: []
2019-06-20 22:50:07 DEBUG (MainThread) [zigpy.application] Topology updated

When I restart hassio, I see the following.

2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c] device init for <class 'str'>(lumi.sensor_switch)(00:15:8d:00:03:26:97:bd) -> Endpoints: [0, 1], already joined
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:0] endpoint init
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] endpoint init
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] node config for 00:15:8d:00:03:26:97:bd-1: {}
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] Import DH lumi.sensor_switch success
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] custom_info for lumi.sensor_switch: {'module': <module 'custom_components.device.lumi_sensor_switch' from '/config/custom_components/device/lumi_sensor_switch.py'>, '_custom_endpoint_init': <function _custom_endpoint_init at 0x7f30e89aea60>, '_custom_cluster_command': None, '_parse_attribute': <function _parse_attribute at 0x7f30e89ae598>, 'custom_parameters': None}
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] pre call _custom_endpoint_init: {'module': <module 'custom_components.device.lumi_sensor_switch' from '/config/custom_components/device/lumi_sensor_switch.py'>, '_custom_endpoint_init': <function _custom_endpoint_init at 0x7f30e89aea60>, '_custom_cluster_command': None, '_parse_attribute': <function _parse_attribute at 0x7f30e89ae598>, 'custom_parameters': None}
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] call _custom_endpoint_init: lumi.sensor_switch
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] node config for 00:15:8d:00:03:26:97:bd-1: {'in_cluster': [0, 6, 18], 'type': 'binary_sensor'}
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] config reports skipped for 00:15:8d:00:03:26:97:bd, already joined
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] 2:profile 260, component: binary_sensor cluster:[{0, 18, 6}, {768, 1280, 4, 5, 6, 8}] in_clusters: {0: <zigpy.zcl.clusters.general.Basic object at 0x7f30f18c0cf8>, 3: <zigpy.zcl.clusters.general.Identify object at 0x7f30f18c0d68>, 65535: <zigpy.zcl.clusters.manufacturer_specific.ManufacturerSpecificCluster object at 0x7f30f18c0dd8>, 25: <zigpy.zcl.clusters.general.Ota object at 0x7f30f18c0e48>, 1280: <zigpy.zcl.clusters.security.IasZone object at 0x7f30f18c0eb8>}
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] Single Cluster: set()
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1]general entity:260, component:binary_sensor clusters:{0, 1280, 3, 25, 65535}<->{0, 3, 4, 5, 6, 8, 25}
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c:1] Create general entity:00:15:8d:00:03:26:97:bd
2019-06-20 22:57:13 DEBUG (MainThread) [custom_components.zha_new] [0x562c] Exit device init 00:15:8d:00:03:26:97:bd

Are you using state changes or events?
I stopped some time ago to try to mimic a state device. Some devices still do, but beside on/off it makes no sense for the xiaomi button.
Please use the HA events, there you should see them all.
This is a simple event automation script I used for testing:

- alias: click_log
  id: click_log
  initial_state: False
  trigger:
    platform: event
    event_type: click
    # optional
    event_data:
      #entity_id: binary_sensor.ikea_of_sweden_tradfri_remote_control_fe39e28d_1
      channel: OnOff
  action:
    - service: logbook.log
      data_template:
        name: "click event: "
        message: "Entity {{ trigger.event.data.entity_id  }}, type {{ trigger.event.data.type }}"

The important part is the

event_type: click

If you don't match on the event data you should see all the created events (single/double/long click, etc)
Such remotes are stateless devices that only creates events.

I copy pasted your automation script and changed the entity_id and removed the channel data. It does not work. I don't see anything in the log.

- alias: click_log
  id: click_log
  initial_state: True
  trigger:
	platform: event
	event_type: click
	event_data:
	  entity_id: binary_sensor.binary_sensor_lumi_lumi_sensor_switch_032697bd_1_on_off
  action:
	- service: logbook.log
	  data_template:
		name: "click event: "
		message: "Entity {{ trigger.event.data.entity_id  }}, type {{ trigger.event.data.type }}"

Strange, it seems your button missing the Multistateinput (18) cluster, where in older buttons the events came in.
Can you click in the HA web interface on the device and check if any of the attributes changes, when you use the button.
Xiaomi may have changed the firmware in newer versions.

When I press the button nothing changes. If I soft press the reset button at the back, then iqi and rssi changes.

I am by no means an expert, but when I looked at hubitats implementation here, this switch looks different than the other ones.

I will create an extra DH file for your button. Possible my implementation does not cover it looking at the hubitats page

you may wanna try the newest master.
It has now a new device handler for your device. Please give it a try and let me know if it does anything better...

Thanks a lot. It works now. Closing the issue.