FacebooktwitterredditpinterestlinkedinmailFacebooktwitterredditpinterestlinkedinmail

I had recently put Sengled Zigbee bulbs in my nightstand lamps to pair with Zigbee2MQTT on Home Assistant. I was using them to automatically turn the lights off/on when playing/pausing a movie on the TV. However, we found ourselves cutting power to the night stand to turn them off since pulling out our phone to turn them off was too much of a hassle. So when they had no power, the automation for those bulbs wouldn’t work unless I manually turned them back on. Not an ideal situation. That’s when I started my hunt for smart buttons. I bought some Echo Buttons, as I wrote about previously, but their bulkiness and ugliness just didn’t work for me. So I decided to get a couple types of the Xiaomi Aqara buttons:

They also make a single button version of the second switch, along with wired versions of the second switch. Although I’m not sure how well it will work with US wiring. I’m pretty sure it won’t be simple to get it to fit in a standard electrical box.

For those of you that are just looking for my quick opinion on these: I have been using them for about a month now, and I love them. They look good, the button click feels good, and most importantly, they just work. I only have one issue, and I’m pretty sure it’s a Home Assistant/Zigbee2MQTT issue. Sometimes, after restarting HA, or turning the power to a bulb on/off manually, it pressing the button doesn’t turn the bulb on/off the first time, and I have to press it again. But after that first time, it works flawlessly, until I restart again, which isn’t often. I get this same behavior through the HA web interface, so I’m 99% sure that this isn’t a flaw with the buttons. If you have a need for a smart button, and you have Zigbee2MQTT, I would recommend these buttons. If you have another Zigbee platform, there’s a good chance they will work with that as well. I did have another issue with pairing, but I can get it going without issues now. Just read on if you need help pairing it.

Pairing the Aqara button with Zigbee2MQTT

This was the most challenging part for me. And it took me a while to figure it out. First enable pairing in Zigbee2MQTT. To pair the dual button, you have to hold one of the buttons for 10 seconds. The blue LED will turn off and then back on. That is when it’s ready for pairing. The Mini Button has a tiny button on the side. Just hold that for 3 seconds, and it will start pairing mode.

Now the trick for both buttons is that after it starts pairing mode, you need to press the button every 2 seconds to keep it awake. I think that with the Xiaomi official hub, it is sending some signal to keep it awake until pairing is complete. However, with other hubs, they aren’t sending that signal, so we have to keep them awake manually until they pair.

Once it is paired, it should show up as a sensor at the top of Home Assistant. You may need to switch to the ‘States’ view in case you have made the switch to Lovelace.

Now, when you press the button, you should see the states of those sensors change. For the dual button, you have 5 possible states: left, right, left_double, right_double, and both. Although if you double click too fast, sometimes it won’t register it. For the Mini, you have click, double_click, triple_click, and quadruple click.

You can use any of those types of clicks to create an automation in Home Assistant.

Home Assistant automation with buttons:

I haven’t really setup the single button to do anything yet, so below I’m just going to post the HA yaml code for what I’m using the buttons for. That is to toggle our nightstand lights. Left/right clicks toggles the left/right lamps, and pressing both buttons at once toggles both lamps. It should be pretty straightforward to take this code and have it do whatever action you want. As a bonus I went ahead and posted the automation to turn the lights off shortly after sunrise (We were sometimes turning the lights on when we got up and then forgetting to turn them off when we left for work).

- alias: MasterButtonLeft
  initial_state: True
  hide_entity: true
  trigger:
  - platform: mqtt
    topic: 'zigbee2mqtt/0x00158d0002f07928'
  condition:
    condition: template
    value_template: "{{ 'left' == trigger.payload_json.click }}"
  action:
    service: light.toggle
    entity_id: light.0xb0ce181403202c53_2
    
- alias: MasterButtonRight
  initial_state: True
  hide_entity: true
  trigger:
  - platform: mqtt
    topic: 'zigbee2mqtt/0x00158d0002f07928'
  condition:
    condition: template
    value_template: "{{ 'right' == trigger.payload_json.click }}"
  action:
    service: light.toggle
    entity_id: light.0xb0ce181400012763
    
- alias: MasterButtonBoth
  initial_state: True
  hide_entity: true
  trigger:
  - platform: mqtt
    topic: 'zigbee2mqtt/0x00158d0002f07928'
  condition:
    condition: template
    value_template: "{{ 'both' == trigger.payload_json.click }}"
  action:
    service: light.toggle
    entity_id: 
      - light.0xb0ce181403202c53_2
      - light.0xb0ce181400012763
- alias: SunriseBedLightsOff
  initial_state: true
  hide_entity: true
  trigger:
    platform: sun
    event: sunrise
    offset: "+00:20:00"
  action: 
    service: light.turn_off
    entity_id: 
      - light.0xb0ce181400012763
      - light.0xb0ce181403202c53_2

And if need any help with this, or if you have any comments, please post them below.

 

3 Replies to “Using the Xiaomi Aqara buttons with Home Assistant via Zigbee2MQTT

Leave a Reply

Your email address will not be published. Required fields are marked *