Bluetooth MQTT gateway for eq3 thermostat / xiaomi scale /

Hi

I’ve created small bluetooth <-> mqtt gateway which im using on raspberry pi zero w to get bluetooth status updates / control thermostats that are out of reach from the server that hosts HA. It’s probaly also useful when run on the same computer as HA, because its doing sequential status update / commands to devices, making bluetooth status updates more reliable. I’m not a python programmer so its probably not best python code, but it works stable for me. Maybe someone finds it usefull. There is also support for mysensors configured as serial gateway.

https://github.com/zewelor/bt-mqtt-gateway

3 Likes

Hi, thanks for the code. I have a bluetooth scale (not xiaomi), would it be difficult to implement?

If there is some library for it, it should be pretty simple. Just copy xiami worker ( https://github.com/zewelor/bt-mqtt-gateway/blob/master/workers/miscale.py ) and change https://github.com/zewelor/bt-mqtt-gateway/blob/master/workers/miscale.py#L17 function to return weight value. Also you can remove whole “class ScanProcessor():”, unless it is using same idea to broadcast weight as xiaomi scale.

I got this up and running with my EQ3 Bluetooth Thermostats. It’s already been up for a few weeks with no issues. Perhaps when I find some time I will try to implement BT Beacon support.

its Yunmai (excellent hardware)

I found this, but a bit complicated for me

I see your BT-MQTT bridge is very special for your devices. You may want to have a look at the generic Bridge I wrote: https://github.com/seidler2547/ble-mqtt-bridge

I plan to extend it with GUID support, but it already has support for listening to broadcasts (beacons) and also for all read+write operations over BT LE.

I have been using this for more than a year with my Comet Blue thermostats: https://github.com/seidler2547/home-assistant-cc

Thanks for sharing this. I’m not familiar with BT protocols - do you think the Xiaomi Bluetooth Thermostat will work with the BT-MQTT bridge? Or perhaps natively through the eq3btsmart component (can’t tell if this is a brand, proprietary format, open standard, etc.)?

I’d like to add simple, battery-powered physical thermostats that sync/control my HASS virtual thermostats regulating each room (via a combination of window openings, fans, space heaters, duct fans & closures, etc). Certainly not worth buying 3-4 nest/ecobees for this purpose, and I’m considering picking up a handful of basic z-wave thermostats in the $30-$50 range. At ~$15, the Xiaomi platform sounds enticing, but only if it can be integrated (locally, that is).

Hi

Without adding support for it, it won’t work. I don’t know that device so not sure how it communicates. EQ3 is name of other thermostat and they are using different protocol for sure.

Thanks @Michal_Ciemiega. I picked one up from China for $12 that will arrive in 2-3 weeks and will try configuring it with a BT-MQTT bridge. At that price it’s worth a shot…

Is an full blown mqtt server needed ? I got my EQ3 connected via mqtt and I can see the status,
but I can’ controll it (on/off/set temperature).

Thanks

Not sure what do you mean by full blown mqtt server. I’m using mosquitto. Try to read all messages to see if topic matches etc.

1 Like

Sorry Im using the embedded mqtt broker from ha.
I meant if it is mandatory to use mosquito to get everything work.

I think it should work with embedded mqtt broker. Don’t see any reason why not.

Hi, tried your script but it exits with an error:

Setting LWT to: hostname/lwt_topic
Traceback (most recent call last):
  File "./gateway.py", line 32, in <module>
    manager.register_workers(settings['manager']).start(mqtt)
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 39, in register_workers
    module_obj = importlib.import_module("workers.%s" % worker_name)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/pi/bt-mqtt-gateway/workers/mithermometer.py", line 3, in <module>
    from workers.base import BaseWorker
  File "/home/pi/bt-mqtt-gateway/workers/base.py", line 11
    return '/'.join([self.topic_prefix, *args])
                                           ^
SyntaxError: can use starred expression only as assignment target

Running it on a Pi Zero W

Hi

Minimum supported python version is 3.5 ( https://github.com/zewelor/bt-mqtt-gateway#prerequisites ). Upgrade python and try again.

How is it possible to integrate Yunmai into HassOS?

@Michal_Ciemiega I am struggling to install yaml for raspbian can you help me with correct install for raspbian?

[email protected]:~/bt-mqtt-gateway $ ./gateway.py
Traceback (most recent call last):
  File "./gateway.py", line 9, in <module>
    import logger
  File "/home/pi/bt-mqtt-gateway/logger.py", line 3, in <module>
    import yaml
ImportError: No module named 'yaml'

I tried this but no luck

pip3 install pyYaml

Install libs from requirements.txt , as stated in readme:

sudo pip3 install -r requirements.txt

It should install correct version of pyyaml and other required libs. What do you mean by no luck after doing install pyYaml ? Maybe you got pyyaml installed via apt-get ? Or something is wrong with pythonpath settings ?

I did and requirements are met

[email protected]:~/bt-mqtt-gateway $ sudo pip3 install -r requirements.txt
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: paho-mqtt in /usr/local/lib/python3.5/dist-packag                                            es (from -r requirements.txt (line 1)) (1.4.0)
Requirement already satisfied: pyyaml in /usr/local/lib/python3.5/dist-packages                                             (from -r requirements.txt (line 2)) (5.1)
Requirement already satisfied: interruptingcow in /usr/local/lib/python3.5/dist-                                            packages (from -r requirements.txt (line 3)) (0.8)
Requirement already satisfied: apscheduler in /usr/local/lib/python3.5/dist-pack                                            ages (from -r requirements.txt (line 4)) (3.6.0)
Requirement already satisfied: six>=1.4.0 in /usr/lib/python3/dist-packages (fro                                            m apscheduler->-r requirements.txt (line 4)) (1.12.0)
Requirement already satisfied: tzlocal>=1.2 in /usr/local/lib/python3.5/dist-pac                                            kages (from apscheduler->-r requirements.txt (line 4)) (1.5.1)
Requirement already satisfied: pytz in /usr/local/lib/python3.5/dist-packages (f                                            rom apscheduler->-r requirements.txt (line 4)) (2019.1)
Requirement already satisfied: setuptools>=0.7 in /usr/local/lib/python3.5/dist-                                            packages (from apscheduler->-r requirements.txt (line 4)) (41.0.1)
[email protected]:~/bt-mqtt-gateway $ sudo nano config.yaml
[email protected]:~/bt-mqtt-gateway $ ./gateway.py
Traceback (most recent call last):
  File "./gateway.py", line 9, in <module>
    import logger
  File "/home/pi/bt-mqtt-gateway/logger.py", line 3, in <module>
    import yaml
ImportError: No module named 'yaml'