|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: "Xiaomi Binary sensors” |
| 4 | +description: "Instructions how to integrate your Xiaomi Binary sensors within Home Assistant." |
| 5 | +date: 2017-07-21 16:34 |
| 6 | +sidebar: true |
| 7 | +comments: false |
| 8 | +sharing: true |
| 9 | +footer: true |
| 10 | +logo: xiaomi.png |
| 11 | +ha_category: Binary sensor |
| 12 | +ha_release: "0.50" |
| 13 | +--- |
| 14 | + |
| 15 | +To get your Xiaomi binary sensors working with Home Assistant, follow the instructions for the general [Xiaomi Gateway component](/components/xiaomi/) |
| 16 | + |
| 17 | +### Type of sensors supported: |
| 18 | +- Motion |
| 19 | +- Door / Window |
| 20 | +- Smoke |
| 21 | +- Gas |
| 22 | +- Xiaomi Wireless Button |
| 23 | +- Xiaomi Cube |
| 24 | + |
| 25 | +### Some automation examples to get you started: |
| 26 | +- Motion |
| 27 | +```yaml |
| 28 | + # Trigger for motion sensor |
| 29 | + |
| 30 | + - alias: If there is motion and its dark turn on the gateway light |
| 31 | + trigger: |
| 32 | + platform: state |
| 33 | + entity_id: binary_sensor.motion_sensor_158d000xxxxxc2 |
| 34 | + from: 'off' |
| 35 | + to: 'on' |
| 36 | + condition: |
| 37 | + condition: numeric_state |
| 38 | + entity_id: sensor.illumination_34ce00xxxx11 |
| 39 | + below: 300 |
| 40 | + action: |
| 41 | + service: light.turn_on |
| 42 | + entity_id: light.gateway_light_34ce00xxxx11 |
| 43 | + data: |
| 44 | + brightness: 5 |
| 45 | + |
| 46 | + - alias: If there no motion for 5 minutes turn off the gateway light |
| 47 | + trigger: |
| 48 | + platform: state |
| 49 | + entity_id: binary_sensor.motion_sensor_158d000xxxxxc2 |
| 50 | + from: 'on' |
| 51 | + to: 'off' |
| 52 | + for: |
| 53 | + minutes: 5 |
| 54 | + action: |
| 55 | + service: light.turn_off |
| 56 | + entity_id: light.gateway_light_34ce00xxxx11 |
| 57 | +``` |
| 58 | + |
| 59 | +- Door / Window |
| 60 | + ```yaml |
| 61 | + # Trigger for door window sensor |
| 62 | + |
| 63 | + - alias: If the window is open turn off the radiator |
| 64 | + trigger: |
| 65 | + platform: state |
| 66 | + entity_id: binary_sensor.door_window_sensor_158d000xxxxxc2 |
| 67 | + from: 'off' |
| 68 | + to: 'on' |
| 69 | + action: |
| 70 | + service: climate.set_operation_mode |
| 71 | + entity_id: climate.livingroom |
| 72 | + data: |
| 73 | + operation_mode: 'Off' |
| 74 | + |
| 75 | + - alias: If the window is closed for 5 minutes turn on the radiator again |
| 76 | + trigger: |
| 77 | + platform: state |
| 78 | + entity_id: binary_sensor.door_window_sensor_158d000xxxxxc2 |
| 79 | + from: 'on' |
| 80 | + to: 'off' |
| 81 | + for: |
| 82 | + minutes: 5 |
| 83 | + action: |
| 84 | + service: climate.set_operation_mode |
| 85 | + entity_id: climate.livingroom |
| 86 | + data: |
| 87 | + operation_mode: 'Smart schedule' |
| 88 | + ``` |
| 89 | +- Smoke |
| 90 | + ```yaml |
| 91 | + # Trigger for smoke sensor |
| 92 | + |
| 93 | + - alias: Send notification on fire alarm |
| 94 | + trigger: |
| 95 | + platform: state |
| 96 | + entity_id: binary_sensor.smoke_sensor_158d0001574899 |
| 97 | + from: 'off' |
| 98 | + to: 'on' |
| 99 | + action: |
| 100 | + - service: notify.html5 |
| 101 | + data: |
| 102 | + title: Fire alarm! |
| 103 | + message: Fire/Smoke detected! |
| 104 | + - service: xiaomi.play_ringtone |
| 105 | + data: |
| 106 | + gw_mac: xxxxxxxxxxxx |
| 107 | + ringtone_id: 2 |
| 108 | + ringtone_vol: 100 |
| 109 | + ``` |
| 110 | +- Gas |
| 111 | +```yaml |
| 112 | + # Trigger for natgas detected |
| 113 | + |
| 114 | + - alias: Send notification on gas alarm |
| 115 | + trigger: |
| 116 | + platform: state |
| 117 | + entity_id: binary_sensor.natgas_sensor_158dxxxxxxxxxx |
| 118 | + from: 'off' |
| 119 | + to: 'on' |
| 120 | + action: |
| 121 | + - service: notify.html5 |
| 122 | + data_template: |
| 123 | + title: Gas alarm! |
| 124 | + message: 'Gas with a density of {{ states.binary_sensor.natgas_sensor_158dxxxxxxxxxx.attributes.density }} detected.' |
| 125 | +``` |
| 126 | +- Xiaomi Wireless Button (available events are `single`, `double`, `hold`, `long_click_press` and `long_click_release`). For Square version (Aqara brand) only `single` and `double` events are supported. Furthermore the space between two clicks to generate a double click must be quite large now |
| 127 | +```yaml |
| 128 | + # Trigger for the wireless button with different click types |
| 129 | +
|
| 130 | + - alias: Toggle dining light on single press |
| 131 | + trigger: |
| 132 | + platform: event |
| 133 | + event_type: click |
| 134 | + event_data: |
| 135 | + entity_id: binary_sensor.switch_158d000xxxxxc2 |
| 136 | + click_type: single |
| 137 | + action: |
| 138 | + service: switch.toggle |
| 139 | + entity_id: switch.wall_switch_left_158d000xxxxx01 |
| 140 | +
|
| 141 | + - alias: Toggle couch light on double click |
| 142 | + trigger: |
| 143 | + platform: event |
| 144 | + event_type: click |
| 145 | + event_data: |
| 146 | + entity_id: binary_sensor.switch_158d000xxxxxc2 |
| 147 | + click_type: double |
| 148 | + action: |
| 149 | + service: switch.toggle |
| 150 | + entity_id: switch.wall_switch_right_158d000xxxxx01 |
| 151 | +
|
| 152 | + - alias: Let a dog bark on long press |
| 153 | + trigger: |
| 154 | + platform: event |
| 155 | + event_type: click |
| 156 | + event_data: |
| 157 | + entity_id: binary_sensor.switch_158d000xxxxxc2 |
| 158 | + click_type: long_click_press |
| 159 | + action: |
| 160 | + service: xiaomi.play_ringtone |
| 161 | + data: |
| 162 | + gw_mac: xxxxxxxxxxxx |
| 163 | + ringtone_id: 8 |
| 164 | + ringtone_vol: 8 |
| 165 | + ``` |
| 166 | + |
| 167 | +- Xiaomi Cube (available events are `flip90`, `flip180`, `move`, `tap_twice`, `shake_air`, `swing`, `alert`, `free_fall` and `rotate`). |
| 168 | +```yaml |
| 169 | + # Trigger for a few cube events |
| 170 | +
|
| 171 | + - alias: Cube event flip90 |
| 172 | + trigger: |
| 173 | + platform: event |
| 174 | + event_type: cube_action |
| 175 | + event_data: |
| 176 | + entity_id: binary_sensor.cube_15xxxxxxxxxxxx |
| 177 | + action_type: flip90 |
| 178 | + action: |
| 179 | + - service: light.turn_on |
| 180 | + entity_id: light.gateway_light_28xxxxxxxxxx |
| 181 | + data: |
| 182 | + color_name: "springgreen" |
| 183 | + |
| 184 | + - alias: Cube event flip180 |
| 185 | + trigger: |
| 186 | + platform: event |
| 187 | + event_type: cube_action |
| 188 | + event_data: |
| 189 | + entity_id: binary_sensor.cube_15xxxxxxxxxxxx |
| 190 | + action_type: flip180 |
| 191 | + action: |
| 192 | + - service: light.turn_on |
| 193 | + entity_id: light.gateway_light_28xxxxxxxxxx |
| 194 | + data: |
| 195 | + color_name: "darkviolet" |
| 196 | + |
| 197 | + - alias: Cube event move |
| 198 | + trigger: |
| 199 | + platform: event |
| 200 | + event_type: cube_action |
| 201 | + event_data: |
| 202 | + entity_id: binary_sensor.cube_15xxxxxxxxxxxx |
| 203 | + action_type: move |
| 204 | + action: |
| 205 | + - service: light.turn_on |
| 206 | + entity_id: light.gateway_light_28xxxxxxxxxx |
| 207 | + data: |
| 208 | + color_name: "gold" |
| 209 | + |
| 210 | + - alias: Cube event tap_twice |
| 211 | + trigger: |
| 212 | + platform: event |
| 213 | + event_type: cube_action |
| 214 | + event_data: |
| 215 | + entity_id: binary_sensor.cube_15xxxxxxxxxxxx |
| 216 | + action_type: tap_twice |
| 217 | + action: |
| 218 | + - service: light.turn_on |
| 219 | + entity_id: light.gateway_light_28xxxxxxxxxx |
| 220 | + data: |
| 221 | + color_name: "deepskyblue" |
| 222 | + |
| 223 | + - alias: Cube event shake_air |
| 224 | + trigger: |
| 225 | + platform: event |
| 226 | + event_type: cube_action |
| 227 | + event_data: |
| 228 | + entity_id: binary_sensor.cube_15xxxxxxxxxxxx |
| 229 | + action_type: shake_air |
| 230 | + action: |
| 231 | + - service: light.turn_on |
| 232 | + entity_id: light.gateway_light_28xxxxxxxxxx |
| 233 | + data: |
| 234 | + color_name: "blue" |
| 235 | + ``` |
0 commit comments