Skip to content

Commit

Permalink
feat: add new Xiaomi Mi integration (#184)
Browse files Browse the repository at this point in the history
Kudos to the upstream projects that provided the code for the parser.

Closes #176.
  • Loading branch information
alan-strohm committed May 8, 2020
1 parent e2aecdb commit 0be912b
Show file tree
Hide file tree
Showing 10 changed files with 1,010 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/.vuepress/config.js
Expand Up @@ -82,7 +82,8 @@ module.exports = {
'/integrations/omron-d6t',
'/integrations/grid-eye',
'/integrations/gpio',
'/integrations/shell'
'/integrations/shell',
'/integrations/xiaomi-mi'
]
}
]
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/README.md
Expand Up @@ -29,4 +29,5 @@ Looking for a way to integrate OpenHAB? You can use the [Home Assistant Core](ho
| ------------------- | ------------------ |
| [GPIO](./gpio.md) | Binary sensors |
| [Shell](./shell.md) | Binary sensors |
| [Xiaomi Mi](./xiaomi-mi.md) | Temperature, humidity, etc sensors |

60 changes: 60 additions & 0 deletions docs/integrations/xiaomi-mi.md
@@ -0,0 +1,60 @@
# Xiaomi Mi Sensors

**Integration Key:** `xiaomiMi`

::: warning

Using this together with [Bluetooth Classic](./bluetooth-classic) requires multiple Bluetooth adapters.
Using this together with [Bluetooth Low Energy](./bluetooth-low-energy)
requires that the hciDeviceId settings of both integrations are the same value.

:::

The Xiaomi Mi integration scans for Bluetooth Low Engery (BLE) advertisements from a variety of Xiaomi sensors.
Sensor readings can then be published to MQTT using the [Home Assistant integration](./home-assistant).

## Requirements

This integration has all the same requirements as the [Bluetooth Low Energy](./bluetooth-low-energy) integration.

## Supported devices

This integration has been tested with these devices:

- LYWSD02

(rectangular body, E-Ink, broadcasts temperature and humidity, about 20 readings per minute, no battery info)

- LYWSD03MMC

(small square body, segment LCD, broadcasts temperature and humidity once in about 10 minutes and battery level once in an hour, advertisements are encrypted, therefore you need to set the key in your configuration, see for instructions the [bindKey](#sensor-options) option)

## Settings

| Name | Type | Default | Description |
| ----------------- | --------------------------------- | -------- | ------------------------------- |
| `sensors` | [Sensor options](#sensor-options) | | An array of sensor definitions. |
| `hciDeviceId` | Number | `0` | Bluetooth Device ID (e.g. `0` to use `hci0`). |

### Sensor Options

| Name | Type | Default | Description |
| ----------------- | ------ | -------- | ---------------------------------------------------------------------- |
| `name` | string | | A human readable name for the sensor. Will be used in MQTT topics. |
| `address` | string | | MAC address of the device ([Format](#address-format)). |
| `bindKey` | string | | A decryption key for sensors which send [encrypted data](#encryption). |

### Address Format

The `address` field is a lowercase MAC address without `:`. This is the same format as a [tag ID](./bluetooth-low-energy#determining-the-ids) in the BLE integration. The BLE integration can also be used to log device IDs to the console.

## Encryption

Some Xiaomi sensors encrypted their data (e.g. LYWSD03MMC). To be able to read the data from this sensor one needs to get a hold of the encryption key. For ways to get this key please read this [this FAQ entry](https://github.com/custom-components/sensor.mitemp_bt/blob/master/faq.md#my-sensors-ble-advertisements-are-encrypted-how-can-i-get-the-key) from the [custom-components/sensor.mitemp_bt](https://github.com/custom-components/sensor.mitemp_bt/) repository. Once found, it can be set with the [bindKey](#sensor-options) option.

## See also

There are many projects dedicated to these devices. This integration has particularly benefited from these two:

- [Homebridge plugin](https://github.com/hannseman/homebridge-mi-hygrothermograph). Much of the parser code came from this project.
- [mitemp_bt](https://github.com/custom-components/sensor.mitemp_bt/). One of the better documented projects with extensive device support.
2 changes: 2 additions & 0 deletions src/config/definitions/default.ts
Expand Up @@ -7,6 +7,7 @@ import { GridEyeConfig } from '../../integrations/grid-eye/grid-eye.config';
import { BluetoothClassicConfig } from '../../integrations/bluetooth-classic/bluetooth-classic.config';
import { GpioConfig } from '../../integrations/gpio/gpio.config';
import { ShellConfig } from '../../integrations/shell/shell.config';
import { XiaomiMiConfig } from '../../integrations/xiaomi-mi/xiaomi-mi.config';

export class AppConfig {
global: GlobalConfig = new GlobalConfig();
Expand All @@ -17,6 +18,7 @@ export class AppConfig {
gridEye: GridEyeConfig = new GridEyeConfig();
gpio: GpioConfig = new GpioConfig();
shell: ShellConfig = new ShellConfig();
xiaomiMi: XiaomiMiConfig = new XiaomiMiConfig();
homeAssistant: HomeAssistantConfig = new HomeAssistantConfig();
}

Expand Down
3 changes: 3 additions & 0 deletions src/integrations/xiaomi-mi/env.ts
@@ -0,0 +1,3 @@
import c from 'config';

process.env.NOBLE_HCI_DEVICE_ID = c.get('xiaomiMi.hciDeviceId');

0 comments on commit 0be912b

Please sign in to comment.