Skip to main content

xiaomipassive

LYWSD02, LYWSD03MMC (custom firmware ATC) and MiFlora passive scanner

Installation

git clone https://github.com/afer92/xiaomipassive.git
cd xiaomipassive
pip3 install .

Command line tool

xiaomipassivec

Output:

mac: 80:EA:CA:89:xx:yy conductivity:   54 µS/cm (2023-02-26T00:42:25)
mac: C4:7C:8D:64:xx:yyconductivity:  837 µS/cm (2023-02-26T00:42:25)
mac: C4:7C:8D:6C:xx:yy light:          26 lux   (2023-02-26T00:42:26)
...
A4:C1:38:09:xx:yy ATC_0990AB
=================
mac: A4:C1:38:09:xx:yyB rssi:          -35 dBm   (2023-02-26T00:42:39)
mac: A4:C1:38:09:xx:yy temperature:  21.6 °C    (2023-02-26T00:42:39)
mac: A4:C1:38:09:xx:yy moisture:       32 %     (2023-02-26T00:42:39)
mac: A4:C1:38:09:xx:yyB battery:        93 %     (2023-02-26T00:42:39)
mac: A4:C1:38:09:xx:yy volt:         3.04 V     (2023-02-26T00:42:39)

class XiaomiPassiveScanner

loop = asyncio.get_event_loop()
scanner = XiaomiPassiveScanner(loop, callback, timeout_seconds=240)

callback

Function call at each received advertissement

def callback(self, data):
    print(self.dump_result(data))

Output:

mac: C4:7C:8D:65:xx:yy conductivity: 376 µS/cm
mac: 80:EA:CA:89:xx:yy light:        283 lux
mac: 15:03:10:12:xx:yy moisture:     47.0 %
mac: C4:7C:8D:65:xx:yy temperature:  20.8 °C
mac: E7:2E:01:71:xx:yy battery:      18 %

Function dump_result format the data decoded in an advertisement

Dictionnary data:

{'ok': True,
 'mac': 'C4:7C:8D:6C:xx:yy',
 'sensor': 4100,
 'stype': 'temperature',
 'svalue': ListContainer([123, 0]),
 'typeCst': ListContainer([113, 32, 152, 0]),
 'num': 247,
 'tab': 13,
 'name': 'Flower care',
 'rssi': -87,
 'value': 12.3
 }

timeout_seconds

Scan for timeout_seconds, default=240s

devices

After timeout_seconds scanning, data collected for each mac address

Function dump_device(mac) format the data for one mac address

E7:2E:01:71:xx:yy LYWSD02
=================
mac: E7:2E:01:71:xx:yy rssi:          -93 dBm   (2023-02-24T19:34:19)
mac: E7:2E:01:71:xx:yy moisture:     47.0 %     (2023-02-24T19:32:44)
mac: E7:2E:01:71:xx:yy temperature:  20.6 °C    (2023-02-24T19:34:18)
mac: E7:2E:01:71:xx:yy battery:        18 %     (2023-02-24T19:33:37)

C4:7C:8D:65:B1:1D Flower care
=================
mac: C4:7C:8D:65:xx:yy rssi:          -81 dBm   (2023-02-24T19:34:19)
mac: C4:7C:8D:65:xx:yy light:         118 lux   (2023-02-24T19:33:41)
mac: C4:7C:8D:65:xx:yy moisture:       21 %     (2023-02-24T19:33:52)
mac: C4:7C:8D:65:xx:yy conductivity:  309 µS/cm (2023-02-24T19:34:04)
mac: C4:7C:8D:65:xx:yy temperature:  20.7 °C    (2023-02-24T19:34:15)

Example

#!/usr/bin/python3

from xiaomipassive import xiaomipassive as xiaomi
import asyncio

def main():

    def callback(self, result):
        print(self.dump_result(result))

    def get_data():
        loop = asyncio.get_event_loop()
        scanner = xiaomi.XiaomiPassiveScanner
        miflora_scanner = scanner(loop, callback, timeout_seconds=240)
        try:
            loop.run_until_complete(miflora_scanner.run())
        except KeyboardInterrupt as err:
            print(err)

        for mac, device in miflora_scanner.xdevices.items():
            print(device)

    get_data()


if __name__ == '__main__':
    exit(main())

Metadata

Release files for xiaomipassive 2023.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xiaomipassive 2023.2.6
File Size Uploaded Provenance Actions
xiaomipassive-2023.2.6.tar.gz 9.9 kB Without provenance Details for xiaomipassive-2023.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xiaomipassive 2023.2.6
File Interpreter ABI Platform Actions
xiaomipassive-2023.2.6-py3-none-any.whl Python 3 none any Details for xiaomipassive-2023.2.6-py3-none-any.whl

Total release size: 20.2 kB

Release files / xiaomipassive-2023.2.6.tar.gz

Download URL xiaomipassive-2023.2.6.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ab813bf19b934fcac2e2db7f06f7befc87c7e89e8614292bab854175dbf04d2d
BLAKE2b-256 checksum
How to use checksums
7f548596e827c07ad127851120c82b0c2a0f2036286ebbb74f13c992a667f708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.2

Release files / xiaomipassive-2023.2.6-py3-none-any.whl

Download URL xiaomipassive-2023.2.6-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
188396d48791e7b3323f7079309beca6c24e2e44695787ee9db3f3495df1eddd
BLAKE2b-256 checksum
How to use checksums
581311fb9dfdcfbcc8341f92b25506d7d6f3f734cae21c6ddf12082d129c5efc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.2

Security for xiaomipassive 2023.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page