Skip to content

Commit

Permalink
Merge pull request #49 from custom-components/bleadv-decryption
Browse files Browse the repository at this point in the history
BLE ADV decryption
  • Loading branch information
Magalex2x14 authored Mar 8, 2020
2 parents b6afc5f + 3e00ade commit ed9c479
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 73 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ This custom component is an alternative for the standard build in [mitemp_bt](ht

(FlowerPot, RoPot, broadcasts moisture and conductivity, 2 readings per minute, no battery info with firmware v1.2.6)

- LYWSD03MMC

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

*The amount of actually received data is highly dependent on the reception conditions (like distance and electromagnetic ambiance), readings numbers are indicated for good RSSI (Received Signal Strength Indicator) of about -75 till -70dBm.*

**Do you want to request support for a new sensor? In the [FAQ](https://github.com/custom-components/sensor.mitemp_bt/blob/master/faq.md#my-sensor-from-the-xiaomi-ecosystem-is-not-in-the-list-of-supported-ones-how-to-request-implementation) you can read instructions how to request support for other sensors.**

## HOW TO INSTALL

**1. Grant permissions for Python rootless access to HCI interface (usually not needed on HASSio):**
Expand Down Expand Up @@ -105,9 +111,11 @@ sensor:
active_scan: False
hci_interface: 0
batt_entities: False
encryptors: 'A4:C1:38:2F:86:6C': '217C568CF5D22808DA20181502D84C1B'
report_unknown: False
```
Note: The encryptors parameter is only needed for LYWSD03MMC.
### Configuration Variables
Expand Down Expand Up @@ -159,6 +167,22 @@ sensor:
(boolean)(Optional) By default, the battery information will be presented only as a sensor attribute called `battery level`. If you set this parameter to `True`, then the battery sensor entity will be additionally created - `sensor.mi_batt_ <sensor_mac_address>`. Default value: False
#### encryptors
(dictionary)(Optional) This option is used to link the mac-address of the sensor broadcasting encrypted advertisements to the encryption key (32 characters = 16 bytes). This is only needed for LYWSD03MMC sensors. The case of the characters does not matter. The keys below are an example, you need your own key(s)! Information on how to get your key(s) can be found [here](https://github.com/custom-components/sensor.mitemp_bt/blob/master/faq.md#my-sensors-ble-advertisements-are-encrypted-how-can-i-get-the-key). Default value: Empty
```yaml
sensor:
- platform: mitemp_bt
encryptors:
'A4:C1:38:2F:86:6C': '217C568CF5D22808DA20181502D84C1B'
'A4:C1:38:D1:61:7D': 'C99D2313182473B38001086FEBF781BD'
```
#### report_unknown
(boolean)(Optional) This option is needed primarily for those who want to request an implementation of device support that is not in the list of [supported sensors](#supported-sensors). If you set this parameter to `True`, then the component will log all messages from unknown Xiaomi ecosystem devices to the Home Assitant log. **Attention!** Enabling this option can lead to huge output to the Home Assistant log, do not enable it if you do not need it! Details in the [FAQ](https://github.com/custom-components/sensor.mitemp_bt/blob/master/faq.md#my-sensor-from-the-xiaomi-ecosystem-is-not-in-the-list-of-supported-ones-how-to-request-implementation). Default value: False
## FREQUENTLY ASKED QUESTIONS
Still having questions or issues? Please first have a look on our [Frequently Asked Questions (FAQ) page](faq.md) to see if your question is already answered. There are some useful tips also.
Expand Down
19 changes: 12 additions & 7 deletions custom_components/mitemp_bt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
CONF_ACTIVE_SCAN = "active_scan"
CONF_HCI_INTERFACE = "hci_interface"
CONF_BATT_ENTITIES = "batt_entities"
CONF_ENCRYPTORS = "encryptors"
CONF_REPORT_UNKNOWN = "report_unknown"

# Default values for configuration options
DEFAULT_ROUNDING = True
Expand All @@ -19,6 +21,7 @@
DEFAULT_ACTIVE_SCAN = False
DEFAULT_HCI_INTERFACE = 0
DEFAULT_BATT_ENTITIES = False
DEFAULT_REPORT_UNKNOWN = False


"""Fixed constants."""
Expand All @@ -31,12 +34,13 @@

# Xiaomi sensor types dictionary with offset for adv parser
XIAOMI_TYPE_DICT = {
b'\x20\x98\x00': ["HHCCJCY01", 1],
b'\x20\xAA\x01': ["LYWSDCGQ", 0],
b'\x20\x5B\x04': ["LYWSD02", 1],
b'\x30\x47\x03': ["CGG1", 0],
b'\x20\x5D\x01': ["HHCCPOT002", 1],
b'\x20\xBC\x03': ["GCLS002", 1]
b'\x98\x00': "HHCCJCY01",
b'\xAA\x01': "LYWSDCGQ",
b'\x5B\x04': "LYWSD02",
b'\x47\x03': "CGG1",
b'\x5D\x01': "HHCCPOT002",
b'\xBC\x03': "GCLS002",
b'\x5B\x05': "LYWSD03MMC"
}


Expand All @@ -49,5 +53,6 @@
'HHCCPOT002': [9, 9, 0, 1, 9, 9],
'LYWSDCGQ' : [0, 1, 9, 9, 9, 2],
'LYWSD02' : [0, 1, 9, 9, 9, 9],
'CGG1' : [0, 1, 9, 9, 9, 2]
'CGG1' : [0, 1, 9, 9, 9, 2],
'LYWSD03MMC': [0, 1, 9, 9, 9, 2]
}
2 changes: 1 addition & 1 deletion custom_components/mitemp_bt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "mitemp_bt",
"name": "Xiaomi passive BLE monitor sensor integration",
"documentation": "https://github.com/custom-components/sensor.mitemp_bt",
"requirements": ["aioblescan==0.2.4"],
"requirements": ["aioblescan>=0.2.4", "pycryptodomex>=3.9.7"],
"dependencies": [],
"codeowners": [
"@Magalex2x14",
Expand Down
Loading

0 comments on commit ed9c479

Please sign in to comment.