Using the Xiaomi Gateway & Button

I’ve fallen in love with my Xiaomi Smart Home kit. It really is an affordable, quality product. After connecting the Xiaomi Gateway to Home Assistant and the rest of my Smart-Home set up, I spent some time thinking about how I wanted to use it with the different sensors. I started with the Button. The lamps in my living room do not have light switches, so using the Button as a light switch was a pretty obvious choice.  The Gateway also has a couple more trick up its sleeve, that I’ll show you here.

This guide will teach you:

  • How to control the Gateway’s light with Home Assistant.
  • How to use the Gateway’s sound effects.
  • How to set up and use the (1st Gen) Xiaomi Button.

Notice:

This post has been marked as a legacy post and has been flagged to be updated.

If you would like to receive updates from Smart Home Hobby, please subscribe below.


The Xiaomi Gateway

Screen Shot 2017-11-04 at 11.42.32 AM

Gateway Light

By the end of the Xiaomi Gateway post, you should have been able to turn on and off the Gateway with the Home Assistant front end, as well as Alexa using your Echo device. The light can also be controlled using scripts.

Screen Shot 2017-11-02 at 8.13.01 PM

Screen Shot 2017-11-02 at 8.13.17 PM

https://gist.github.com/smarthomehobby/10483d70e483a475592e5086900e5e91

  • When utilizing a script, you can set the RGB Color, and the Brightness (0-255).

Screen Shot 2017-11-04 at 11.50.09 AM

  • I recommend finding a color you like, by using the Home Assistant front end, then checking the light’s state in the Developer’s Tools section of the menu.
  • Note the min_mireds and max_mireds parameters. These appear to be related to color temperature. I have not learned, yet, how or if these can be utilized.
  • I’ve found [255,103,23] to be a pretty good “Warm White” color.
    • This site has some helpful RGB codes for different types of lighting.

Gateway Sounds

  • The Gateway also has built in sound effects that can help the Gateway be used as a security alarm, an alarm clock, or a doorbell.
  • You can test/hear the different sounds within the MiHome App.
  • From the Gateway page, choose Devices
  • Choose the Gateway
  • Here are some more of the Gateway’s settings
  • I recommend changing the volume settings before testing the sound effects, it can be pretty loud.
  • I turn off the Radio and Notification volumes. The Radio stations are all in Chinese, and the Notification volume refers to the Chinese voice prompts.
  • Now, you can go the Ringtone settings
  • Go ahead and give them a go!

Ringtone ID’s

  • To reference these sounds in Home Assistant, you’ll need to use a ringtone_id. Home Assistant’s docs has them ID’d like this:
    •  Alarms
      • 0 – Police car 1
      • 1 – Police car 2
      • 2 – Accident
      • 3 – Countdown
      • 4 – Ghost
      • 5 – Sniper rifle
      • 6 – Battle
      • 7 – Air raid
      • 8 – Bark
    • Doorbells
      • 10 – Doorbell
      • 11 – Knock at a door
      • 12 – Amuse
      • 13 – Alarm clock
    • Alarm clock
      • 20 – MiMix
      • 21 – Enthusiastic
      • 22 – GuitarClassic
      • 23 – IceWorldPiano
      • 24 – LeisureTime
      • 25 – ChildHood
      • 26 – MorningStreamLiet
      • 27 – MusicBox
      • 28 – Orange
      • 29 – Thinker
  • The services you can use are xiaomi_aqara.play_ringtone and xiaomi_aqara.stop_ringtone.
  • Note that the sound effects will stop playing once it has ended, the stop ringtone service will just stop the sound effect earlier.
    • Pushing the button on the Gateway will also stop the sound. This would work really well for an alarm clock.

Screen Shot 2017-11-04 at 2.27.52 PM

https://gist.github.com/smarthomehobby/644b6c84e0ddc44cfd8f29f2ef36fe95

  • This configuration can be added to a trigger for an automation.

Screen Shot 2017-11-04 at 2.53.04 PM

https://gist.github.com/smarthomehobby/12bad9aae08f886ed4b0da75ef77fd13

  • This can alse be configured as a script.
    • Remember to add the script to a group so you can access it.
  • gw_mac is the Gateway’s mac address and is required along with the ringtone_id.
    • ringtone_vol is not required.

Screen Shot 2017-11-04 at 3.02.15 PM

Setting up & Using the (1st Gen) Xiaomi Button

I used Google Translate to provide a Shoddily Translated English Manual for the Xiaomi Button

Setting up the Button

The Smart-Home kit I purchased came with a 1st Gen Button. There is also a 2nd Gen Button available. I think the 1st Gen works well for general usage, though I am interested in getting a 2nd Gen Button to use as a Doorbell.

The first thing you’ll need to do is connect the Button to the Gateway, which is really easy.

  • Push the button on the Gateway 3 times.
    • Be careful, holding the Gateway button down for 5 seconds will reset the Gateway.
  • If the Notification volume is still on, the Gateway will prompt you to connect the sensor.

IMG_20171104_163829.jpg

  • Use a pin or sim card tool to push into the hole on the back of the Button.
  • It should now be connected.

Screen Shot 2017-11-04 at 4.12.46 PM

  • You can confirm the connection within the App or by restarting Home Assistant searching for it in the Developer Tool’s States page.

Screenshot_2017-10-26-15-12-06.png

  • Now that the button is set up, you can check that its connection still works wherever you put it by pushing the hole with a pin again. This will make the Gateway confirm if it’s still connected.

Using the Button

