Using the Xiaomi Door/Window Sensor

After I got my Xiaomi kit, I integrated the Gateway and Button pretty quickly into my Smart-Home set up. The Door/Window sensors, on the other hand, took a little more time to figure out. However, it ended up being worth it in the end. These sensors changed the game by making automations that respond to actions; as opposed to buttons, time, or your voice. This, I feel, is my first entry into true Home Automation, instead of just having smart devices.

There are two Door/Window sensors that are compatible with the Xiaomi Gateway; a first generation and second generation version. With my Door/Window sensors, I wanted to try a couple of things. First, I wanted to be able to monitor the front door. With this, I figured I could set up a very, very, very basic alarm system. Secondly, I wanted to monitor the bedroom door. I was already using the Gateway as a night light in the bathroom at night. With the Door/Window sensor, I could automate that as well as my morning lights routine.

This guide will show you:

  • How to connect the Door/Window Sensors to the Xiaomi Gateway.
  • How to add the Sensors to your Home Assistant front end.
  • How to use the Door/Window Sensors in automations.
  • Make a simple Door alarm.
  • How to add your own “ringtones” to the Xiaomi Gateway

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 Door/Window Sensors

I used Google Translate to provide a Shoddily Translated English Manual for the Xiaomi Door/Window Sensor

Setting up the Door/Window Sensors

  • Setting up the Door/Window Sensor is identical to setting up the Button:
    • Push the button on the Gateway 3 times.
      • Be careful, holding the 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.
    • Use a pin or sim card tool to push into the hole in the bottom of the Sensor.
    • It should now be connected.

    Screen Shot 2017-11-04 at 4.56.30 PM

    • You can check 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 Door/Window sensor is connected, you can confirm its connection still works wherever you put it by pushing the hole with a pin again. This will cause the Gateway to confirm if it’s still connected.
  • Note: Once connected to the Gateway, the violet light on the sensor will stop flashing when it switches on or off.

Adding the Sensors to your Front End.

  • To add the sensors to your front end, you can use a Template Sensor in your configuration.yaml. Mine is in my sensors.yaml file.
  • Below are how I added both sensors to my front end.

Screen Shot 2017-11-19 at 4.59.59 PM

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

  • For the binary Door/Window sensors, “off” is when the sensor is closed, and “on” is open. I wanted my front end to say “Open” and “Closed” as well as change the icon to match the state of the door.

Screen Shot 2017-11-19 at 5.00.12 PM

  • This is how it will look when added to your front end.
  • Now let’s put the sensors to work.

Automated Night Light & Home Wake-Up Script

  • My first move in automation, was to use the Gateway as a Night Light in the bathroom.
  • First, you’ll want to open your automation.yaml file.

Screen Shot 2017-11-05 at 11.44.59 AM

https://gist.github.com/smarthomehobby/0a6b91fcd62c63c5eda221a5e023db87

  • This first part, makes the light turn on when the bedroom door opens.

Screen Shot 2017-11-05 at 11.45.09 AM

https://gist.github.com/smarthomehobby/61692965b55ed9b0b09cc4443ee3670b

https://gist.github.com/smarthomehobby/61692965b55ed9b0b09cc4443ee3670b#file-automation_night_light_toggle_off

  • Then, it shuts off when the door is closed.

Screen Shot 2017-11-19 at 4.33.01 PM

https://gist.github.com/smarthomehobby/6093a6cdc4acc86ee839007275f999ca

  • You can add both automations to a group, so that only the group needs to be called when activating these automations.

Screen Shot 2017-11-19 at 4.40.03 PM

Screen Shot 2017-11-19 at 4.40.42 PM

  • When added to a group, the automations can all be accessed by clicking the automation group.

Screen Shot 2017-11-22 at 4.45.05 PM

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

  • Now, I can activate the Night Light automation by turning on group.evening_night_light within the bedtime script from a previous post.
  • The automation will stay on throughout the night.
  • Notice I also tied the bedroom door sensor to the end of my bedtime script.
    • These sensors can have multiple uses.
    • Now, my lamp will stay on in the living room, until I close the bedroom door to go to bed.

Screen Shot 2017-11-19 at 4.35.49 PM

