A simple Python script which provides a Bluetooth to MQTT gateway, easily extensible via custom workers. See https://github.com/zewelor/bt-mqtt-gateway/wiki for more information.
Config
mqtt:
host: 192.168.2.153
port: 1883
username: test
password: test@123456
ca_cert: /etc/ssl/certs/ca-certificates.crt # Uncomment to enable MQTT TLS, update path to appropriate location.
ca_verify: False # Verify TLS certificate chain and host, disable for testing with self-signed certificates, default to True
topic_prefix: hostname # All messages will have that prefix added, remove if you dont need this.
client_id: bt-mqtt-gateway
availability_topic: lwt_topic
manager:
sensor_config:
topic: homeassistant
retain: true
topic_subscription:
update_all:
topic: homeassistant/status
payload: online
command_timeout: 35 # Timeout for worker operations. Can be removed if the default of 35 seconds is sufficient.
workers:
lywsd03mmc_homeassistant:
args:
devices:
bathroom: 00:11:22:33:44:55
topic_prefix: mijasensor_gen2
update_interval: 120
am43:
args:
devices:
upper_hall:
mac: a4:c1:38:6b:54:d2
pin: c19d8156b58038225c31f9a33b3d6412 # Pin code for the device
invert: true # Set to true to make position 100 be open instead of the default of closed
topic_prefix: blinds
per_device_timeout: 40
hass_device_class: blind # Optional; the default will be "shade", see https://www.home-assistant.io/integrations/cover/#device-class for details
iface: 0 # Optional; you can get the list of available interfaces by calling hciconfig
rapid_update_interval: 10 # Optional; if set — the status of the device would be requested automatically after this value of seconds,
if any activity was detected during the last update (or a command was executed)
default_update_interval: 300 # Optional; used together with `rapid_update_interval`, should have the same value as update_interval.
# when no changes detected after an update request, and `rapid_update_interval` is set, the update update_interval
# will be changed to `default_update_interval`.
topic_subscription: blinds/+/+/+
update_interval: 300
Debug gateway logs
(.venv) root@raspberrypi:/opt/bt-mqtt-gateway# sudo ./gateway.py
Traceback (most recent call last):
File "./gateway.py", line 11, in
import logger
File "/opt/bt-mqtt-gateway/logger.py", line 3, in
import yaml
ModuleNotFoundError: No module named 'yaml'
Server (please complete the following information):
Config mqtt: host: 192.168.2.153 port: 1883 username: test password: test@123456
ca_cert: /etc/ssl/certs/ca-certificates.crt # Uncomment to enable MQTT TLS, update path to appropriate location.
ca_verify: False # Verify TLS certificate chain and host, disable for testing with self-signed certificates, default to True
topic_prefix: hostname # All messages will have that prefix added, remove if you dont need this. client_id: bt-mqtt-gateway availability_topic: lwt_topic
manager: sensor_config: topic: homeassistant retain: true topic_subscription: update_all: topic: homeassistant/status payload: online command_timeout: 35 # Timeout for worker operations. Can be removed if the default of 35 seconds is sufficient.
workers:
lywsd03mmc_homeassistant: args: devices: bathroom: 00:11:22:33:44:55 topic_prefix: mijasensor_gen2 update_interval: 120 am43: args: devices: upper_hall: mac: a4:c1:38:6b:54:d2 pin: c19d8156b58038225c31f9a33b3d6412 # Pin code for the device invert: true # Set to true to make position 100 be open instead of the default of closed topic_prefix: blinds per_device_timeout: 40 hass_device_class: blind # Optional; the default will be "shade", see https://www.home-assistant.io/integrations/cover/#device-class for details iface: 0 # Optional; you can get the list of available interfaces by calling
hciconfig
rapid_update_interval: 10 # Optional; if set — the status of the device would be requested automatically after this value of seconds,if any activity was detected during the last update (or a command was executed)
Debug gateway logs (.venv) root@raspberrypi:/opt/bt-mqtt-gateway# sudo ./gateway.py Traceback (most recent call last): File "./gateway.py", line 11, in
import logger
File "/opt/bt-mqtt-gateway/logger.py", line 3, in
import yaml
ModuleNotFoundError: No module named 'yaml'
Server (please complete the following information):