homebridge-miot
is a plugin for homebridge which allows you to control any device supporting the miot protocol from Xiaomi!
The goal is to add Homekit support to miot devices and make them fully controllable from the native Homekit iOS app and Siri.
More device types will be added!
For a full list of supported devices by model check here: all supported devices by model.
If you are new to homebridge, please first read the homebridge documentation. If you are running on a Raspberry, you will find a tutorial in the homebridge wiki.
Install homebridge:
sudo npm install -g homebridge
Install homebridge-miot:
sudo npm install -g homebridge-miot
Add the miot
platform in config.json
in your home directory inside .homebridge
.
Add your devices in the devices
array.
Example configuration:
{
"platforms": [
{
"platform": "miot",
"micloud": {
"username": "miotuser@mio.com",
"password": "mySecretPassword",
"country": "cn"
},
"devices": [
{
"name": "Xiaomi Smartmi Fan 3",
"ip": "192.168.0.83",
"token": "63d4d8fba83f94aa5ad8f96536c84c12",
"pollingInterval": 10,
"horizontalMoveControl": true,
"buzzerControl": true,
"ledControl": true,
"modeControl": true,
"offDelayControl": true,
"ioniserControl": true,
"horizontalAngleButtons": [
5,
60,
100
],
"actionButtons": [
{
"action": "fan:toggle",
"name": "Toggle power action",
"params": [
123
]
},
{
"action": "2.3",
"name": "Toggle mode action"
}
],
"methodButtons": [
{
"method": "get_room_mapping",
"name": "Get room mapping"
}
],
"propertyControl": [
{
"property": "fan:anion",
"name": "Control anion"
},
{
"property": "2.7",
"value": 0,
"name": "Set natural wind mode"
},
{
"property": "custom-service:speed-level",
"config": {
"type": "fan"
}
}
],
"propertyMonitor": [
{
"property": "battery:battery-level",
"name": "Show bat level only when mode 1",
"linkedProperty": "vacuum:mode",
"linkedPropertyValue": 1
},
{
"property": "vacuum:mode",
"value": 2,
"name": "Notify when mode 2 set"
},
{
"property": "battery:battery-level",
"value": 15,
"valueOperator": "lessOrEqual",
"name": "Low Battery"
}
]
}
]
}
]
}
For the plugin to work the device token is required. The plugin offers you two ways to retrieve the token for your devices:
miot cloud-devices -u <username> -p <password>
in the command line to get the tokens for all your devices!Other ways:
Keep in mind that your device needs to support the feature which you enable, otherwise you will not see any effect.
platform
[required]
Must always be "miot".devices
[required]
A list of your devices.micloud
[optional]
This is a global configuration object for the MiCloud connection. When specified, this credentials will be used when a device requires a MiCloud connection. Some older devices require a MiCloud connection in order to be controlled! Default: "" (not specified)
name
[required]
The name of the accessory.ip
[required]
The ip address of your device.token
[required]
The token of your device.deviceId
[optional]
The deviceId is required for a MiCloud connection to identify the device. If not specified an attempt will be made to retrieve it from a local connection to the device Default: "" (not specified)model
[optional]
The device model if known. Should only be specified when certain about the device model. If specified then the accessory will be created instantly without the need to first discover and identify the device. Default: "" (not specified)micloud
[optional]
When specified overwrites the global setting for the device. Useful when you have devices on different servers or want to force certain devices to use MiCloud. Default: "" (not specified)prefsDir
[optional]
The directory where the device info will be stored. Default: "~/.homebridge/.xiaomiMiot"pollingInterval
[optional]
The device state polling interval in seconds. Default: 15propertyChunkSize
[optional]
Size of a property chunk when syncing properties with the device. A lower value might reduce the load on the device. Range 1-14 Default: device class default, if not defined -> 14deepDebugLog
[optional]
Enables additional more detailed debug log. Useful when trying to figure out issues with the plugin. Default: falsesilentLog
[optional]
When enabled all log output will only appear in debug mode. Default: falsedeviceEnabled
[optional]
Whether the device is enabled. Disabling the device will not initiate polling. Useful when a device is longer offline and it should not automatically reconnect. Default: truecustomAccessory
[optional]
Creates a custom empty accessory for the device which can be manually populated with services. Requires actionButtons, propertyControl or propertyMonitor to be set. Default: falseonlyMainService
[optional]
Only the main accessory service will be created without any additional services. Useful when wanting to have a clean layout. actionButtons, propertyControl or propertyMonitor can be used to manually add services. Default: falsebuzzerControl
[optional]
Whether the buzzer service is enabled. This allows to turn on/off the device buzzer/alarm. Default: trueledControl
[optional]
Whether the led service is enabled. This allows to turn on/off the device LED. Default: truechildLockControl
[optional]
Whether the child lock control service is enabled. This allows to turn on/off the device child lock. Default: truemodeControl
[optional]
Show mode switches which allow to change the device mode. Default: truesuppressAutoServiceCreation
[optional]
Suppress auto creation of some sensor services. Default: "" (not specified)
actionButtons
[optional]
Show additional action switches if the device supports any. Default: false
methodButtons
[optional]
Execute a raw miio method on the device. Can be useful for advanced robot cleaner configuration. Default: "" (not specified)
propertyControl
[optional]
Allows to control any properties of your device. Default: "" (not specified)
propertyMonitor
[optional]
Allows to monitor any properties of your device. Default: "" (not specified)
There are 4 ways to get the property an action names (or ids) used in actionButtons, propertyControl and propertyMonitor:
Some properties have a configuration which enables to change certain aspects of the resulting service.
It is also possible to connect BLE and ZigBee devices to the plugin via a gateway or hub. To do that, first the device needs to be connected to the gateway or hub, afterwards you have to manually specify the token and ip of the gateway/hub, but the model and deviceId needs to be that of the BLE or ZigBee device. All the required information can be retrieved from the MiCloud either via the Ui or the CLI commands.
Example:
{
"platforms": [
{
"platform": "miot",
"devices": [
{
"name": "Zigbee Outlet",
"ip": "<GATEWAY_IP>",
"token": "<GATEWAY_TOKEN>",
"model": "lumi.plug.mmeu01",
"deviceId": "<OUTLET_DID>",
}
]
}
]
}
The plugin also offers a command line interface to control your devices directly from the command line.
Just type miot
in the console to get a list of available options. Currently available are:
miot send
-> Send a RAW command over your local network to the devicemiot get-prop
-> Get the specified property value from the device. Accepts property id in the format siid:piidmiot set-prop
-> Set the value for the specified property. Accepts property id in the format siid:piidmiot action
-> Execute an action on the device. Accepts action id in the format siid:aiidmiot test
-> Test connection to a devicemiot tokens
-> Store and show tokens for specific devicesmiot cloud
-> Connect to the MiCloud, execute commands, list devices and get specific device infomiot fetch-metadata
-> Fetch device metadata for the specified modelExamples:
miot send <IP> -t <TOKEN> get_properties '[{"siid":2,"piid":2}]'
miot send <IP> -t <TOKEN> set_properties '[{"siid":2,"piid":2,"value":1}]'
miot send <IP> -t <TOKEN> action '{"aiid":13,"in":[],"siid":10}'
miot cloud list-devices
miot cloud get-props '[{"siid":2,"piid":2,"did":"<DID>"}]'
miot cloud set-props '[{"siid":2,"piid":2,"value":1,"did":"<DID>"}]'
If you have any issues with the plugin or device services then you can run homebridge in debug mode, which will provide some additional information. This might be useful for debugging issues.
Homebridge debug mode:
homebridge -D
Deep debug log, add the following to your config.json:
"deepDebugLog": true
This will enable additional extra log which might be helpful to debug all kind of issues.
You can test the connection to a device with the following cli command:
miot test <ip> -t <token>
If the connection test will succeed then your ip and token are correct!
HAP-NodeJS & homebridge - for making this possible.