All of the Xiaomi sensors are categorized as binary sensors.

  • The docs state that this Button has 5 separate click types:
    • single
    • double
    • hold,
    • long_click_press
    • long_click_release
  • The 2nd Gen Button has 2 separate click types
    • single
    • double

Screen Shot 2017-11-02 at 8.13.35 PM

https://gist.github.com/smarthomehobby/1e6630cde915283e3b519e024077ef17

Screen Shot 2017-11-02 at 8.13.51 PM

https://gist.github.com/smarthomehobby/8c4a630df31fe690f628b7665fb3949a

Screen Shot 2017-11-02 at 8.14.17 PM

https://gist.github.com/smarthomehobby/a6fd54619dabed1ff779bf9e3954b2f8

  • You will use the click types as automation triggers, but can connect them to do anything you want.
    • You can also use the automation to set off a script.

The Xiaomi Gateway and Button are great devices for anyone who wants to add more versatility to their Smart-Home set up. They work well, look great, and are a fraction of the price of their competitors. I highly recommend them. If these guides have been helpful to you, please share them! If you have any questions, please reach out to me in the comments. Thanks for visiting!

If you’re interested in getting started with the Xiaomi Gateway, I recommend starting with one of the kits.

Different Gateway Kits Available

IMG_20171018_190537

  • I purchased my Gateway with the Smart Home Aqara Security Kit. This came with the Gateway, a Button, and 2 Door/Window Sensors (as pictured above), but there are other kits available.
    Gearbest 5 in 1 Xiaomi
  • The Xiaomi 5 in 1 Smart Home Security Kit includes the Gateway, a Button, a Door/Window Sensor, a Motion Sensor, and the Outlet (Zigbee Version).Gearbest 6 in 1 Xiaomi
  • Lastly, there’s the Xiaomi mijia 6 in 1 Smart Home Security Kit, which includes The Gateway, a Button, a Door/Window Sensor, a Motion Sensor, an Outlet (Zigbee Version), and a Temperature Humidity Sensor.

All of the parts can also be purchased individually:

  • Xiaomi Aqara Gateway.
  • Temperature and Humidity Sensor (1st and 2nd generation)
  • Motion Sensor (1st and 2nd generation)
    1. The 1st generation Motion Sensor is available with this Gateway kit
  • Door and Window Sensor (1st and 2nd generation)
  • Button (1st and 2nd generation)
  • Plug aka Socket (Zigbee version only, reports power consumed, power load, state and if device in use)
  • Wall Plug (reports power consumed, power load and state)
  • Aqara Wall Switch (Single)
  • Aqara Wall Switch (Double)
  • Aqara Wireless Switch (Single)
  • Aqara Wireless Switch (Double)
  • Cube – Magic Controller
  • Smoke Detector (reports alarm and density)
  • Gateway (Light, Illumination Sensor, Ringtone play)
  • Intelligent Curtain
  • Water Leak Sensor

14 thoughts on “Using the Xiaomi Gateway & Button

  • November 13, 2017 at 11:13 am
    Permalink

    hey, is it possible to use the switch as an on/off switch? so i use a single click to turn it on and another single click to turn it off? currently the switch turn my devices on and off again.

    Reply
    • November 13, 2017 at 11:35 am
      Permalink

      Hey Johnny, the switch.toggle service will turn a device that is on, off and the other way around. The example I provided would be the one that does this. When you push the button, the device is turning on then off? What does your automation look like?

      Reply
      • November 13, 2017 at 1:53 pm
        Permalink

        oh i used
        service: homeassistant.turn_on
        entity_id: scene.nightlight
        but i think its not possible to turn off the scene without a second automation

        – alias: ‘xiaomi wireless button turn off’
        trigger:
        platform: event
        event_type: click
        event_data:
        entity_id: binary_sensor.switch_158dxxxxxxxxxxxxx
        click_type: long_click_press
        action:
        service: homeassistant.turn_off
        entity_id: group.lights

        Reply
  • November 13, 2017 at 1:55 pm
    Permalink

    i want to do the turn off automation with a click_type: single too but in this case the scene goes on and then the second automation triggers and everything goes off

    Reply
  • November 20, 2017 at 1:45 pm
    Permalink

    Hey are you gonna make a post about the mqtt stuff like mqtt switches or mqtt fans?

    Reply
  • February 9, 2018 at 12:55 pm
    Permalink

    Do you know if the Xiaomi 2nd Gen button is supported by Home Assistant? I added a couple of these buttons, they seem to work OK in the Xiaomi app, but HA does not recognize them.

    Reply
      • February 11, 2018 at 12:51 pm
        Permalink

        First of all, thanks for your response. Yes, the square one is the 2nd Gen. I was expecting to see the state change (in states or my default view) when pressing these buttons. I have one of the 1st gen buttons which show the state changing. After setting up an automation for the 2nd gen buttons, I found that they do indeed work, just no visual confirmation (blush). Sorry to have bothered you, I should have checked more thoroughly before posting.

        Reply
  • March 16, 2021 at 9:22 pm
    Permalink

    Do you happen to know if the switch can work with echo devices? I got one but can’t for the life of me get it into the Amazon app.

    Reply
    • March 16, 2021 at 9:26 pm
      Permalink

      Hi Kieren,
      I’m sorry but I not longer have this device. You would probably need to download the MiHome Alexa skill (there are 3 different ones I think). So, you may need to try different combinations of the Alexa skill and the different Mi Home servers.

      Reply

Leave a Reply to Alex Jensen-SharpCancel reply