Xiaomi Aqara Mini Switch doesn't show switch

OK I have the same, but just now realized you have a Xiaomi-Hub and not an Aqara-Hub. I added it via the Homekit-Controller --> https://www.home-assistant.io/integrations/homekit_controller/
You’ve probably added it via the Xiaomi-Integration, right? --> https://www.home-assistant.io/integrations/xiaomi_aqara/

OK for anyone who wants a stupid solution :smiley:

I create in the Aqara-App for each button-event i want to check an automation, each sets the Aqara-Hub-Light to a different brightness level, waits 1s, and turns it off again. And then I check in HA for the brightness-level, and thus i know which button was clicked.
Here’s my table for a Switch with 2 buttons, first is the brightness in the Aqara-App and second is the one in HA since in HA its from 0-255:

Single-L: 20 / 51
Double-L: 21 / 53.55
Long-L: 22 / 56.1
Single-R: 25 / 63.75
Double-R: 26 / 66.3
Long-R: 27 / 68.85

And then just create a template-sensor:

        tmpl_button2:
            friendly_name: "Button 2"
            value_template: >-
                {% if state_attr('light.aqara_hub_eab7', 'brightness') == 51 %}
                  Links_Klick
                {% elif state_attr('light.aqara_hub_eab7', 'brightness') == 53.55 %}
                  Links_Klick-Doppel
                {% elif state_attr('light.aqara_hub_eab7', 'brightness') == 56.1 %}
                  Links_Klick-Lang
                {% elif state_attr('light.aqara_hub_eab7', 'brightness') == 63.75 %}
                  Rechts_Klick
                {% elif state_attr('light.aqara_hub_eab7', 'brightness') == 66.3 %}
                  Rechts_Klick-Doppel
                {% elif state_attr('light.aqara_hub_eab7', 'brightness') == 68.85 %}
                  Rechts_Klick-Lang
                {% else %}
                  Fertig
                {% endif %}

Works so far, delay of ~1s to turn on a light :slight_smile:

1 Like

Thats brilliant! If it works its not stupid :smile:

Any news? Will it drop in 0.111.x?

Hey, I tried your setup and it kinda works for me, I adjust the brightness the same way you did, but sometimes the template sensor misbehaves, sometimes when I click once it will says Single_Click (working good) but then I would double click and it will still says Single_Click, then after a few presses it will change to Double_Click, (thinking it finally work but…) if I press the button once, it will still say Double_Click on the template sensor! Any insights on this?

I have the same issue. My Aqara switch is connected via a HUSBZB-1 though.

I open to suggestions as well.

I have now Zigbee2MQTT, but what I did was, I set the Hub-Light on, and then i check in HA for the brightness, then set the brightness to a default value, and then turn it of in the HA-Automation rather than on the Aqara-Automation. So it’s as long/short turn on as needed. Better then a set amount of time.
If you don’t set the brightness back to default, next time you turn the light on, for a short time it’s the old value.

Do you use Zigbee2MQTT? The Swtiches of Aqara are supported by it, so it should work normally.

I don’t, I use the ZHA integration with a HUSBZB-1. I thought the button was supposed to show up as switches, instead it just shows up as remote, and a battery sensor. I have had the HUSBZB-1 for a long time but I am just now getting around to trying it out.

I noticed on the remote that I could create an automation with it, started one and ended up with the below yaml code. Works great.

  - alias: 'Toggle Bedroom Fan'
    trigger: 
      - platform: device
        device_id: redacted
        domain: zha
        type: remote_button_short_press
        subtype: remote_button_short_press
    action:
      - service: fan.toggle
        entity_id: fan.bedroom_fan

The xiaomi normal wifi switch also only shows as battery sensors, hence not working either. Unfortunately that is a show stopper for me as I use the switches to connect other pieces that not part of the xiaomi world. I have been using Home Assistant since the beginning but unfortunately I will now have to find an alternative home automation system. I wish I could help solving the issue and I am very thankfull to all the great volunteers, but there seems to be more emphasis in developing a cool dark theme instead of solving this quite serious issue. How can I help in trying to solve the issue with stateless switches and Homekit integration, who should I talk too, I can try to help if I am pointed in the right direction,

1 Like

Hi,
I have the same problem and i wish a help to integrate the aqara switchs using the homekit integration (i want to have several mi smart hub in the house). I don’t want to get 50€ Conbee 2 just for some switches.
I red a lot about it and i don’t find any solution when we don’t get any event from the switch when listening to *.
I’m very new at home assistant and it’s a show stopper for me too.
Can you please help us to use this wonderful open source tool ?

This is serious issue for you and some others that use this device with homekit, but not really a quite serious issue of Home Assistant. Remember most devs are working for free!

You can use Zigbee2Mqtt if you want a permanent and “clean” solution.
Here is the Hardware list you need: https://www.zigbee2mqtt.io/getting_started/what_do_i_need.html

With this it works fine for me, ordered the hardware from Aliexpress, in my case my light-bulbs act as an extender for the zigbee signal through the house.

Remember this is not a company which has several developers to which they assign tasks. For most of the ingerations there is 1-2 persons which worked days over days for free to make it work. The developer of the Homekit-Integration is not the person which makes a dark theme.
And this is not a problem per se, it’s just something which is not supported at the moment.

