[Square Xiaomi] Single click to light automation

Hello,

I’m trying to create a basic automation using a Xiaomi Square (WXKG11LM) to turn_on a light.

I have checked on forum and googled it but still doesn’t work after some tests…

Here is the automation :

- id : 'light_bulb_automation_click'
  alias: Light Bulb Click
  trigger:
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
        entity_id: sensor.0x00158d000204a63d_click
        click_type: single
  action:
    - service: light.toggle
      entity_id:
        - light.bulb_floor

Everywhere, i see binary_sensor instead of sensor that i have, could it be the issue ?

Thank you for your help.

Hello,

To complete the request, i can see the click status in the service tab.
I really don’t know what i missed.

Axel

Hello,

Speaking alone but find my way.

Here is what i have done for someone looking to use it :

  • id : ‘light_bulb_automation_click’
    alias: Light Bulb Click
    initial_state: true
    hide_entity: true
    trigger:
    • platform: mqtt
      topic: ‘zigbee2mqtt/0x00158d000204a63d’
      condition:
      condition: template
      value_template: “{{ ‘single’ == trigger.payload_json.click }}”
      action:
      • service: light.toggle
        entity_id: light.bulb_floor
      • service: notify.ios_iphax
        data:
        title: “[LIGHT] {{states(‘light.bulb_floor’)}}”
        message: “Floor Bulb”

Your initial automation would have worked if you were using the Xiaomi hub. Since you are using Zigbee2MQTT that’s why your latest attempt worked.

Yes indeed.
It’s why i have changed and used the platform mqtt instead.

My suggestion would be to use node-red for this type of automation.
its expecially easy if you also use hassio since the add-on for nodered is all preconfigured for home assistant integration.
Using xiaomi buttons your automation is as simple as this:

Event from the button --> Switch for whether its one click or two --> action for each 1/2 clicks

Look at the lists of entities shown on the States page. That’s where you will learn if the device is represented as a sensor or binary_sensor.

1 Like

@hijinx Indeed, i have nodered installed also but not yet try it. I’ll use for this automation and check how is it going.

@123 Thank for the tip.

I’m putting all my automations through node-red now.
I much prefer it to yaml.

Ok.

With Nodered, just created the automation and click deploy directly work on Hassio ?

Yes, should do.

Ok let’s try later.

I’ll already created an automation for the Single and Double clicks :sunglasses: :

Same logic as you but it’s for test.

I was fumbling with this.

Then I came upon this post (#3) with the automation template you came up with.

Now it makes sense.

Thanks.

Hi , just trying to make your script working but no luck.

- id : ‘click’
  alias: Light Bulb Click
  initial_state: true
  hide_entity: true
  trigger:
    - platform: mqtt
      topic: ‘zigbee2mqtt/0x00158d0002eb5a33’
      condition:
       condition: template
       value_template: “{{ ‘single’ == trigger.payload_json.click }}”
       action:
        - entity_id: light.living_room
          service: light.toggle

Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->trigger->0->condition. (See ?, line ?).

Any help?
thanks

Try this:

- id: 'click'
  alias: 'Light Bulb Click'
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/0x00158d0002eb5a33'
  condition:
    condition: template
    value_template: "{{ trigger.payload_json.click == 'single' }}"
  action:
    service: light.toggle
    entity_id: light.living_room

Notice the difference in indentation and the type of single and double quotes used.

thanks :slight_smile:

i solved

- id: welcome
  alias: welcome_home
  trigger:
  - platform: state
    entity_id: sensor.0x00158d0002eb5a33_click_1
    to: single
  condition: []
  action:
  - entity_id: light.living_room
    service: light.toggle