Package: ble2mqtt
BLE2MQTTControl your Bluetooth devices with smart homeSupported devices:Any deviceAny bluetooth device can work as a presence tracker
You can provide"threshold"parameter to the device to set the limit in
second when the device is considered away. The default value is 180 seconds.KettlesRedmond RK-G2xxS series (type: redmond_rk_g200)The default key that is used is"ffffffffffffffff"and can be omitted in the config.
In some cases kettles don't accept it. Just use another
key in the config file for the device:"key": "16 random hex numbers"Mi Kettle (type: mikettle)Use correctproduct_idfor your kettle:yunmi.kettle.v1:131yunmi.kettle.v2:275(default)yunmi.kettle.v7:1116Multi-CookersRedmond RMC-M225S, RMC-M227S (type: redmond_rmc_m200)Notes about the key parameter you can read above for the
Redmond kettles.Other RMC multi-cookers may need
adjustments for the list of available programs, it depends
on the device panel.Humidity sensorsXiaomi MJ_HT_V1 (type: xiaomihtv1)Xiaomi LYWSD02MMC (type: xiaomihtv1)Xiaomi LYWSD03MMC (type: xiaomilywsd)(due to the connection to the device on
every data fetch, it consumes more battery power. Flashing to the custom
firmware is recommended)Xiaomi LYWSD03MMC with custom ATC firmware (xiaomilywsd_atc)supported both atc1441 and pvvx formatsQingping CGDK2 (type: qingpingCGDK2)RuuviTag (type: ruuvitag)RuuviTag Pro 2in1 (type: ruuvitag_pro_2in1)RuuviTag Pro 3in1 (type: ruuvitag_pro_3in1)RuuviTag Pro 4in1 (type: ruuvitag)Govee H5074 (type: govee_ht)Air sensorsVson WP6003 (type: wp6003)Shades and BlindsGeneric AM43 (type: am43)Manufacturer can be A-OK, Zemismart, etc.Soma Shades (type: soma_shades)BulbsAvea RGBW bulbs (type: avea_rgbw)DosimetersAtom Fast (type: atomfast)HeatersEnsto EPHBEBT10PR, EPHBEBT15PR (type: ensto_thermostat)These devices requiremanual pairing.
After the device is paired on the host device, see the logs for thekeyand
put it to the config.The adapter uses holiday mode to control temperature as thermostat. You cannot
use this feature in the official app while ble2mqtt is working.Vacuum cleanersRoidmi NEX2 Pro (type: roidmi_cleaner)Battery voltage metersBM2 car battery voltage meter (type: voltage_bm2)Plant sensors:LifeControl MCLH-09 (type: mclh09)optionally, polling interval can be configured withintervalparameter in secondsXiaomi Mi Flora (type: miflora)optionally, polling interval can be configured withintervalparameter in secondsBy 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": falseparameter.Supported devices in passive mode:Xiaomi MJ_HT_V1 (xiaomihtv1)Xiaomi LYWSD03MMC with custom ATC firmware (xiaomilywsd_atc)RuuviTag (ruuvitag/ruuvitag_pro_2in1/ruuvitag_pro_3in1)Govee temperature/humidity sensors (govee_ht)Any device as presence trackerManual pairing in LinuxSome devices (e.g. Ensto heaters) require paired connection to work with it.
You need to pair the device with linux machine before using it.Find out MAC addresses of your devices. Put the device in pairing mode if it is supported.Open console and runbluetoothctlcommand. It is a command line tool to work with BLE devices.
Wait for the prompt[bluetooth]#Print a command to enable scanning. Linux must know the device is present before pairing.[bluetooth]# scan onWait for MAC address of the device appears in the list of found devices.
Print a pairing command (replace MAC address to the one from your device)[bluetooth]# pair 90:fd:00:00:00:01On successful pairing you'll see a message:[CHG] Device 90:FD:00:00:00:01 Paired: yes
Pairing successfulYou can proceed with the next configuration steps now.Selinux issuesIf using SELinux and you are experience issues, seeREADME.md.Known issues:High cpu usage due to underlying library to work with bluetoothUse this software at your own risk.ConfigurationDefault config should be located in/etc/ble2mqtt.jsonor
can be overridden withBLE2MQTT_CONFIGenvironment variable.Example run command:BLE2MQTT_CONFIG=./ble2mqtt.jsonble2mqttThe 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":"redmond_rk_g200","key":"ffffffffffffffff"},{"address":"11:22:33:aa:bb:c0","type":"redmond_rmc_m200","key":"ffffffffffffffff"},{"address":"11:22:33:aa:bb:c1","type":"ensto_thermostat","# see logs after pairing and put the key to config":"","key":"00112233"},{"address":"11:22:33:aa:bb:cd","type":"mikettle","product_id":275},{"address":"11:22:33:aa:bb:de","type":"am43"},{"address":"11:22:33:aa:bb:dd","type":"xiaomihtv1","interval":60},{"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","interval":60},{"address":"11:22:33:aa:aa:aa","type":"atomfast"},{"address":"11:22:33:aa:aa:bb","type":"voltage_bm2"},{"address":"11:22:33:aa:aa:bc","type":"mclh09","interval":600},{"address":"11:22:33:aa:aa:bd","type":"miflora","interval":500},{"address":"11:22:33:aa:aa:be","type":"ruuvitag","interval":60},{"address":"11:22:33:aa:aa:0a","type":"roidmi_cleaner"}]}You can omit a line, then default value will be used.Extra configuration parameters:"base_topic"- the default value is 'ble2mqtt'"mqtt_prefix"- a prefix to distinguish ble devices from other instances and
programs. The default value is 'b2m_'."hci_adapter"- an adapter to use. The default value is "hci0"Devices acceptfriendly_nameparameter to replace mac address in device
names for Home Assistant.Systemd unit file to start on bootPut the following content to the unit file/etc/systemd/system/ble2mqtt.service[Unit]
Description=ble2mqtt bridge

