--- id: mihome label: Xiaomi Mi Smart Home title: Xiaomi Mi Smart Home - Bindings type: binding description: "This binding allows your openHAB to communicate with the Xiaomi Smart Home Suite." since: 2x install: auto --- {% include base.html %} # Xiaomi Mi Smart Home Binding This binding allows your openHAB to communicate with the Xiaomi Smart Home Suite. In order to connect the Gateway, you need to install the MiHome app from the [Google Play](https://play.google.com/store/apps/details?id=com.xiaomi.smarthome) or [AppStore](https://itunes.apple.com/app/mi-home-xiaomi-for-your-smarthome/id957323480). ## Supported devices * Xiaomi Smart Gateway v2 (with radio support) * Xiaomi Smart Temperature and Humidity Sensor (round one) * Xiaomi Smart Door/Window Sensor (round one) * Xiaomi Wireless Switch (round one) * Xiaomi Motion Sensor / IR Human Body sensor * Xiaomi Smart Plug * Xiaomi Smart Magic Cube * Xiaomi Aqara ZigBee Wired Wall Switch (1 and 2 buttons) * Xiaomi Aqara ZigBee Wireless Wall Switch (1 and 2 buttons) * Xiaomi Aqara Smart Curtain (not yet confirmed) * Xiaomi Aqara Neutral Wall Switch (1 and 2 buttons) * Xiaomi Mijia Honeywell Gas Alarm Detector * Xiaomi Mijia Honeywell Fire Alarm Detector ## Setup * Install the binding * Setup Gateway to be discoverable 1. Add Gateway 2 or 3 to your WiFi Network 1. Install MiHome app from [Google Play](https://play.google.com/store/apps/details?id=com.xiaomi.smarthome) or [AppStore](https://itunes.apple.com/app/mi-home-xiaomi-for-your-smarthome/id957323480) (your phone may need to be changed to English language first) 1. Set your region to Mainland China under Settings -> Locale (seems to be required) 1. Update gateway to the latest firmware (note that update window may pop up sequentially) 1. Enable developer mode: 1. Select your Gateway in the MiHome app 1. Go to the "..." menu on the top right corner and click "About" 1. Tap the version number "Version : 2.XX" at the bottom of the screen repeatedly until you enable developer mode 1. You should now have 2 extra options listed: `local area network communication protocol` and `gateway information` 1. Choose `local area network communication protocol` 1. Tap the toggle switch to enable LAN functions. Note down the developer key (something like: 91bg8zfkf9vd6uw7) 1. Make sure you hit the OK button (to the right of the cancel button) to save your changes * In openHAB you should now be able to discover the Xiaomi Gateway * From now on you don't really need the app anymore - only if you're keen on updates or you want to add devices (see below), which also can be done without the app * Enter the previously noted developer key in openHAB Paper UI -> Configuration -> Things -> Xiaomi Gateway -> Edit -> Developer Key. Save (This is required if you want to be able to send controls to the devices like the light of the gateway) * Your sensors should be getting discovered by openHAB as you add and use them ## Connecting sub-devices (sensors) to the Gateway There are two ways of connecting Xiaomi devices to the gateway: * Online - within the MiHome App * Offline - manual 1. Click 3 times on the Gateway's button 1. Gateway will flash in blue and you will hear female voice in Chinese 1. Place the needle into the sensor and hold it for at least 3 seconds 1. You'll hear confirmation message in Chinese 1. The device appears in openHAB thing Inbox * If you don't want to hear the Chinese voice every time, you can disable it by setting the volume to minimum in the MiHome App (same for the blinking light) * The devices don't need an Internet connection to be working after you have set up the developer mode BUT you won't be able to connect to them via App anymore - easiest way is to block their outgoing Internet connection in your router and enable it later, when you want to check for updates etc. ## Important information The binding requires port `9898` to not be used by any other service on the system. ## Full Example ### xiaomi.things: ``` Bridge mihome:bridge:f0b429XXXXXX "Xiaomi Gateway" [ serialNumber="f0b429XXXXXX", ipAddress="192.168.0.3", port=9898, key="XXXXXXXXXXXXXXXX", pollingInterval=6000 ] { Thing mihome:gateway:f0b429XXXXXX "Xiaomi Mi Smart Home Gateway" [itemId="f0b429XXXXXX"] Thing mihome:sensor_ht:158d0001XXXXXX "Xiaomi Temperature Sensor" [itemId="158d0001XXXXXX"] Thing mihome:sensor_motion:158d0001XXXXXX "Xiaomi Motion Sensor" [itemId="158d0001XXXXXX"] Thing mihome:sensor_plug:158d0001XXXXXX "Xiaomi Plug" [itemId="158d0001XXXXXX"] Thing mihome:sensor_magnet:158d0001XXXXXX "Xiaomi Door Sensor" [itemId="158d0001XXXXXX"] Thing mihome:sensor_switch:158d0001XXXXXX "Xiaomi Mi Wireless Switch" [itemId="158d0001XXXXXX"] Thing mihome:86sw2:158d0001XXXXXX "Aqara Wireless Wall Switch" [itemId="158d0001XXXXXX"] } ``` ### xiaomi.items: ``` // Xiaomi Gateway Switch Gateway_LightSwitch { channel="mihome:gateway::brightness" } Dimmer Gateway_Brightness { channel="mihome:gateway::brightness" } Color Gateway_Color { channel="mihome:gateway::color" } Dimmer Gateway_ColorTemperature { channel="mihome:gateway::colorTemperature" } Number Gateway_AmbientLight { channel="mihome:gateway::illumination" } Number Gateway_Sound { channel="mihome:gateway::sound" } Switch Gateway_SoundSwitch { channel="mihome:gateway::enableSound" } Dimmer Gateway_SoundVolume { channel="mihome:gateway::volume" } // Xiaomi Temperature and Humidity Sensor Number HT_Temperature { channel="mihome:sensor_ht::temperature" } Number HT_Humidity { channel="mihome:sensor_ht::humidity" } Number HT_Battery { channel="mihome:sensor_ht::batteryLevel" } Switch HT_BatteryLow { channel="mihome:sensor_ht::lowBattery" } // Xiaomi Motion Sensor Switch MotionSensor_MotionStatus { channel="mihome:sensor_motion::motion" } // minimum 5 seconds - remember that the sensor only triggers every minute to save energy Number MotionSensor_MotionTimer { channel="mihome:sensor_motion::motionOffTimer" } DateTime MotionSensor_LastMotion "[%1$tY-%1$tm-%1$td %1$tH:%1$tM]" { channel="mihome:sensor_motion::lastMotion" } Number MotionSensor_Battery { channel="mihome:sensor_motion::batteryLevel" } Switch MotionSensor_BatteryLow { channel="mihome:sensor_motion::lowBattery" } // Xiaomi Plug Switch Plug_Switch { channel="mihome:sensor_plug::power" } Switch Plug_Active { channel="mihome:sensor_plug::inUse" } Number Plug_Power { channel="mihome:sensor_plug::loadPower" } Number Plug_Consumption { channel="mihome:sensor_plug::powerConsumed" } // Xiaomi Window Switch Contact WindowSwitch_Status { channel="mihome:sensor_magnet::isOpen" } // minimum 30 seconds Number WindowSwitch_AlarmTimer { channel="mihome:sensor_magnet::isOpenAlarmTimer" } DateTime WindowSwitch_LastOpened "[%1$tY-%1$tm-%1$td %1$tH:%1$tM]" { channel="mihome:sensor_magnet::lastOpened" } Number WindowSwitch_Battery { channel="mihome:sensor_magnet::batteryLevel" } Switch WindowSwitch_BatteryLow { channel="mihome:sensor_magnet::lowBattery" } // Xiaomi Cube - see "xiaomi.rules" for action triggers Number Cube_RotationAngle { channel="mihome:sensor_cube::rotationAngle" } Number Cube_RotationTime { channel="mihome:sensor_cube::rotationTime" } Number Cube_Battery { channel="mihome:sensor_cube::batteryLevel" } Switch Cube_BatteryLow { channel="mihome:sensor_cube::lowBattery" } // Xiaomi Switch - see "xiaomi.rules" for action triggers Number Switch_Battery { channel="mihome:sensor_switch::batteryLevel" } Switch Switch_BatteryLow { channel="mihome:sensor_switch::lowBattery" } // Xiaomi Aqara Battery Powered Switch 1- see "xiaomi.rules" for action triggers Number AqaraSwitch1_Battery { channel="mihome:86sw1::batteryLevel" } Switch AqaraSwitch1_BatteryLow { channel="mihome:86sw1::lowBattery" } // Xiaomi Aqara Battery Powered Switch 2- see "xiaomi.rules" for action triggers Number AqaraSwitch2_Battery { channel="mihome:86sw2::batteryLevel" } Switch AqaraSwitch2_BatteryLow { channel="mihome:86sw2::lowBattery" } // Xiaomi Aqara Mains Powered Wall Switch 1 Switch AqaraWallSwitch { channel="mihome:ctrl_neutral1::ch1" } // Xiaomi Aqara Mains Powered Wall Switch 2 Switch AqaraWallSwitch1 { channel="mihome:ctrl_neutral2::ch1" } Switch AqaraWallSwitch2 { channel="mihome:ctrl_neutral2::ch2" } // Xiaomi Aqara Intelligent Curtain Motor Rollershutter CurtainMotorControl { channel="curtain::curtainControl" } ``` ### xiaomi.rules: ``` rule "Xiaomi Switch" when Channel "mihome:sensor_switch::button" triggered then var actionName = receivedEvent.getEvent() switch(actionName) { case "SHORT_PRESSED": { } case "DOUBLE_PRESSED": { } case "LONG_PRESSED": { } case "LONG_RELEASED": { } } end rule "Xiaomi Cube" when Channel 'mihome:sensor_cube::action' triggered then var actionName = receivedEvent.getEvent() switch(actionName) { case "MOVE": { } case "ROTATE_RIGHT": { } case "ROTATE_LEFT": { } case "FLIP90": { } case "FLIP180": { } case "TAP_TWICE": { } case "SHAKE_AIR": { } case "FREE_FALL": { } case "ALERT": { } } end rule "Xiaomi Motion Sensor" when Item MotionSensor_MotionStatus changed then if (MotionSensor_MotionStatus.state == ON) { } else { } end rule "Xiaomi Window Switch" when Item WindowSwitch_Status changed then if (WindowSwitch_Status.state == OPEN) { } else { } end rule "Xiaomi Window Switch - Window is open alarm" when Channel "mihome:sensor_magnet::isOpenAlarm" triggered ALARM then end rule "Xiaomi Aqara Battery Powered 1 Button Switch" when Channel "mihome:86sw1::ch1" triggered SHORT_PRESSED then end rule "Xiaomi Aqara Battery Powered 2 Button Switch" when Channel "mihome:86sw2::ch1" triggered SHORT_PRESSED then end rule "Xiaomi Aqara Battery Powered 2 Button Switch" when Channel "mihome:86sw2::ch2" triggered SHORT_PRESSED then end rule "Xiaomi Aqara Battery Powered 2 Button Switch" when Channel "mihome:86sw2::dual_ch" triggered SHORT_PRESSED then end // This rule is applicable for every battery powered sensor device rule "Xiaomi Motion Sensor Low Battery" when Channel "mihome:sensor_motion::lowBattery" changed to ON then end rule "Play quiet knock-knock ringtone with the Xiaomi Gateway" when // Item ExampleSwitch changed to ON then sendCommand(Gateway_SoundVolume, 2) sendCommand(Gateway_Sound, 11) Thread::sleep(2000) /* wait for 2 seconds */ sendCommand(Gateway_Sound, 10000) sendCommand(Gateway_SoundVolume, 0) end ``` ### xiaomi.sitemap: ``` sitemap xiaomi label="Xiaomi" { Frame { ... // Selection for Xiaomi Gateway Sounds // 10000 is STOP // >10001 are own sounds you uploaded to the gateway Selection item=Gateway_Sound mappings=[ 0="police car 1", 1="police car 2", 2="accident", 3="countdown", 4="ghost", 5="sniper rifle", 6="battle", 7="air raid", 8="bark", 10="doorbell", 11="knock at a door", 12="amuse", 13="alarm clock", 20="mimix", 21="enthusuastic", 22="guitar classic", 23="ice world piano", 24="leisure time", 25="child hood", 26="morning stream liet", 27="music box", 28="orange", 29="thinker"] } } ```