Xiaomi Gateway not registering click events in HA?

I’m trying to integrate these Aqara switches and can’t seem to get them to show a state change in HA.

Below is my package for it. I’m trying to keep track of the last command sent to control the curtains with the input_boolean. But I’ve also tried just having the excerpt from the component and it fails to register the click.

I have verified that HA is able to communicate with the gateway via the xiaomi_aqara.play_ringtone service on the services tab but it does log Got error element in data {"error":"Invalid key"} .

Any ideas where I can look?

# curtains package
  input_boolean:
    curtainssmartswitch:
      initial: off


  switch:
    - platform: template
      switches:
        curtainssmartswitch:
          friendly_name: Curtain Smart Switch
          value_template: "{{ is_state('input_boolean.curtainssmartswitch', 'on') }}"
          turn_on:
            service: input_boolean.turn_on
            data:
              entity_id: input_boolean.curtainssmartswitch
          turn_off:
            service: input_boolean.turn_off
            data:
              entity_id: input_boolean.curtainssmartswitch

    - platform: template
      switches:
        bedroomcurtains:
          value_template: "{{ is_state('switch.bedroomcurtains', 'on') }}"
          turn_on:
            service: script.turn_on
            data:
              entity_id: script.curtains_open
          turn_off:
            service: script.turn_on
            data:
              entity_id: script.curtains_close




  automation:
    - alias: curtains_open
      trigger:
        - platform: state
          entity_id: input_boolean.curtainssmartswitch
          to: 'on'
      action:
        - service: script.curtains_open
    - alias: curtains_close
      trigger:
        - platform: state
          entity_id: input_boolean.curtainssmartswitch
          to: 'off'
      action:
        - service: script.curtains_close
    - alias: Curtains Smart Button Toggle
      trigger:
        platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d00019cd406
          click_type: single
      action:
        service: switch.toggle
        entity_id: switch.curtainssmartswitch
    - alias: Curtains Smart Button Stop
      trigger:
        platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d00019cd406
          click_type: double
      action:
        service: switch.on
        entity_id: switch.curtains_stop

Before going into the complex automation … have you checked on the HA GUI if the 'Click" is detected at all ?

I had the same issues with some switches and had to redo to connect sequence (upto 3 times) before the ‘click’ and “long press” was reaching in HA.

see this thread

basically they have no state as they are momentary, but you can use the click event to toggle them

I looked at the switch.curtainssmartswitch which is supposed to change based on the click and it is not. Is there a more direct way of watching it in the GUI that I’me not aware of?

That’s what I gathered from reading the components page. It seems that the automation should still function if it’s receiving the trigger. And the automation format is copied from the gateway’s component’s example.