Theengs Gateway - BLE to MQTT on a Raspberry Pi, Windows PC or Apple Mac

I am using the docker installation, thus i have the env var set to false.

With that configuration, every bluetooth device that comes in range will be taken and send to my mqtt server. Those it does not decode anything just get an empty topic without any content

What is the expected behavoir as per design? How would the gateway distingues between devices to be send and those to be ignored - especially since BLE sensors will not require any pairing?

The gateway will analyze the advertisements received through Theengs Decoder. When using the publish_all to 0, If the advertisement matches a recognized device, it will publish it to the broker.
If not, it will not.

Hi, would like to use this for my switchbot.
I have successfully istalled the Gateway on my pi where oh is.

In my MQTT explorer I also see the device.

How can I send a command to it?

At my things there is only a sensor and the state is unknown.

Thanks in advance and sorry for my bad English.

Hi @Joko,

Not sure why you are not seeing the state for the SwitchBot thing, it should also have the properties you see in MQTT Explorer. I don’t use auto-discovery, so not exactly sure where the problem might lie.

Do you have MQQT set up fully in OH, possibly using other MQTT devices?

For writing the commands the WRITE command of OpenMQTTGateway is required, as described at

Not having a SwitchBot myself, but other MQTT controlled devices I (admittedly manually defined) I would use a String Type Thing with the commandTopic

home/OpenMQTTGateway/commands/MQTTtoBT/config
  • the gateway name being the one of your gateway - and the string(s)

