Xiaomi Gateway (Aqara)

From Domoticz
Jump to: navigation, search

Xiaomi Gateway

Xiaomi (Aqara) makes a smart home gateway/hub that has support for a variety of Xiaomi sensors. They can be purchased on AliExpress or other stores at very competitive prices. Protocol is Zigbee and WiFi, and the gateway and Domoticz need to be in the same network/subnet.

Multiple gateways are not supported (this decision has been made to simplify development during beta. For now, you can setup a second Domoticz server on a different subnet to run a 2nd Xiaomi Gateway), however the Smart Socket/Plug *may* act as a wireless repeater so you can use these to extend network range.

If you experience problems and are connecting your Domoticz server through a LAN cable, try connecting Domoticz through WiFi instead.

Currently you need the beta version of Domoticz to support the Xiaomi Gateway and devices

Note that the gateway needs to be at least version 2. Radio support on the gateway indicates at least version 2. If you are unsure, please ask your supplier before purchasing

Xiaomi.jpg

Compatible Devices

Compatible Devices:

  1. Human Body Sensor (Motion Sensor)
  2. Wireless Smart Switch
  3. Door/Window Sensor
  4. Temperature and Humidity Sensor
  5. Smart Socket/Plug - Zigbee version (The WiFi version is not supported)
  6. Xiaomi Mi Smart Cube
  7. Wireless Aqara Switch (Dual Button)
  8. Wireless Aqara Switch (Single Button)
  9. Wired Aqara Switch (Dual Button)
  10. Wired Aqara Switch (Single Button)
  11. Xiaomi Gateway LED, Speaker/Alarm, Illumination Sensor

Adding the Xiaomi Gateway to Domoticz

You first need to enable local network functions by using the Android Mi Home App https://play.google.com/store/apps/details?id=com.xiaomi.smarthome

  1. Install the App on a Android device
  2. Make sure you set your region to: Mainland China under settings -> Locale - at time of writing this seems to be required.
  3. Mainland China and language can set on English
  4. Select your Gateway in Mi Home
  5. Then the 3 dots at the top right of the screen
  6. Then click on about
  7. Tap the version (2.23 is the current Android version as of 8 March 2017) number at the bottom of the screen repeatedly
  8. You should see now 2 extra options listed in English (was Chinese in earlier versions)until you did now enable the developer mode. [ if not try all steps again!]
  9. Choose the first new option
  10. Then tap the first toggle switch to enable LAN functions. Note down the password (91bg8zfkf9vd6uw7 in the screenshot). Make sure you hit the OK button (to the right of the cancel button) to save your changes.
  11. If you change here something, you lose your password! [ this password you need in Domoticz ]

Xiaomi 01.png

Now choose the second new menu option, and note down the IP address after "localIp".
Make the IP static in your router!

Then in Domoticz go to Setup -> Hardware, and choose the Xiaomi Gateway Type. Enter the following:

  1. Name: "Xiaomi Gateway" or anything you want to name it
  2. Remote Address: the IP address of your gateway
  3. Port: Use 9898 Note that you cannot have another service on your system already using port 9898
  4. Password: The password of your gateway

Note that you may need to clear your browser cache if you can't see the Xiaomi Gateway option and/or all the fields

Xiaomi 03.PNG

  1. Then click the Add button.
  2. set in Domotic new hardware and devices active
  3. Navigate to Setup -> Devices, and you should now see detected devices listed.

You should learn the new Xiaomi devices [ sensors you have ] first on the gateway with the Xiaomi app. When they are learned in the gateway, you will see the devices under new devices in Domoticz.


Playing Gateway Sound

