Xiaomi Buttons & Switches Around The House

I’ve already told you how much I loved Xiaomi’s 1st Generation Button, and I’m happy to say that the others are just as great! In this post I’ll quickly cover…

Connecting the Devices to the Xiaomi Gateway

If you want to use a 1st Generation Button, I’ve already done a complete write up on how to set it up. The other button and switch are not much different.

Connecting the 2nd Generation Button

IMG_0147

  • The 2nd Generation Button no longer requires a SIM card tool to connect to the Gateway. It has a button on the top of the device.

bty

  • First, you will need to put the Gateway in pairing mode. To do this, simply press the button on the Gateway 3 times. You will receive an audio prompt.
  • Push and hold down the button on the 2nd Generation Button.
  • When the light on the button blinks, you can let go. The device will now pair.

After the light stops blinking on the button, you can restart Home Assistant and find the device in the Developer Tool’s States page. It will look like this.

Gen 2 States

Connecting the Wireless Double Key Switch

IMG_0140

The process for connecting the Wireless Double Key Switch is identical to the others, but there is no need for a SIM card tool or an extra button. To pair this switch you will use the left key.

  • First, put the Gateway in pairing mode by pressing the button on the Gateway 3 times. You will receive an audio prompt.
  • Push and hold down the left key on the Double Key Switch.

IMG_0142

  • The lights on the bottom of the switch will light up, now you can let go. The device will now pair.

Restart Home Assistant and you will be able to find the switch in the Developer Tool’s States page. It will come up as 3 separate binary sensory, one for each click option.

Wall Switch States

Now that you’re all connected, lets put them to use.

Using the Buttons and Switches

All of these devices are considered binary sensors in Home Assistant. The best way I’ve found to utilize them is to create automations based on the input of the sensor.

Gen 1 Buttons

The Xiaomi Gen 1 Buttons turned out to be the best devices to control the bedroom from bed. I got two of them so my SO and I each have one on our side of the bed. We use them to control the lamp, the bedroom fan, and the window fan. You can see that I made one automation that can use either button as the trigger.

IMG_0143

  • A single click toggles the bedroom lamp.
    • If my sunrise script is on, it turns off the lamp and snoozes for 5 minutes
  • A double click toggles the window fan.
  • A long click toggles the bedroom fan.


################################################
## Gen 1 Button Automations
################################################
This goes in automations.yaml
– id: bedside_button_single
alias: Bedside Button Single Click
initial_state: 'on'
trigger:
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00019cd6e4
click_type: single
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001e61312
click_type: single
action:
service: homeassistant.turn_on
entity_id: script.bedroom_lamp_toggle
– id: bedside_button_double
alias: Bedside Button Double Click
initial_state: 'on'
trigger:
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00019cd6e4
click_type: double
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001e61312
click_type: double
action:
service: switch.toggle
entity_id:
– switch.window_fan
– id: bedside_button_long
alias: Bedside Button Long Click
initial_state: 'on'
trigger:
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00019cd6e4
click_type: long_click_press
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001e61312
click_type: long_click_press
action:
service: homeassistant.toggle
entity_id:
– switch.bedroom_fan
This goes in scripts.yaml
bedroom_lamp_toggle:
alias: Bedroom Lamp Toggle
sequence:
– service: homeassistant.turn_on
data_template:
entity_id: >
{% if is_state("light.bedroom_lamp", "off") %}
script.bedroom_lamp_toggle_on
{%-elif is_state("light.bedroom_lamp", "on") %}
script.bedroom_lamp_toggle_off
{% else %}
script.none
{% endif %}
bedroom_lamp_toggle_on:
alias: Bedroom Lamp Toggle On
sequence:
– service: homeassistant.turn_on
entity_id: light.bedroom_lamp
data:
brightness_pct: 80
– service: homeassistant.turn_off
entity_id: script.bedroom_lamp_sunrise_snooze
bedroom_lamp_sunrise_snooze:
alias: Sunrise Snooze
sequence:
– service: homeassistant.turn_off
entity_id: script.sunrise
– service: homeassistant.turn_off
entity_id: light.bedroom_lamp
– delay: 00:05:00
– service: homeassistant.turn_on
entity_id: script.sunrise
bedroom_lamp_toggle_off:
alias: Bedroom Lamp Toggle Off
sequence:
– service: homeassistant.turn_off
entity_id: light.bedroom_lamp

view raw

Gen 1 Buttons

hosted with ❤ by GitHub

Gen 2 Button

The 2nd Generation Button has been turned into a smart(ish) doorbell. I live in an apartment that has a broken doorbell. When we moved in, we got a cheap RF doorbell and chime, but I thought this would be a worthwhile upgrade. I utilized an external speaker, the Audio Player add-on, and a doorbell mp3 file. The Gen 2 Button has 2 triggers; a single press and a double press. For this usage, I made both triggers call the same action.

IMG_0148

  • To put this together, first you will need to put your chosen mp3 file in the “www” file inside your config file.
  • Install the Audio Player add-on.
  • To make the doorbell smart(ish), I use it as a trigger to send me a text with IFTTT.