https://gist.github.com/smarthomehobby/37d823e97712d20748d0e05ff07b96da

  • With the addition of this new sensor, I also changed my whole Morning Wake Up automation.
  • This new routine doesn’t use the time to turn lights on. Instead, it will turn on my lights when I open the bedroom door, after my usual 5:15 wake up time.
    • It also turns off the Night Light automation group as well as turning itself off.
  • This creates a nice smooth string of actions that all go into effect after I tell Alexa that I’m going to bed. It goes like this:
    • Tell Alexa it’s time for bed (this can be done with a custom Alexa skill or by using the Alexa Routines)
    • The bedroom turns on
    • The living room turns off (except the main lamp, which turns off when the bedroom door closes)
    • Night Light & Morning Wake up automations turn on
    • When I go to bed and shut the door, the rest of the living room shuts off
    • Throughout the night, if the bedroom door is open, the night light turns on
    • After 5:15, when the bedroom door is opened, the living room turns on, and the Night Light and Morning routine automations are all
    • turned off.

Make A Simple Alarm

  • Creating a simple alarm using the Xiaomi Gateway and Door/Window Sensors is really easy
  • First, open your automations.yaml file to begin a new automation.

Screen Shot 2017-11-19 at 5.06.07 PM

https://gist.github.com/smarthomehobby/06405441577c31f3d51e2a12d5c1d06c

  • This automation uses the sensor on my front door. When opened, the Gateway will play whichever sound I choose. That’s it!

Screen Shot 2017-11-19 at 5.06.59 PM

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

  • I also added a script to my front end for turning off and silencing the alarm.

Screen Shot 2017-11-19 at 5.14.01 PM

  • I used the MDI Icons “alarm-light” and “volume-off” when customizing the entities.
  • You can now tie in your alarm to any of your other automations. I am considering tying it to the rest of my Bedtime/Wake up routine to go off if someone opens the door while we’re sleeping.

Screen Shot 2017-11-19 at 5.00.41 PM

BONUS: You can add your own “ringtones” to the Xiaomi Gateway!

I wanted to have a better alarm sound than the one I used creating the automation above. You can add your own sounds to the Gateway through the MiHome app. I used an alarm that I found amongst these different alarm sounds.

  • Navigate to the Gateway in the MiHome app
  • Choose “Device” from the top of the screen
  • Select the Gateway
  • Select Ringtone Settings
  • Choose one of the Ringtone Types
  • Touch the “+ Add Ringtone” at the bottom of the page
  • Choose your desired file and touch “Yes”
  • Your file will now be available at the top of the page as a “Custom Ringtone.”

The Xiaomi Gateway and Door/Window sensors are a great addition to any Smart-Home set up. The sensors dramatically increase the possibilities of home automation and are very affordable. They took me a little more time to add to the system, but that is just because they are capable of doing so much. 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

9 thoughts on “Using the Xiaomi Door/Window Sensor

  • December 17, 2017 at 11:50 am
    Permalink

    Thanks for this! I’ve been following along and all of your posts have been very helpful. Do you have any plans to do a how-to write up on using Amazon dash buttons with hassio?

    Reply
    • December 17, 2017 at 12:59 pm
      Permalink

      Thank you! I have not been able to successfully get Amazon dash buttons to work with Home Assistant. I’ve tried 3 separate times with 2 versions of buttons. It was not reliable enough to use for anything. Actually, not being able to use the dash buttons is what lead me to the Xiaomi stuff because of the Xiaomi buttons.

      Reply
  • December 20, 2017 at 4:51 pm
    Permalink

    Hi,
    very nice blog with a lot of helpful tips and tricks, love it.
    Do you publish your config file somewhere??
    Cause it would be hard to type everything that you show in your pictures…

    Thanks

    Reply
  • February 26, 2018 at 7:30 pm
    Permalink

    hey dude love the articles, just an observation would be great if your code was actual text, easier to cut and paste into my files compared to images.

    thanks

    Reply
    • May 16, 2018 at 8:22 pm
      Permalink

      Thank you for this feedback. I figured out how to share the YAML as text and keep the formatting. So you will be able to cut and paste from future posts.

      Reply
  • May 21, 2018 at 10:10 pm
    Permalink

    Well done, the explanations are very effective – just please, can you pass the codes that we can copy instead of writing from the pictures?

    Reply
    • May 22, 2018 at 11:46 am
      Permalink

      Thanks for your feedback! I actually just figured out how to paste the codes and keep the formatting in my articles. Future posts will utilize this so you can cut and paste from them.

      Reply

Leave a Reply