Since FW 1.4.1_145.0141 we are enable to playing sound who are stored on the Gateway (Already stored and personnilised ones) for using them Domoticz create 5 Switches :

  1. Xiaomi Gateway Alarm Ringtone : Off/Police siren 1/Police siren 2/Accident tone/Missle countdown/Ghost/Sniper/War/Air Strike/Barking dogs
  2. Xiaomi Gateway Alarm Clock : Off/MiMix/Enthusiastic/GuitarClassic/IceWorldPiano/LeisureTime/Childhood/MorningStreamlet/MusicBox/Orange/Thinker
  3. Xiaomi Gateway Doorbell : Off/Doorbell ring tone/Knock on door/Hilarious/Alarm clock
  4. Xiaomi Gateway MP3 : Who allow to play personnalise sound that you store on the gateway using MiHome App, see below for more information
  5. Xiaomi Gateway Volume : Who allow to set Gateway Volume, each time this slider is trigger gateway will play last sound set from Domoticz


Gatewaysound.png

Each Sound can be trigger on Scene/Group/Lua/Blocky and Json Call


About Xiaomi Gateway MP3

This switch Allow you to play sound that you have stored on the gateway using MiHome App. Each sound have a record number who start by 100xx : 10000 : Is always stop 10001 : First personnalise sound 10002 : Second personnalise sound etc etc..

When Domoticz create this Switch, it create a User Variable : XiaomiMP3 with 10001 as a value : remember what is 10001 ? first sound recorded on the gateway ! Change it for 10002, click on Xiaomi Gateway MP3 switch and it will play sound 10002 which is your second personnilise sound.

IMPORTANT : If you record a sound as 10001 and erase it after, 10001 value is no more usable, each new sound value number growup. Actually, we don't know what is the limit, as on file seize and on 100xx value

Easy Way to use personnilise sound

To be more easy to use, we "offer" you a simple tweak who allow you to play 99 personnilise sound.

First create a dummy Selector, and call it Mid Value, edit this brand new dummy and set it as a Dimmer.

Midvalue.png

Then Create a Device Lua Script who will react to this Dummy Slider and update XiaomiMP3 user variable

--script_device_Xiaomimp3.lua
--as each sound is recorded as 100+xx value the slider will update user variable to 10000+dimmer value and play sound
commandArray = {}
 
if devicechanged['Mid Value'] then
      DomValue = otherdevices_svalues['Mid Value'];
       NumericValue = tonumber(DomValue)
            Calcvalue = (NumericValue + 10000)
 
    commandArray['Variable:XiaomiMP3']=''..Calcvalue..''
    print('Xiaomi Gateway will play sound stored on bank '..Calcvalue)
    commandArray['Xiaomi Gateway MP3']='On'
 
end
return commandArray

On the dimmer pic : value is 3 that mean that Variable:XiaomiMP3 is set to 10003, gateway will play the 3rd sound I store on the gateway.

With this script each time you change value on the dimmer Gateway will automaticaly play sound, not easy to to on point and clik but really usefull on Scene/Group/Lua/Blocky and Json Call, have a try to record fonction from MiHome app, that an easy way to made some vocal notification with your favorite voice


Great job Corbin & Deennoo !!

Troubleshooting

Problem Solution
After adding the gateway, no devices are found in Domoticz OR devices do not update state Solution: You need to ensure the system Domoticz is running on can receive UDP Multicast packets. On Linux, this can be done with

iptables -P OUTPUT ACCEPT

iptables -I INPUT -p udp -j ACCEPT

After adding the gateway, no devices are found in Domoticz OR devices do not update state Make sure the WiFi where your Xiaomi Gateway is connected is on the same subnet as your Domoticz server. Also have your Domoticz server connected directly to the same WiFi network, rather than a LAN cable (try disconnecting the LAN cable as well)
Unable to control devices (Smart Plug/Gateway Light/Alarm) Enter the correct IP address for your gateway. Be aware that if you restart your Xiaomi Gateway, it may get a new IP address and this will need to be updated in Domoticz. Note, devices will still be found if you have an incorrect IP address or password entered.
Error: XiaomiGateway: unable to write command - Invalid Key Enter the correct password for your gateway. Double check it is exact, with no extra spaces.

You can enable the raw gateway messages to appear in the Domoticz log by creating a user variable 'XiaomiMessage' of type Integer and value 1. (Setup -> More Options -> User Variables). Then restart the Gateway hardware in Domoticz.