[Service]
Type=Simple
ExecStart=/usr/local/bin/ble2mqtt
User=ble2mqtt
Group=ble2mqtt
Wants=bluetooth.target

[Install]
WantedBy=multi-user.targetThe user and group should match the owner and group of the configuration file /etc/ble2mqtt.json.Afterwards you simply have to enable and start the service:sudosystemctldaemon-reload
sudosystemctlenableble2mqtt
sudosystemctlstartble2mqttInstallation on OpenWRTOpenWRT 23.05 and laterCreate the configuration file in /etc/ble2mqtt.json and
append your devices.Execute the following commands in the terminal:opkgupdate
opkginstallpython3-ble2mqtt
/etc/init.d/ble2mqttenable/etc/init.d/ble2mqttstartOpenWRT 22.03 and earlierExecute the following commands in the terminal:opkgupdate
opkginstallpython3-pippython3-asyncio
pip3install"bleak>=0.11.0"pip3install-Uble2mqttCreate the configuration file in /etc/ble2mqtt.json and
append your devices.Bluetooth must be turned on.hciconfighci0upRun the service in backgroundble2mqtt2>/tmp/ble2mqtt.log&Add a service script to start:cat<<EOF > /etc/init.d/ble2mqtt#!/bin/sh /etc/rc.commonSTART=98USE_PROCD=1start_service(){procd_open_instanceprocd_set_param env BLE2MQTT_CONFIG=/etc/ble2mqtt.jsonprocd_set_param command /usr/bin/ble2mqttprocd_set_param stdout 1procd_set_param stderr 1procd_close_instance}EOFchmod+x/etc/init.d/ble2mqtt
/etc/init.d/ble2mqttenable/etc/init.d/ble2mqttstartRunning on Xiaomi Zigbee GatewayDue to small CPU power and increasing number of messages from bluetoothd
it is recommended to do several workarounds:Use passive mode for those sensors for which this is possible. E.g. use
custom ATC firmware for lywsd03mmc sensorsRestartbluetoothddaily and restart ble2mqtt several times a day to
reduce increasing CPU usage.
Put the following lines to the/etc/crontabs/root10 0,7,17 * * * /etc/init.d/ble2mqtt restart
1 4,14 * * * /etc/init.d/bluetoothd restartRunning in ContainerBuild the image as:podmanbuild-tble2mqtt:dev.Start the container and share the config file and DBus for Bluetooth connectivity:podmanrun\-d\--net=host\-v$PWD/ble2mqtt.json.sample:/etc/ble2mqtt.json:z\-v/var/run/dbus:/var/run/dbus:z\ble2mqtt:devInstead of sharing/var/run/dbus, you can exportDBUS_SYSTEM_BUS_ADDRESS.NOTE:--net=hostis required as it needs to use the bluetooth interfaceNOTE:podmanis the same asdockerRunning in Container FULLyATTENTION:Make surebluezis not running (or not intalled) on your host.Build the image as:dockerbuild-tble2mqtt:dev.Start the container and share the config file:dockerrun\-d\--net=host\--cap-add=NET_ADMIN\-v$PWD/ble2mqtt.json.sample:/etc/ble2mqtt.json:ro\ble2mqtt:devDocker compose:version:'3.7'services:ble2mqtt:image:ble2mqtt:devbuild:./ble2mqtthostname:ble2mqttrestart:alwaysenvironment:-TZ=Asia/Yekaterinburgvolumes:-./ble2mqtt/ble2mqtt.json:/etc/ble2mqtt.json:ronetwork_mode:hostcap_add:-NET_ADMINYou do not need sharing/var/run/dbus, becausedbuswill start in the container.NOTE:--net=hostand--cap-add=NET_ADMINis required as it needs to use and control the bluetooth interface