Skip to main content

BLE to MQTT bridge

Project description

Service to export BLE devices to MQTT with Home Assistant discovery

!!! It is a very early alpha release !!!

Use this software at your own risk.

Default config should be located in /etc/ble2mqtt.json or can be overridden with BLE2MQTT_CONFIG environment variable.

Example run command:

BLE2MQTT_CONFIG=./ble2mqtt.json ble2mqtt

The configuration file is a JSON with the following content:

{
    "mqtt_host": "localhost",
    "mqtt_port": 1883,
    "mqtt_user": "",
    "mqtt_password": "",
    "log_level": "INFO",
    "devices": [
        {
            "address": "11:22:33:aa:cc:aa",
            "type": "presence"
        },
        {
            "address": "11:22:33:aa:bb:cc",
            "type": "redmond200"
        },
        {
            "address": "11:22:33:aa:bb:dd",
            "type": "xiaomihtv1"
        },
        {
            "address": "11:22:34:aa:bb:dd",
            "type": "xiaomihtv1",
            "passive": false
        },
        {
            "address": "11:22:33:aa:bb:ee",
            "type": "xiaomilywsd"
        },
        {
            "address": "11:22:33:aa:bb:ff",
            "type": "xiaomilywsd_atc"
        }
    ]
}

You can omit a line, then default value will be used.

Supported devices:

Any device

  • Any bluetooth device can work as a presence tracker

Kettles:

  • Redmond G2xx series (redmond200)

Humidity sensors:

  • Xiaomi MJ_HT_V1 (xiaomihtv1)
  • Xiaomi LYWSD03MMC (xiaomilywsd)
  • Xiaomi LYWSD03MMC with custom ATC firmware (xiaomilywsd_atc)

By default, a device works in the passive mode without connection by listening to advertisement packets from a device. To use connection to the device provide "passive": false parameter.

Supported devices in passive mode:

  • Xiaomi MJ_HT_V1 (xiaomihtv1)
  • Xiaomi LYWSD03MMC with custom ATC firmware (xiaomilywsd_atc)

OpenWRT installation

Execute the following commands in the terminal:

opkg update
opkg install python3-pip python3-asyncio
pip3 install http://github.com/hbldh/bleak/tarball/dbus-next-2#egg=bleak-0.11.0a1
pip3 install -U ble2mqtt

Create the configuration file in /etc/ble2mqtt.json and append your devices.

Bluetooth must be turned on.

hciconfig hci0 up

Run the service in background

ble2mqtt 2> /tmp/ble2mqtt.log &

Container

Build the image as:

podman build -t ble2mqtt:dev .

Start the container and share the config file and DBus for Bluetooth connectivity:

podman run \
-d \
--net=host \
-v $PWD/ble2mqtt.json.sample:/etc/ble2mqtt.json:z \
-v /var/run/dbus:/var/run/dbus:z \
ble2mqtt:dev

Instead of sharing /var/run/dbus, you can export DBUS_SYSTEM_BUS_ADDRESS.

NOTE: --net=host is required as it needs to use the bluetooth interface

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ble2mqtt-0.1.0a27.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

ble2mqtt-0.1.0a27-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file ble2mqtt-0.1.0a27.tar.gz.

File metadata

  • Download URL: ble2mqtt-0.1.0a27.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0

File hashes

Hashes for ble2mqtt-0.1.0a27.tar.gz
Algorithm Hash digest
SHA256 df765f56297a1c9a5d5b9132f7d315b849f185d059e7275a3ab1fce7f67c3b98
MD5 8264c509fa6321cc40f4187d647fd13a
BLAKE2b-256 a73eab239336d3e5b4a4d9f1e068f653e598c1990332bdd1fb66a9eecaec2b3c

See more details on using hashes here.

File details

Details for the file ble2mqtt-0.1.0a27-py3-none-any.whl.

File metadata

  • Download URL: ble2mqtt-0.1.0a27-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0

File hashes

Hashes for ble2mqtt-0.1.0a27-py3-none-any.whl
Algorithm Hash digest
SHA256 e79ca0a1192b7ed0a7a2b6ee5a90c0bf1abb45923777305edbfbc54fc49a40dc
MD5 7472b5095e8f120dbe11da4a0b042a0e
BLAKE2b-256 3873eac0444b3a15887ffe05ca137f7a99d026cf39bf336c8a9f306876fc77d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page