forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openhab#4 from dimalo/mihome-pullme
Several Improvements
- Loading branch information
Showing
6 changed files
with
304 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,186 @@ | ||
--- | ||
layout: documentation | ||
--- | ||
|
||
{% include base.html %} | ||
|
||
# Xiaomi Mi Smart Home Binding | ||
|
||
The binding allows your openHAB to communicate with Xiaomi Smart Home Suite. | ||
This binding allows your openHAB to communicate with the Xiaomi Smart Home Suite. | ||
|
||
In order to connect the Gateway, you need to install MiHome app | ||
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). | ||
|
||
## How to set up | ||
|
||
1. Install the binding | ||
2. Setup Gateway to be discoverable | ||
1. Add Gateway 2 to your WiFi Network | ||
2. Install Mi Home 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) | ||
3. Set your region to Mainland China under Settings -> Locale (seems to be required) | ||
4. Update gateway (maybe multiple times) | ||
5. Enable developer mode:<br /> | ||
1. Select your Gateway in Mi Home | ||
2. Go to the "..." menu and click "About" | ||
3. Tap the version number "Version : 2.XX" at the bottom of the screen repeatedly until you enable developer mode | ||
4. you should now have 2 extra options listed in Chinese. | ||
5. Choose the first new option (fourth position in the menu or the longer text in Chinese) | ||
6. Tap the toggle switch to enable LAN functions. Note down the developer key (something like: 91bg8zfkf9vd6uw7). | ||
7. Make sure you hit the OK button (to the right of the cancel button) to save your changes. | ||
4. In openHAB you should now be able to discover the Xiaomi Gateway | ||
5. 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.) | ||
6. Your sensors should be getting discovered by openHAB as you add and use them. | ||
## Setup | ||
|
||
* Install the binding | ||
* Setup Gateway to be discoverable | ||
|
||
1. Add Gateway 2 to your WiFi Network | ||
1. Install Mi Home 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 (maybe multiple times) | ||
1. Enable developer mode: | ||
|
||
1. Select your Gateway in Mi Home | ||
1. Go to the "..." menu 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 in Chinese | ||
1. Choose the first new option (fourth position in the menu or the longer text in Chinese) | ||
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: | ||
|
||
1. Online - within the MiHome App | ||
2. Offline - manual | ||
* 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 | ||
|
||
* Click 3 times on the Gateway's button | ||
* Gateway will flash in blue and you will hear female voice in Chinese | ||
* Place the needle into the sensor and hold it for at least 3 seconds | ||
* You'll hear confirmation message in Chinese | ||
|
||
## Important information | ||
|
||
The binding requires port `9898` to not be used by any other service on the system. | ||
|
||
## Full Example | ||
|
||
xiaomi.items: | ||
**xiaomi.items:** | ||
|
||
``` | ||
TODO | ||
// Xiaomi Gateway | ||
Dimmer Gateway_Brightness <dimmablelight> { channel="mihome:gateway:<ID>:brightness" } | ||
Color Gateway_Color <rgb> { channel="mihome:gateway:<ID>:color" } | ||
Dimmer Gateway_ColorTemperature <heating> { channel="mihome:gateway:<ID>:colorTemperature" } | ||
// Xiaomi Temperature and Humidity Sensor | ||
Number HT_Temperature <temperature> { channel="mihome:sensor_ht:<ID>:temperature" } | ||
Number HT_Humidity <humidity> { channel="mihome:sensor_ht:<ID>:humidity" } | ||
// NOTE: Battery level will be sent when battery is low | ||
Number HT_Battery <battery> { channel="mihome:sensor_ht:<ID>:voltage" } | ||
// Xiaomi Motion Sensor | ||
Switch MotionSensor_MotionStatus <motion> { channel="mihome:sensor_motion:<ID>:motion" } | ||
DateTime MotionSensor_LastMotion "[%1$tY-%1$tm-%1$td %1$tH:%1$tM]" <clock-on> { channel="mihome:sensor_motion:<ID>:lastMotion" } | ||
// NOTE: Battery level will be sent when battery is low | ||
Number MotionSensor_Battery <battery> { channel="mihome:sensor_motion:<ID>:voltage" } | ||
// Xiaomi Plug | ||
Switch Plug_Switch <switch> { channel="mihome:sensor_plug:<ID>:powerOn" } | ||
Number Plug_Voltage <poweroutlet> { channel="mihome:sensor_plug:<ID>:loadVoltage" } | ||
Number Plug_Power <energy> { channel="mihome:sensor_plug:<ID>:loadPower" } | ||
Number Plug_Consumption <line-incline> { channel="mihome:sensor_plug:<ID>:powerConsumed" } | ||
// Xiaomi Window Switch | ||
Contact WindowSwitch_Status <window> { channel="mihome:sensor_magnet:<ID>:isOpen" } | ||
// NOTE: Battery level will be sent when battery is low | ||
Number WindowSwitch_Battery <battery> { channel="mihome:sensor_magnet:<ID>:voltage" } | ||
// Xiaomi Cube - see "xiaomi.rules" for action triggers | ||
Number Cube_RotationAngle { channel="mihome:sensor_cube:<ID>:rotationAngle" } | ||
Number Cube_RotationTime { channel="mihome:sensor_cube:<ID>:rotationTime" } | ||
// NOTE: Battery level will be sent when battery is low | ||
Number Cube_Battery <battery> { channel="mihome:sensor_cube:<ID>:voltage" } | ||
// Xiaomi Switch - see "xiaomi.rules" for action triggers | ||
// NOTE: Battery level will be sent when battery is low | ||
Number Switch_Battery <battery> { channel="mihome:sensor_switch:<ID>:voltage" } | ||
``` | ||
|
||
xiaomi.rules: | ||
**xiaomi.rules:** | ||
|
||
``` | ||
rule "Xiaomi Switch single click" | ||
rule "Xiaomi Switch" | ||
when | ||
Channel "mihome:sensor_switch:<id>:button" triggered CLICK | ||
Channel "mihome:sensor_switch:<ID>:button" triggered | ||
then | ||
if (Vacuum_Dock.state == ON) { | ||
sendCommand(Vacuum_Dock, OFF) | ||
} else { | ||
sendCommand(Vacuum_Dock, ON) | ||
var actionName = receivedEvent.getEvent() | ||
switch(actionName) { | ||
case "CLICK": { | ||
<ACTION> | ||
} | ||
case "DOUBLE_CLICK": { | ||
<ACTION> | ||
} | ||
case "LONG_CLICK_PRESS": { | ||
<ACTION> | ||
} | ||
case "LONG_CLICK_RELEASE": { | ||
<ACTION> | ||
} | ||
} | ||
end | ||
rule "Xiaomi Switch double click" | ||
rule "Xiaomi Cube" | ||
when | ||
Channel "mihome:sensor_switch:<id>:button" triggered DOUBLE_CLICK | ||
Channel 'mihome:sensor_cube:<ID>:action' triggered | ||
then | ||
if (Gateway_Light.state > 0) { | ||
sendCommand(Gateway_Light, OFF) | ||
} else { | ||
sendCommand(Gateway_Light, ON) | ||
var actionName = receivedEvent.getEvent() | ||
switch(actionName) { | ||
case "MOVE": { | ||
<ACTION> | ||
} | ||
case "ROTATE_RIGHT": { | ||
<ACTION> | ||
} | ||
case "ROTATE_LEFT": { | ||
<ACTION> | ||
} | ||
case "FLIP90": { | ||
<ACTION> | ||
} | ||
case "FLIP180": { | ||
<ACTION> | ||
} | ||
case "TAP_TWICE": { | ||
<ACTION> | ||
} | ||
case "SHAKE_AIR": { | ||
<ACTION> | ||
} | ||
case "FREE_FALL": { | ||
<ACTION> | ||
} | ||
case "ALERT": { | ||
<ACTION> | ||
} | ||
} | ||
end | ||
rule "Bedroom light control with cube" | ||
rule "Xiaomi Motion Sensor" | ||
when | ||
Channel 'mihome:sensor_cube:<id>:action' triggered | ||
Item MotionSensor_MotionStatus changed | ||
then | ||
if (receivedEvent.event == "SHAKE_AIR") { | ||
if (LEDBulb_Brightness.state == 0) { | ||
sendCommand(LEDBulb_Brightness, ON) | ||
sendCommand(LEDBulb_ColorTemperature, 50) | ||
if (MotionSensor_MotionStatus.state == ON) { | ||
<ACTION> | ||
} else { | ||
sendCommand(LEDBulb_Brightness, OFF) | ||
<ACTION> | ||
} | ||
} else if (receivedEvent.event == "FLIP90") { | ||
sendCommand(LEDBulb_Brightness, ON) | ||
sendCommand(LEDBulb_ColorTemperature, 10) | ||
} else if (receivedEvent.event == "FLIP180") { | ||
sendCommand(LEDBulb_Brightness, ON) | ||
sendCommand(LEDBulb_Color, new HSBType(new DecimalType(90),new PercentType(100),new PercentType(100))) | ||
} | ||
end | ||
rule "Xiaomi Window Switch" | ||
when | ||
Item WindowSwitch_Status changed | ||
then | ||
if (WindowSwitch_Status.state == OPEN) { | ||
<ACTION> | ||
} else { | ||
<ACTION> | ||
} | ||
end | ||
rule "Hallway night light" | ||
// This rule is applicable for every battery powered sensor device | ||
rule "Xiaomi Motion Sensor Low Battery" | ||
when | ||
Item MotionSensor_MotionStatus changed from OFF to ON or | ||
Item MotionSensor_MotionStatus changed from ON to OFF | ||
Channel "mihome:sensor_motion:<ID>:batteryLevel" triggered LOW | ||
then | ||
if (MotionSensor_MotionStatus.state == ON) { | ||
sendCommand(Gateway_Brightness, new PercentType(2)) | ||
Thread::sleep(100) | ||
sendCommand(Gateway_Color, HSBType.fromRGB(i255, 241, 224)) | ||
} else { | ||
sendCommand(Gateway_Brightness, new PercentType(0)) | ||
} | ||
<ACTION> | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.