{\"mac\":\"AA:BB:CC:DD:EE:FF\",\"SBS1\":\"on\"}
respectively
{\"mac\":\"AA:BB:CC:DD:EE:FF\",\"SBS1\":\"off\"}

You could initially try these command (without the escaped ") in MQTT Explorer’s Publish section, so see if it is all working fine there.

{"mac":"AA:BB:CC:DD:EE:FF","SBS1":"on"}
respectively
{"mac":"AA:BB:CC:DD:EE:FF","SBS1":"off"}

Thank you for your anwer.

But unfortunally it didn´t work.
I userd the method with the ESP32 and this is working.

But I don´t want to use an other device. My pi can bluetooth. Do you have an other hint for me?

Thanks in advance.

Sorry, my bad, Theengs Gateway on the Pi does currently not have any READ/WRITE capability, so no commands can be sent through it.

Only OpenMQTTGateway on an ESP32 has this implemented so far.

Theengs installed as a service stops receiving all measurements after a while

I am using theengsgateway successfully since a few months on a raspberry pi 0 w and on a raspberry pi 3.

I recently started using a raspberty pi 4 with a metal case for passive cooling. I therefore installed an external Bluetooth adapter connected with a cable and disabled internal Bluetooth.

In this case it happens that Theengsgateway do not receive sensor data any more. I have to restart the Bluetooth service or reboot the raspberry.
I disabled WiFi, if this matter.

Strangely, when theengsgateway does not receive data, if I issue sudo hcitool lescan I see the Mac address of sensors.

Does it happen to others?
Thanks

Hello!
Could you add support for YEELIGHT remote control YLYK01YL ?
It use MiBeacon symilar to LYWSD03MMC.
Here is info about it:

encryption_key

(string, 24 or 32 characters)(Optional) This option is used for sensors broadcasting encrypted advertisements. The encryption key should be 32 characters (= 16 bytes) for most devices (LYWSD03MMC, CGD1, MCCGQ02HL, and MHO-C401 (original firmware only). Only Yeelight YLYK01YL (all types), YLYB01YL-BHFRC, YLKG07YL and YLKG08YL require a 24 character (= 12 bytes) long key. 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://custom-components.github.io/ble_monitor/faq#my-sensors-ble-advertisements-are-encrypted-how-can-i-get-the-key). Default value: Empty

ble_monitor:
devices:
- mac: ‘A4:C1:38:2F:86:6C’
encryption_key: ‘217C568CF5D22808DA20181502D84C1B’

I’ve got few of them so I can test it .

Hi @Dom_KS

We’ve only recently introduced decoding of encrypted broadcast data in the current development branch of Theengs Gateway and the related Theengs Decoder library, so we’d be interested to include further encrypted devices like your YEELIGHT remote YLYK01YL.

It would be very helpful to get some undecrypted and undecoded sample data from you with the current development branch version.

If you are unable to download and build the development branch yourself it might be best waiting for the next official release to work on including the YLYK01YL.

For most convenient tracking of this new device could you open a new discussion issue about it in the Theengs Gateway GitHub Discussions?

Thanks

I am sorry if this is not the right place for my question. But I don’t know where I can put this.

I installad Theengs on Docker with docker-compose. It seems that my bluetooth stick is recognized. But nothing is found. I have a Switchbot Bot I will control on home assistant.

On MQTT Explorer I don’t see anything. And in HASS there is not device at all.

What is my problem? Where can I start to debug it?

Thanks
Nils

Do you have the LOG_LEVEL environment variable set to DEBUG? What output do you see in the container’s logs?

This is the output of my container log:

Creating config at /root/theengsgw.conf ...
{
    "host": "XXX.XXX.XXX.XXX",
    "pass": "XXXXXXXXXX",
    "user": "XXXXXXXXXX",
    "port": 1883,
    "publish_topic": "home/TheengsGateway/BTtoMQTT",
    "subscribe_topic": "home/+/BTtoMQTT/undecoded",
    "presence_topic": "home/presence/TheengsGateway",
    "presence": false,
    "publish_all": true,
    "publish_advdata": false,
    "ble_scan_time": 60,
    "ble_time_between_scans": 60,
    "log_level": "DEBUG",
    "lwt_topic": "home/TheengsGateway/LWT",
    "discovery": true,
    "hass_discovery": true,
    "discovery_topic": "homeassistant/sensor",
    "discovery_device_name": "TheengsGateway",
    "discovery_filter": "[IBEACON]",
    "scanning_mode": "active",
    "adapter": "hci0",
    "time_sync": "[]",
    "time_format": "0"
}
INFO:BLEGateway:Starting BLE scan
INFO:BLEGateway:Connected to MQTT Broker!
INFO:BLEGateway:Subscribed to home/+/BTtoMQTT/undecoded

I tried it with other ways to. I have a Pi4 around and installed Theengs on it, startet the scan with python. Still no Switchbot devices is shown. I also tried the USB dongle direktly on my Home Assistant. It is recongnized but still doesn’t find my Switchbot.

Are you sure the adapter is hci0, as set in the Theengs Gateway configuration? And how do you give the container access to the Bluetooth adapter? What’s your docker-compose.yml look like for Theengs Gateway?

This is the device on the host server:

This is the hciconfig output on the container sh console

hci0:   Type: Primary  Bus: USB
        BD Address: 8C:88:4B:65:EA:6B  ACL MTU: 1021:6  SCO MTU: 255:12
        UP RUNNING 
        RX bytes:1620 acl:0 sco:0 events:176 errors:0
        TX bytes:32913 acl:0 sco:0 commands:176 errors:0

And my docker-compose file looks like this:

version: "1"

services:
  theengsgateway:
    image: theengs/gateway
    restart: unless-stopped
    network_mode: "host"
    environment:
      - MQTT_HOST=XXX.XXX.XXX.XXX
      - MQTT_USERNAME=XXXXXXXXX
      - MQTT_PASSWORD=XXXXXXXXX
      - PUBLISH_ALL=true
      - TIME_BETWEEN=60
      - SCAN_TIME=60
      - HASS_DISCOVERY=true
      - DISCOVERY=true
      - SCANNING_MODE=active
      - ADAPTER=hci0
    volumes:
      - theengsgateway:/theengsgateway
      - /var/run/dbus:/var/run/dbus

volumes:
  theengsgateway:

Can you try with the following capabilities added to your theengsgateway service?

    cap_add:
      - NET_ADMIN
      - SYS_ADMIN

The switchbot bot can be controlled by OpenMQTTGateway but not by Theengs gateway for now

Thanks you, but on the theengs gateway the bot is listed as compatible

The listed data can be read (mode, state, battery) but the bot cannot be controlled for now.

New release v1.2.0 !

What’s Changed

On top of numerous new devices supported, this version brings exciting features like the support of encrypted advertisements, the capability to resolve private BLE addresses, HA MQTT discovery tuning, and TLS/Websockets support. Let’s dive in!

New devices

Devices Model Measurements
April Brother N07 temperature/humidity/battery/packet ID
BM6 Battery Monitor BM6 battery
GOVEE H5100 temperature/humidity/battery
GOVEE H5104 temperature/humidity/battery
GOVEE H5179 temperature/humidity/battery
INKBIRD IBS-TH12S temperature/humidity/battery
NUT NUTALE tracker
Oral B Toothbrush state, mode, sector, pressure, time
Lippert BottleCheck temperature/level/sync status/voltage/battery/reading quality/acceleration x/y-axis
ShellyBlu Button1 button press type/battery/packet ID
ShellyBlu Door/Window contact/rotation/battery/packet ID
ShellyBlu Motion motion, illuminance, battery, packet ID
ThermoPro TP357s temperature/humidity

New features

Miscelleanous

Documentation

CI

New Contributors

Full Changelog: v1.1.0…v1.2.0

1 Like

[1.3.0]

What’s Changed

This release is focused on presence detection. We can now detect the presence and absence of trackers devices like TILE, NUT, BlueCharm (and other models identified here, the gateway will publish an offline message after tracker_timeout (120s per default) to set your controller to “Away” status. Added to this, Apple Watch, iPhone, and iPad can be used for presence detection with the usage of their IRK. And of course numerous other enhancements detailed below, thanks @DigiH and @koenvervloesem !

New devices

Devices Model Measurements
ClearGrass/Qingping CGP23W temperature, humidity, atmospheric pressure, battery
Aranet4 CO₂ Monitor temperature, humidity, pressure, carbon dioxide, battery
Switchbot Curtain model 3 moving, position, light level, battery, calibration state

New features

Miscelleanous

Documentation

CI

Full Changelog: Comparing v1.2.0...v1.3.0 ¡ theengs/gateway ¡ GitHub