################################################
## Gen 2 Button Automations & Scripts
################################################
– id: doorbell
alias: Doorbell
initial_state: 'on'
trigger:
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0002134dde
click_type: single
– platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0002134dde
click_type: double
action:
service: homeassistant.turn_on
entity_id:
– script.doorbell
Add to scripts.yaml
doorbell:
sequence:
– service: hassio.addon_stdin
data:
addon: de3cd379_audio_player
input: "https://YOUR_RASPBERRY_PI'S_IP:8123/local/doorbell.mp3"
– service: ifttt.trigger
data: {"event":"text_notification", "value1":"Someone rang the doorbell."}

view raw

Gen 2 Button

hosted with ❤ by GitHub

Wireless Double Key Switch

The Xiaomi Wireless Double Key Switch is probably my favorite Xiaomi device so far. It is solidly built and looks like a built in light switch, which is exactly how I use it. I use the left key to toggle the lamp in my living room (there is no light switch), the right key to toggle the light in the entryway, and both keys together toggles the fish tank’s light. I also use them to call my bedtime routine. If you’ve been here before, you’ll notice this is the same bedtime script that has evolved over time, as my house has gotten smarter. This makes it easy if I or my SO stay up late as we can get the bedroom ready without interfering with any of the living room devices.

This is how it works:

  • The input number stays at 0 until 15 minutes before I go to bed to read. At that point it is raised to 3.
  • If the input number is 3 or 2, the right key gets the bedroom ready for bed and lowers the input number by 2. After that it will continue to toggle the entry lamp.
  • If the input number is 3 or 1, the left key gets the living room ready for night and lowers the input number by 1. After that it will continue to toggle the entry lamp.


################################################################################
## Double Key Wireless Switch Automations, Scripts, and Bedtime Script Setup
################################################################################
#Put this in configuration.yaml
input_number:
bedtime_trigger:
name: Bedtime Trigger
min: 0
max: 3
step: 1
#Put this in automations.yaml
– id: living_room_wall_switch_left
alias: Living Room Wall Switch Left
initial_state: 'on'
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.wall_switch_left_158d00016405ac
click_type: single
action:
– service: homeassistant.turn_on
data_template:
entity_id: >
{% if is_state("input_number.bedtime_trigger", "3.0") %}
script.bedtime_living_room
{%-elif is_state("input_number.bedtime_trigger", "1.0") %}
script.bedtime_living_room
{% else %}
script.living_room_lamp_toggle
{% endif %}
– id: living_room_wall_switch_right
alias: Living Room Wall Switch Right
initial_state: 'on'
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.wall_switch_right_158d00016405ac
click_type: single
action:
– service: homeassistant.turn_on
data_template:
entity_id: >
{% if is_state("input_number.bedtime_trigger", "3.0") %}
script.bedtime_bedroom
{%-elif is_state("input_number.bedtime_trigger", "2.0") %}
script.bedtime_bedroom
{% else %}
script.entry_toggle
{% endif %}
– id: living_room_wall_switch_both
alias: Living Room Wall Switch Both
initial_state: 'on'
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.wall_switch_both_158d00016405ac
click_type: both
action:
– service: switch.toggle
entity_id: switch.fish_tank_light
#Put this in scripts.yaml
bedtime_bedroom:
alias: "Bedtime Bedroom"
sequence:
– service: input_number.decrement
entity_id: input_number.bedtime_trigger
– service: input_number.decrement
entity_id: input_number.bedtime_trigger
– service: homeassistant.turn_on
entity_id: light.bedroom_lamp
data:
brightness: 5
– service: homeassistant.turn_on
entity_id:
– switch.bedroom_fan
– group.evening_night_light
– service: homeassistant.turn_off
entity_id:
– switch.entry
– service: homeassistant.turn_on
entity_id: light.gateway_light_34ce008d4aae
data:
rgb_color: [255, 103, 23]
bedtime_living_room:
alias: "Bedtime Living Room"
sequence:
– service: input_number.decrement
entity_id: input_number.bedtime_trigger
– service: homeassistant.turn_off
entity_id:
– switch.tv
– switch.air_conditioner
– switch.entry
– service: homeassistant.turn_on
entity_id: script.fans_off
– wait_template: "{{is_state('binary_sensor.door_window_sensor_158d0001e59f8e', 'on')}}"
– wait_template: "{{is_state('binary_sensor.door_window_sensor_158d0001e59f8e', 'off')}}"
– service: homeassistant.turn_off
entity_id:
– light.lamp
– switch.fish_tank_light
– switch.christmas_tree
– service: homeassistant.turn_on
entity_id:
– automation.nighttime_living_room

The Xiaomi buttons and switches are such a great way to control Home Assistant and they’re so affordable. They’re great quality also, every single one of them. If you’re looking for some devices to add on to your system, I definitely recommend looking into the Xiaomi line of smart home devices. It also seems like it’s a good time to pick up some devices at Gearbest, it looks like they’re having a sale this month! Do you have any of these devices? I’d be interested in how you use them! Share with us in the comments. 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!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s