EDIT: Didn’t see you have a WIFI-Switch, if you use a Xiaomi Gateway Version 1 it should work with the Xiaomi-Integration: https://www.home-assistant.io/integrations/xiaomi_aqara/
V2 seems to be not that easy to use with the Xiaomi-Integration. You’re still free to use my stupid but working solution i used before I switched to Zigbee2Mqtt :smiley:

Thanks for the replies, I fully understand that most contributions come from volunteers and I acknowledged that in my post. I often make donations and my self contribute to open source projects, and I am offering to contribute here, so I will take a look at the developers documentation as a starting point. I put my comments about the dark theme on purpose to stir up some discussions! It would be interesting to find out how many people actually uses Xiaomi products, it must be a huge number. For some context, I have been using the Xiaomi Gateway v2 for years and last month it died, so tried to buy another one, but the v2 is not available anymore, only the v3 (Miija and Aqara) both supporting HomeKit. HomeKit support in Home Assistant does not include stateless switch, which is the case of the ZigBee Xiaomi Miija ones. There are countless HA users posts asking the following questions:

1- Can not get a key for the new Xiaomi Gateway (v3 Miija and Aqara Homekit)
* With the new Gateway, that option is not available anymore, you have to use HomeKit integration
2- Xiaomi stateless switches are not working anymore

  • It is simply not supported in the HomeKit integration

There is no official HA integration documentation for the new Xiaomi Gateway (HomeKit version), hence why users keep asking the same question over and over.

So I am offering to to help here for selfish reason (I have over 60 devices from weather stations, irrigation monitoring, automated garage door based on proximity, lights, switches, automated heating, etc.) using Xiaomi, Broadlink, Tuya,Yeelights, ESP32, ESP8266, SONOFF, etc.all working together until now with Home Assistant on an OrangePi and now on a Odroid-N2.

1- I can write a Xiaomi HomeKit integration page, if I am allowed to, so users know what to do with the new Gateway and know that the stateless switches are not supported yet
2- I can “try” to find a solution to the stateless Zigbee switches, buying a Zigbee sniffer is one option but I would prefer to avoid having to buy yet another dongle. Someone (Jc2k) already had all events (including clicks from stateless switches) supported and integrated in the dev version 0.107 but was never accepted into the official release for whatever reason, So I will try to contact Jc2k and see what needs to be done and if I can help.

You solution using the lights intensity is cool but only works with the Aqara Gateway, I have the multimode Miija Gateway, HomeKit edition. My Xioami switches are ZigBee, not WiFi, my bad.

@mivilleb nagged me directly, but I figured it best to reply here. As i said here I added events to homekit_controller a few months ago. Since then i’ve really struggled to have any time for “big” Home Assistant tasks and have mostly being dealing with “weird” bugs in some of your devices. My favourites at the moment were Ecobee Switch taking “1”, “0” and “false” in a bollean field… but not “true”! And Tado’s bridge would not be able to handle valid JSON if it had spaces in it. Ugh!

But getting triggers right has been a bit of a slog. That is because “normal” homekit_controller code is leveraging the entity system in Home Assistant. A lot of skaffolding is already in place and mapping a new sensor to Home Assistant can be done in 25 lines of code. But AIUI the mini switch is like my phillips hue dimmer switch and is a “stateless” accessory.

For stateless accessories, there is no entity on the Home Assistant side. Theres much less skaffolding in place to hang the new code off of. So while I had a prototype back in March, i’ve not had time to structure it in a way that i thought was ready to go usptream into the Home Assistant code base.

@mivilleb kindly volunteered to try and help finish the code. Whilst trying to get the code into shape for @mivilleb to take a look at i came to the conclusion that actually what was needed was to get the HA devs to review it and see how they thought it could be improved. So I made some cleanups, added tests and submitted it in 2 pieces:

I expect a few rounds of code review on this of course, so don’t expect it to be imminent… But hopefully we are not far away.

Big shout out to mohannadon for encouraging me. Don’t think i’d have got round to it without your poking :wink: !

I would be very interested in your .storage/homekit_controller-entity-map files so I can test that the Mini Switch is correctly enumerated but it is working very well with my Phillips Hue dimmer switch (4 button remote).

Probably been nagging at the wrong tree, seems to me the python-miio is the way to go, the switches are not implemented there either but at least it does not have the overhead of Homekit. The problem I have is there does not seem to be any token for the switches, tried the log method and also been snooping around the gateway via Telnet, and looks like the switches are the only devices without a token. Also tried the DB backup Mi Home app method and returned nothing (maybe I need a rooted device?). Is it the same with others too, not being able to find a token for the Xiaomi zigbee switches?


A 2nd developer has completely by surprise contributed their own implementation of stateless switches for homekit_controller. So we’ve gone from having no PR’s to 2 competing ones!

(Obviously we are looking at how to work together to get one of them done).

Looking more and more likely that I won’t need to take up your kind offer of help @mivilleb!

Can you link to this implementation please?

1 Like

hi my friend,

what is the latest state integration?
I’m excitedly waiting for it to result. i have Home Assistant 0.115.4 but not yet my mini switch work