Giter Club home page Giter Club logo

bt-mqtt-gateway's People

Contributors

4383 avatar andrey-yantsen avatar bbbenji avatar byackee avatar cybe avatar diplix avatar dmirecki avatar elviosebastianelli avatar gingerlime avatar hobbypunk90 avatar ignacio-mov avatar jumping2000 avatar koenvervloesem avatar krasnoukhov avatar lsiudut avatar lucboudreau avatar lwestenberg avatar merll avatar missingdll avatar mklooss avatar nonninz avatar philmd avatar powerscrypt avatar ronytomen avatar shane-kerr avatar techhummel avatar tothi avatar unconfigured avatar yoda-x avatar zewelor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bt-mqtt-gateway's Issues

do thermostats show up as thermostats in hass

Hi,

this looks very promising but before I drop the money on a few rpi-zeros to connect my eq3bt thermostats to home-assistant via this gateway I would like to ask whether the thermostats do show up as climate components in hass?

change port?

Hello

This is the only program that works for me with the Mi Flora but the problem is, how can I define a different port in bt-mqtt-gateway please?

Cheers
Mark

pi@raspberrypi:~/bt-mqtt-gateway $ sudo systemctl status bt-mqtt-gateway error

I try ble mqtt gateway pi zero w and Amlogic TV box with armbian.
I receive same error.
./gateway.py -d works
I see data:
[{'payload': 21.6, 'topic': 'mithermometer/living_room/temperature'}, {'payload': 54.4, 'topic': 'mithermometer/living_room/humidi ty'}, {'payload': 69, 'topic': 'mithermometer/living_room/battery'}]

but when I check bt-mqtt-gateway status a see error:
pi@raspberrypi:~/bt-mqtt-gateway $ sudo systemctl status bt-mqtt-gateway
● bt-mqtt-gateway.service - Bluetooth MQTT gateway
Loaded: loaded (/etc/systemd/system/bt-mqtt-gateway.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-01-25 11:49:57 CET; 3h 34min ago
Docs: https://github.com/zewelor/bt-mqtt-gateway
Main PID: 421 (python3)
CGroup: /system.slice/bt-mqtt-gateway.service
└─421 python3 /home/pi/bt-mqtt-gateway/gateway.py

jan 25 15:01:03 raspberrypi gateway.py[421]: ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
jan 25 15:01:03 raspberrypi gateway.py[421]: File "/usr/local/lib/python3.5/dist-packages/mithermometer/mithermometer_poller.py", line 136, in param
jan 25 15:01:03 raspberrypi gateway.py[421]: self.fill_cache()
jan 25 15:01:03 raspberrypi gateway.py[421]: File "/usr/local/lib/python3.5/dist-packages/mithermometer/mithermometer_poller.py", line 67, in fill_c
jan 25 15:01:03 raspberrypi gateway.py[421]: with self._bt_interface.connect(self._mac) as connection:
jan 25 15:01:03 raspberrypi gateway.py[421]: File "/usr/local/lib/python3.5/dist-packages/btlewrap/base.py", line 44, in enter
jan 25 15:01:03 raspberrypi gateway.py[421]: self._backend.connect(self._mac)
jan 25 15:01:03 raspberrypi gateway.py[421]: File "/usr/local/lib/python3.5/dist-packages/btlewrap/bluepy.py", line 32, in _func_wrapper
jan 25 15:01:03 raspberrypi gateway.py[421]: raise BluetoothBackendException() from last_error
jan 25 15:01:03 raspberrypi gateway.py[421]: btlewrap.base.BluetoothBackendException
pi@raspberrypi:~/bt-mqtt-gateway $

And I do not see qttt data in nodered

How cna I solve this error?

miFlora error on start

When I add miflora to the config file i got an error on start

my config.yaml

miflora:
  args:
    devices:
      herbs: C4:7C:8D:64:3B:73
    topic_prefix: miflora
  update_interval: 300

sudo ./gateway.py -d

Starting
Added: miscale with 1800 seconds interval
Traceback (most recent call last):
File "./gateway.py", line 30, in
manager.register_workers(settings['manager']).start(mqtt)
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in register_workers
module_obj = importlib.import_module("workers.%s" % worker_name)
File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 673, in exec_module
File "", line 222, in _call_with_frames_removed
File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 5, in
from miflora.miflora_poller import MiFloraPoller,
ImportError: No module named 'miflora'

MQTT to Home Assistant breaks every approx 24 hours

After approx. 24 hours bt-mqtt-gateway messages do not make it over to Home Assistant any more. I do not see any errors in the bt-mqtt-gateway service status and a simple restart resolves the issue. It is annoying though. I am using MQTT on the Home Assistant side, which functions fine (other devices are using it). My source for the bt-mqtt-gateway is a miflora sensor that has not moved.... can I help debug somehow?

MiScale 2 time out error

Hi,

is the Xiaomi miscale 2 supported (the version with body fat measurements)??

I have one of them here and I only get the following error when starting the gateway in debug mode:

pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2019-06-02 23:15:01,611 INFO bt-mqtt-gw gateway.py:39:<module> - Starting
2019-06-02 23:15:01,618 DEBUG bt-mqtt-gw.mqtt mqtt.py:21:__init__ - Setting LWT to: bt2mqtt/LWT
2019-06-02 23:15:02,087 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:59:register_workers - Added miscale worker with 150 seconds interval and a 35 seconds timeout
2019-06-02 23:15:03,640 DEBUG bt-mqtt-gw.mqtt mqtt.py:76:callbacks_subscription - Subscribing to: bt2mqtt/miscale/update_interval
2019-06-02 23:15:03,646 DEBUG bt-mqtt-gw.mqtt mqtt.py:76:callbacks_subscription - Subscribing to: bt2mqtt/homeassistant/status
2019-06-02 23:15:03,671 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:106:update_all - Updating all workers
2019-06-02 23:15:14,081 ERROR bt-mqtt-gw logger.py:48:log_exception - Retrieving the weight from miscale device C8:A1:20:20:91:43 timed out after 5 seconds
Traceback (most recent call last):
  File "./gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 18, in status_update
    return [MqttMessage(topic=self.format_topic('weight/kg'), payload=self._get_weight())]
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 29, in _get_weight
    time.sleep(1)
  File "/usr/local/lib/python3.5/dist-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Retrieving the weight from miscale device C8:A1:20:20:91:43 timed out after 5 seconds
2019-06-02 23:17:43,702 ERROR bt-mqtt-gw logger.py:48:log_exception - Retrieving the weight from miscale device C8:A1:20:20:91:43 timed out after 5 seconds
Traceback (most recent call last):
  File "./gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 18, in status_update
    return [MqttMessage(topic=self.format_topic('weight/kg'), payload=self._get_weight())]
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 29, in _get_weight
    time.sleep(1)
  File "/usr/local/lib/python3.5/dist-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Retrieving the weight from miscale device C8:A1:20:20:91:43 timed out after 5 seconds
2019-06-02 23:20:13,718 ERROR bt-mqtt-gw logger.py:48:log_exception - Retrieving the weight from miscale device C8:A1:20:20:91:43 timed out after 5 seconds
Traceback (most recent call last):
  File "./gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 18, in status_update
    return [MqttMessage(topic=self.format_topic('weight/kg'), payload=self._get_weight())]
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 29, in _get_weight
    time.sleep(1)
  File "/usr/local/lib/python3.5/dist-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Retrieving the weight from miscale device C8:A1:20:20:91:43 timed out after 5 seconds

The connection to the mqtt host work, I get the LWT message.

The mac adress of the scale is correctly set up in the worker, i double checked.

The scale has never been connected to a MiFit App on any phone, if that makes a difference.

Running on a raspberry pi zero w
Linux raspberrypi 4.14.79+ #1159 Sun Nov 4 17:28:08 GMT 2018 armv6l GNU/Linux

error on gateway.py

Hi,
I have this error on raspberry Pi Zero W with last Raspbian Strech Lite, is there a way to solve it?
thanks

./gateway.py
Traceback (most recent call last):
  File "./gateway.py", line 15, in <module>
    from workers_manager import WorkersManager
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 4, in <module>
    from pip._internal import main as pip_main
ImportError: No module named 'pip._internal'

[Solved] Miscale profile

Hello, thank you this antenna ble.
I come from Jeedom where there is the same antenna. [https://github.com/jeedom/plugin-blea/tree/beta/resources/blead/devices]

Do you have the option to add profiles for the scale so that it detects the user.

For example, I weigh 69Kg, my son 40Kg and my wife 60Kg. So according to the weight one comes to inform an input_boolean according to the person who weighs himself. It exists on this page ([https://github.com/jeedom/plugin-blea/blob/beta/resources/blead/devices/miscale.py]) but it is too complex for me.

Multiple MiFlora issue

Hello, it works with only one sensor, but when i add the 2nd sensor i have a issue.
This is my config:

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:
miflora:
args:
devices:
gelsomino: C4:7C:8D:6B:0C:4B
sansevieriamini: C4:7C:8D:6B:1E:88
topic_prefix: miflora
update_interval: 300

and this is a error:

pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2019-09-10 14:49:22,329 INFO bt-mqtt-gw gateway.py:61: - Starting
2019-09-10 14:49:22,336 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:init - Setting LWT to: lwt_topic
2019-09-10 14:49:26,956 INFO bt-mqtt-gw.workers.miflora miflora.py:19:_setup - Adding 2 miflora devices
2019-09-10 14:49:26,959 DEBUG bt-mqtt-gw.workers.miflora miflora.py:21:_setup - Adding miflora device 'gelsomino' (C4:7C:8D:6B:0C:4B)
2019-09-10 14:49:26,963 DEBUG bt-mqtt-gw.workers.miflora miflora.py:21:_setup - Adding miflora device 'sansevieriamini' (C4:7C:8D:6B:1E:88)
2019-09-10 14:49:26,967 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:93:register_workers - Added miflora config with a 2 seconds timeout
2019-09-10 14:49:26,970 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:103:register_workers - Added miflora worker with 300 seconds interval and a 35 seconds timeout
2019-09-10 14:49:27,003 DEBUG bt-mqtt-gw.mqtt mqtt.py:116:callbacks_subscription - Subscribing to: miflora/update_interval
2019-09-10 14:49:27,007 DEBUG bt-mqtt-gw.mqtt mqtt.py:116:callbacks_subscription - Subscribing to: homeassistant/status
2019-09-10 14:49:27,026 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:64:execute - Execution result of command MifloraWorker.config: [{'topic': 'sensor/C4-7C-8D-6B-0C-4B/miflora_gelsomino_temperature/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino_temperature", "state_topic": "miflora/gelsomino/temperature", "name": "miflora_gelsomino_temperature", "device": {"identifiers": ["C4:7C:8D:6B:0C:4B", "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_gelsomino"}, "device_class": "temperature", "unit_of_measurement": "\u00b0C"}'}, {'topic': 'sensor/C4-7C-8D-6B-0C-4B/miflora_gelsomino_moisture/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino_moisture", "state_topic": "miflora/gelsomino/moisture", "name": "miflora_gelsomino_moisture", "device": {"identifiers": ["C4:7C:8D:6B:0C:4B", "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_gelsomino"}, "icon": "mdi:water", "unit_of_measurement": "%"}'}, {'topic': 'sensor/C4-7C-8D-6B-0C-4B/miflora_gelsomino_light/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino_illuminance", "state_topic": "miflora/gelsomino/light", "name": "miflora_gelsomino_light", "device": {"identifiers": ["C4:7C:8D:6B:0C:4B", "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_gelsomino"}, "device_class": "illuminance", "unit_of_measurement": "lux"}'}, {'topic': 'sensor/C4-7C-8D-6B-0C-4B/miflora_gelsomino_conductivity/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino_conductivity", "state_topic": "miflora/gelsomino/conductivity", "name": "miflora_gelsomino_conductivity", "device": {"identifiers": ["C4:7C:8D:6B:0C:4B", "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_gelsomino"}, "icon": "mdi:leaf", "unit_of_measurement": "\u00b5S/cm"}'}, {'topic': 'sensor/C4-7C-8D-6B-0C-4B/miflora_gelsomino_battery/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino_battery", "state_topic": "miflora/gelsomino/battery", "name": "miflora_gelsomino_battery", "device": {"identifiers": ["C4:7C:8D:6B:0C:4B", "bt-mqtt-gateway/C4-7C-8D-6B-0C-4B/miflora_gelsomino"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_gelsomino"}, "device_class": "battery", "unit_of_measurement": "%"}'}, {'topic': 'sensor/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_temperature/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_temperature", "state_topic": "miflora/sansevieriamini/temperature", "name": "miflora_sansevieriamini_temperature", "device": {"identifiers": ["C4:7C:8D:6B:1E:88", "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_sansevieriamini"}, "device_class": "temperature", "unit_of_measurement": "\u00b0C"}'}, {'topic': 'sensor/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_moisture/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_moisture", "state_topic": "miflora/sansevieriamini/moisture", "name": "miflora_sansevieriamini_moisture", "device": {"identifiers": ["C4:7C:8D:6B:1E:88", "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_sansevieriamini"}, "icon": "mdi:water", "unit_of_measurement": "%"}'}, {'topic': 'sensor/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_light/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_illuminance", "state_topic": "miflora/sansevieriamini/light", "name": "miflora_sansevieriamini_light", "device": {"identifiers": ["C4:7C:8D:6B:1E:88", "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_sansevieriamini"}, "device_class": "illuminance", "unit_of_measurement": "lux"}'}, {'topic': 'sensor/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_conductivity/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_conductivity", "state_topic": "miflora/sansevieriamini/conductivity", "name": "miflora_sansevieriamini_conductivity", "device": {"identifiers": ["C4:7C:8D:6B:1E:88", "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_sansevieriamini"}, "icon": "mdi:leaf", "unit_of_measurement": "\u00b5S/cm"}'}, {'topic': 'sensor/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_battery/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini_battery", "state_topic": "miflora/sansevieriamini/battery", "name": "miflora_sansevieriamini_battery", "device": {"identifiers": ["C4:7C:8D:6B:1E:88", "bt-mqtt-gateway/C4-7C-8D-6B-1E-88/miflora_sansevieriamini"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_sansevieriamini"}, "device_class": "battery", "unit_of_measurement": "%"}'}]
2019-09-10 14:49:27,071 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:171:update_all - Updating all workers
2019-09-10 14:49:27,075 INFO bt-mqtt-gw.workers.miflora miflora.py:80:status_update - Updating 2 miflora devices
2019-09-10 14:49:27,077 DEBUG bt-mqtt-gw.workers.miflora miflora.py:85:status_update - Updating miflora device 'gelsomino' (C4:7C:8D:6B:0C:4B)
2019-09-10 14:49:33,083 ERROR bt-mqtt-gw.workers.miflora logger.py:50:log_exception - Time out during update of miflora device 'gelsomino' (C4:7C:8D:6B:0C:4B)
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 89, in status_update
yield self.update_device_state(name, data["poller"])
File "/usr/local/lib/python3.7/dist-packages/interruptingcow/init.py", line 153, in inner
return func(*args, **kwargs)
File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 118, in update_device_state
payload=poller.parameter_value(attr),
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 132, in parameter_value
self.fill_cache()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 61, in fill_cache
firmware_version = self.firmware_version()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 103, in firmware_version
with self._bt_interface.connect(self._mac) as connection:
File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 44, in enter
self._backend.connect(self._mac)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 26, in _func_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 55, in connect
self._peripheral = Peripheral(mac, iface=iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 391, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 436, in _connect
rsp = self._getResp('stat')
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 347, in _waitResp
rv = self._helper.stdout.readline()
File "/usr/local/lib/python3.7/dist-packages/interruptingcow/init.py", line 74, in handler
raise exception
exceptions.DeviceTimeoutError
2019-09-10 14:49:33,151 DEBUG bt-mqtt-gw.workers.miflora miflora.py:85:status_update - Updating miflora device 'sansevieriamini' (C4:7C:8D:6B:1E:88)
2019-09-10 14:49:39,157 ERROR bt-mqtt-gw.workers.miflora logger.py:50:log_exception - Time out during update of miflora device 'sansevieriamini' (C4:7C:8D:6B:1E:88)
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 89, in status_update
yield self.update_device_state(name, data["poller"])
File "/usr/local/lib/python3.7/dist-packages/interruptingcow/init.py", line 153, in inner
return func(*args, **kwargs)
File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 118, in update_device_state
payload=poller.parameter_value(attr),
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 132, in parameter_value
self.fill_cache()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 61, in fill_cache
firmware_version = self.firmware_version()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 103, in firmware_version
with self._bt_interface.connect(self._mac) as connection:
File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 44, in enter
self._backend.connect(self._mac)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 26, in _func_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 55, in connect
self._peripheral = Peripheral(mac, iface=iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 391, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 436, in _connect
rsp = self._getResp('stat')
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 347, in _waitResp
rv = self._helper.stdout.readline()
File "/usr/local/lib/python3.7/dist-packages/interruptingcow/init.py", line 74, in handler
raise exception
exceptions.DeviceTimeoutError
2019-09-10 14:49:39,187 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:64:execute - Execution result of command MifloraWorker.status_update: []

Host dont report state offline in hassio

Hy
Happy New Year
we have talk about the state of host for hassio and i change how you told me and i have this in bt-mqtt-gateway:

mqtt: host: 192.168.x.xx port: 1883 username: xxxx password: xxxx topic_prefix: hostname client_id: bt-mqtt-gateway availability_topic: lwt_topic

manager: topic_subscription: update_all: topic: homeassistant/status payload: online workers: miflora: args: devices: salonplant: xx:xx:xx:xx:xx:xx topic_prefix: miflora update_interval: 300

mithermometer: args: devices: salon: xx:xx:xx:xx:xx:xx cocina: xx:xx:xx:xx:xx:xx topic_prefix: mithermometer update_interval: 120

and in hassio i have:
mqtt: broker: 192.168.x.xx username: xxxxxx password: xxxxxx birth_message: topic: 'homeassistant/status' payload: 'online' discovery: true discovery_prefix: homeassistant

sensor.yaml:
`- platform: mqtt
state_topic: "hostname/mithermometer/salon/temperature"
name: "Salon Temperatura"
unit_of_measurement: "°C"
icon_template: mdi:thermometer
availability_topic: "hostname/lwt_topic"
payload_available: "online"
payload_not_available: "offline"

  • platform: mqtt
    state_topic: "hostname/mithermometer/salon/humidity"
    name: "Salon Humidity"
    unit_of_measurement: "%"
    icon_template: mdi:water
    availability_topic: "hostname/lwt_topic"
    payload_available: "online"
    payload_not_available: "offline"

  • platform: mqtt
    state_topic: "hostname/mithermometer/salon/battery"
    name: "Salon Battery"
    unit_of_measurement: "%"
    availability_topic: "hostname/lwt_topic"
    payload_available: "online"
    payload_not_available: "offline"`

I was change availability_topic: "hostname/lwt_topic"(and he work fine but when i shutdown the host i dont receive in hassio the state offline) with availability_topic: "hostname/lwt_topic/status"(dont work), and availability_topic: "lwt_topic/" dont work, availability_topic: "lwt_topic" .(dont work it means that the state the host in hassio is unavailable).

I check my mqtt and when i start bt-mqtt-gateway i see "hostname/lwt_topic online" and when i shutdown the host i se in mqtt "lwt topic offline" whitout "hostname".

I was try with ( payload_available: "hostname/lwt_topic") and (payload_not_available: "lwt topic") and is work but unchange state when i shutdown the host.

I think that i can make a automacion with mqtt publish but before i want to ask you if can check out again the mqtt.py program. I think that something happened in this program.
It will better if i made fresh install of mt-bt-gateway because i only change config.yaml and i just copy the new mqtt.py over the old mqtt.py and i restarted.

thanks a lot

App crashes on regular basis on Raspberry PI 4

Hi,
I'm trying to use app but it stops working in random time interval with following error:

17:10:51 Updating 3 mithermometer devices
17:11:01 Fatal error while executing worker command: RuntimeError
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 44, in __enter__
    self._backend.connect(self._mac)
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 26, in _func_wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 55, in connect
    self._peripheral = Peripheral(mac, iface=iface)
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 391, in __init__
    self._connect(deviceAddr, addrType, iface)
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 436, in _connect
    rsp = self._getResp('stat')
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 347, in _waitResp
    rv = self._helper.stdout.readline()
  File "/usr/local/lib/python3.7/dist-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
exceptions.DeviceTimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./gateway.py", line 91, in <module>
    raise e
  File "./gateway.py", line 73, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/spock/bt-mqtt-gateway/workers_manager.py", line 52, in execute
    for message in self._callback(*self._args):
  File "/home/spock/bt-mqtt-gateway/workers/mithermometer.py", line 76, in status_update
    yield self.update_device_state(name, data["poller"])
  File "/usr/local/lib/python3.7/dist-packages/interruptingcow/__init__.py", line 153, in inner
    return func(*args, **kwargs)
  File "/home/spock/bt-mqtt-gateway/workers/mithermometer.py", line 105, in update_device_state
    payload=poller.parameter_value(attr),
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 136, in parameter_value
    self.fill_cache()
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 60, in fill_cache
    self.firmware_version()
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 109, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 47, in __enter__
    self._lock.release()
RuntimeError: release unlocked lock

With one Mi Flora timout error not sending MQTT update for any other device

I have four Mi Flora device currently configured. When one of them is out of reach and BT connection timeouts the whole status_update process is stopped and no MQTT update is sent for any device.

I think it should rather execute each device independent of each other, then send normal updates for devices that can be connected and error report for any disconnected device.

Running on Raspberry Pi Zero W with Raspbian Stretch Lite

2019-08-24 09:00:16,345 INFO bt-mqtt-gw.workers.miflora miflora.py:76:status_update - Updating 4 miflora devices
2019-08-24 09:00:16,349 DEBUG bt-mqtt-gw.workers.miflora miflora.py:79:status_update - Updating miflora device 'avocado' (C4:7C:8D:6B:27:9F)
2019-08-24 09:00:20,231 DEBUG bt-mqtt-gw.workers.miflora miflora.py:79:status_update - Updating miflora device 'sansevieria_lower' (C4:7C:8D:6B:23:D3)
2019-08-24 09:00:29,330 DEBUG bt-mqtt-gw.workers.miflora miflora.py:79:status_update - Updating miflora device 'sansevieria_upper' (C4:7C:8D:6B:18:DC)
2019-08-24 09:00:39,860 DEBUG bt-mqtt-gw.workers.miflora miflora.py:79:status_update - Updating miflora device 'zamioculcas' (C4:7C:8D:6B:27:94)
2019-08-24 09:00:51,347 ERROR bt-mqtt-gw logger.py:48:log_exception - Execution of command MifloraWorker.status_update timed out after 35 seconds
Traceback (most recent call last):
  File "gateway.py", line 51, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 82, in status_update
    ret += self.update_device_state(name, data["poller"])
  File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 91, in update_device_state
    ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/miflora/miflora_poller.py", line 132, in parameter_value
    self.fill_cache()
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/miflora/miflora_poller.py", line 61, in fill_cache
    firmware_version = self.firmware_version()
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/miflora/miflora_poller.py", line 103, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/btlewrap/base.py", line 44, in __enter__
    self._backend.connect(self._mac)
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/btlewrap/bluepy.py", line 26, in _func_wrapper
    return func(*args, **kwargs)
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/btlewrap/bluepy.py", line 55, in connect
    self._peripheral = Peripheral(mac, iface=iface)
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/bluepy/btle.py", line 391, in __init__
    self._connect(deviceAddr, addrType, iface)
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/bluepy/btle.py", line 436, in _connect
    rsp = self._getResp('stat')
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/bluepy/btle.py", line 347, in _waitResp
    rv = self._helper.stdout.readline()
  File "/home/pi/bt-mqtt-gateway/.venv/lib/python3.5/site-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Execution of command MifloraWorker.status_update timed out after 35 seconds

Example configuration for homeassistant

Would it be possible to get a basic configuration for climate & miflora components for homeassistant, e.g. how to let homeassistant autodiscover the sensors?

EQ3 thermostat

have installed acording to manual on Zero W to control eq3 thermostat.

Installed pip3 install python-eq3bt

The MQTT topics updated only once when start the program
When run ./gateway -d gives the following error

DEBUG bt-mqtt-gw.workers.thermostat thermostat.py:227:status_update - Updating thermostat device 'bedroom' (00:AE:A9:E5:68:C7)
2019-11-23 13:57:43,751 ERROR bt-mqtt-gw.workers.thermostat logger.py:50:log_exception - Error during update of thermostat device 'bedroom' (00:AE:A9:E5:68:C7): BTLEGattError
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/thermostat.py", line 230, in status_update
thermostat.update()
File "/usr/local/lib/python3.7/dist-packages/eq3bt/eq3btsmart.py", line 205, in update
self._conn.make_request(PROP_WRITE_HANDLE, value)
File "/usr/local/lib/python3.7/dist-packages/eq3bt/connection.py", line 73, in make_request
self._conn.writeCharacteristic(handle, value, withResponse=with_response)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 543, in writeCharacteristic
return self._getResp('wr')
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 368, in _waitResp
raise BTLEGattError("Bluetooth command failed", resp)
bluepy.btle.BTLEGattError: Bluetooth command failed (code: 1, error: Invalid handle)

[blescanmulti] Add battery info for BLE beacons

I'm testing this with an iTag beacon...
Could the battery info be read from the device and published to mqtt?
The battery services is with uuid 0000180f-0000-1000-8000-00805f9b34fb.
Here's an example from command line when reading from the tag:

$ sudo gatttool -I
[                 ][LE]> connect ff:ff:3d:11:47:b7
Attempting to connect to ff:ff:3d:11:47:b7
Connection successful
[ff:ff:3d:11:47:b7][LE]> primary
attr handle: 0x0001, end grp handle: 0x0005 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0006, end grp handle: 0x0008 uuid: 0000180f-0000-1000-8000-00805f9b34fb
attr handle: 0x0009, end grp handle: 0x000b uuid: 00001802-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0x000e uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
[ff:ff:3d:11:47:b7][LE]> characteristics 0x0001
handle: 0x0002, char properties: 0x12, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0007, char properties: 0x12, char value handle: 0x0008, uuid: 00002a19-0000-1000-8000-00805f9b34fb
handle: 0x000a, char properties: 0x1c, char value handle: 0x000b, uuid: 00002a06-0000-1000-8000-00805f9b34fb
handle: 0x000d, char properties: 0x12, char value handle: 0x000e, uuid: 0000ffe1-0000-1000-8000-00805f9b34fb
[ff:ff:3d:11:47:b7][LE]> characteristics 0x0006 0x0008
handle: 0x0007, char properties: 0x12, char value handle: 0x0008, uuid: 00002a19-0000-1000-8000-00805f9b34fb
[ff:ff:3d:11:47:b7][LE]> char-read-hnd 0x0008
Characteristic value/descriptor: 63
[ff:ff:3d:11:47:b7][LE]>

The value 63 is in hexadecimal.
Thanks.

Tootbrush mac ?

hello how can I find the mac address of the toothbrush?
when i send command sudo hcitool lescan find miflora sensors and many unknown devices

New worker, Search for BT LE tag

New idea.
Add new worker to search specific BT LE tag mac address and send it via mqtt as presence detection HOME/AWAY.

Now i use room-assistant on RPi0W with home assistant.
It send a lot information about BLE TAG (i have cheap iTAG).
For presence we need only a is a specific mac in range.
For not flooding mqtt broker it will check is any change and change is send to broker.

BTLEDisconnectError & BluetoothBackEndExeption

Hi

i have used bt-mqtt-gateway for some month, no problems there but since 1 or 2 weeks i receive some errors.

Today i updated to the new version + update bluez to 5.50

Config:

mqtt:
host: 192.168.178.2
port: 1883
username: bt-mqtt
password: *****
client_id: bt-mqtt-gateway

manager:
workers:
thermostat:
args:
devices:
schlafzimmer: 00:1A:22:10:FC:3D
badezimmer: 00:1A:22:11:1D:75
wohnzimmer1: 00:1A:22:11:15:3F
wohnzimmer2: 00:1A:22:10:DE:29
wohnzimmer3: 00:1A:22:11:02:76
hobbyraum: 00:1A:22:11:1D:CA
topic_prefix: heizung
topic_subscription: heizung/+/+/set
update_interval: 60
miflora:
args:
devices:
ebene2: C4:7C:8D:67:40:89
ebene1: C4:7C:8D:67:5A:51
topic_prefix: miflora
update_interval: 60

pi@rpi:~/bt-mqtt-gateway $ sudo ./gateway.py
20:34:53 Starting
20:34:53 Adding 6 thermostat devices
20:34:54 Adding 2 miflora devices
20:34:54 Updating 6 thermostat devices
20:34:54 Error during update of thermostat device 'schlafzimmer' (00:1A:22:10:FC:3D): BTLEDisconnectError
20:34:54 Error during update of thermostat device 'hobbyraum' (00:1A:22:11:1D:CA): BTLEDisconnectError
20:34:54 Error during update of thermostat device 'wohnzimmer1' (00:1A:22:11:15:3F): BTLEDisconnectError
20:34:54 Error during update of thermostat device 'badezimmer' (00:1A:22:11:1D:75): BTLEDisconnectError
20:34:54 Error during update of thermostat device 'wohnzimmer2' (00:1A:22:10:DE:29): BTLEDisconnectError
20:34:54 Error during update of thermostat device 'wohnzimmer3' (00:1A:22:11:02:76): BTLEDisconnectError
20:34:54 Updating 2 miflora devices
20:34:55 Error during update of miflora device 'ebene1' (C4:7C:8D:67:5A:51): BluetoothBackendException
20:34:55 Error during update of miflora device 'ebene2' (C4:7C:8D:67:40:89): BluetoothBackendException
20:34:55 Setting target_temperature to 22.0 on thermostat device 'wohnzimmer2' (00:1A:22:10:DE:29)
20:34:55 Error setting target_temperature to 22.0 on thermostat device 'wohnzimmer2' (00:1A:22:10:DE:29): BTLEDisconnectError
20:34:55 Setting target_temperature to 22.0 on thermostat device 'wohnzimmer3' (00:1A:22:11:02:76)
20:34:55 Error setting target_temperature to 22.0 on thermostat device 'wohnzimmer3' (00:1A:22:11:02:76): BTLEDisconnectError
20:34:55 Setting target_temperature to 23.0 on thermostat device 'badezimmer' (00:1A:22:11:1D:75)
20:34:56 Error setting target_temperature to 23.0 on thermostat device 'badezimmer' (00:1A:22:11:1D:75): BTLEDisconnectError
20:34:56 Setting target_temperature to 22.0 on thermostat device 'wohnzimmer1' (00:1A:22:11:15:3F)
20:34:56 Error setting target_temperature to 22.0 on thermostat device 'wohnzimmer1' (00:1A:22:11:15:3F): BTLEDisconnectError
20:34:56 Setting target_temperature to 22.0 on thermostat device 'hobbyraum' (00:1A:22:11:1D:CA)
20:34:56 Error setting target_temperature to 22.0 on thermostat device 'hobbyraum' (00:1A:22:11:1D:CA): BTLEDisconnectError
20:34:56 Setting target_temperature to 4.5 on thermostat device 'schlafzimmer' (00:1A:22:10:FC:3D)
20:34:56 Error setting target_temperature to 4.5 on thermostat device 'schlafzimmer' (00:1A:22:10:FC:3D): BTLEDisconnectError

sending commands to thermostat

hi,
sorry for the dumb question...

i use 4 eq3 thermostats and want to control them via mqtt
now im curiouse about how to send commands over mqtt to the thermostat.
in the config.yaml is topic_subscription: thermostat/+/+/set and i tryed a lot of commands but nothing worked and i cant find description to this topic.

Whats wrong here?
Thanks in advanced

bluepy.btle.BTLEDisconnectError: Device disconnected

Hi

Trying to get this running on a Pi Zero W i keep getting this error Device disconnected.

I can see the device when I run hcitool lescan however the first time i used it i got a "Set scan parameters failed: Input/output error" error and had to run the below to get it working

sudo hciconfig hci0 down sudo hciconfig hci0 up

log from sudo ./gateway.py -d, i sent "ON" to "bt-mqtt-gateway/switchbot/kitchen/light/set"
2019-09-14 10:22:46,873 INFO bt-mqtt-gw gateway.py:61:<module> - Starting 2019-09-14 10:22:46,880 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: bt-mqtt-gateway/lwt_topic 2019-09-14 10:22:47,351 INFO bt-mqtt-gw.workers.switchbot switchbot.py:19:_setup - Adding 1 switchbot devices 2019-09-14 10:22:47,354 INFO bt-mqtt-gw.workers.switchbot switchbot.py:21:_setup - Adding switchbot device 'light' (D3:A7:92:AA:6D:B3) 2019-09-14 10:22:47,357 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:103:register_workers - Added switchbot worker with 60 seconds interval and a 35 seconds timeout 2019-09-14 10:22:51,670 DEBUG bt-mqtt-gw.mqtt mqtt.py:116:callbacks_subscription - Subscribing to: bt-mqtt-gateway/switchbot/kitchen/update_interval 2019-09-14 10:22:51,679 DEBUG bt-mqtt-gw.mqtt mqtt.py:116:callbacks_subscription - Subscribing to: bt-mqtt-gateway/switchbot/+/+/set 2019-09-14 10:22:51,687 DEBUG bt-mqtt-gw.mqtt mqtt.py:116:callbacks_subscription - Subscribing to: bt-mqtt-gateway/homeassistant/status 2019-09-14 10:22:51,717 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:171:update_all - Updating all workers 2019-09-14 10:22:52,103 DEBUG bt-mqtt-gw.workers.switchbot switchbot.py:31:status_update - Updating 1 switchbot devices 2019-09-14 10:22:52,106 DEBUG bt-mqtt-gw.workers.switchbot switchbot.py:33:status_update - Updating switchbot device 'light' (D3:A7:92:AA:6D:B3) 2019-09-14 10:22:52,109 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:64:execute - Execution result of command SwitchbotWorker.status_update: [{'payload': 'OFF', 'topic': 'switchbot/kitchen/light'}] 2019-09-14 10:23:24,535 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:203:_on_command_wrapper - Received command for switchbot on bt-mqtt-gateway/switchbot/kitchen/light/set: b'ON' 2019-09-14 10:23:24,544 DEBUG bt-mqtt-gw.workers.switchbot switchbot.py:66:on_command - Setting ON on switchbot device 'light' (D3:A7:92:AA:6D:B3) 2019-09-14 10:23:25,464 ERROR bt-mqtt-gw.workers.switchbot logger.py:50:log_exception - Error setting ON on switchbot device 'light' (D3:A7:92:AA:6D:B3): BTLEDisconnectError Traceback (most recent call last): File "/home/pi/bt-mqtt-gateway/workers/switchbot.py", line 74, in on_command "cba20002-224d-11e6-9fb8-0002a5d5c51b" File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 144, in getCharacteristics self.chars = [] if self.hndEnd <= self.hndStart else self.peripheral.getCharacteristics(self.hndStart, self.hndEnd) File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 508, in getCharacteristics rsp = self._getResp('find') File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 407, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 362, in _waitResp raise BTLEDisconnectError("Device disconnected", resp) bluepy.btle.BTLEDisconnectError: Device disconnected 2019-09-14 10:23:25,510 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:64:execute - Execution result of command SwitchbotWorker.on_command: []

Config.yaml:

mqtt:
  host: 192.168.1.253
  port: 1883
  username: mqtt
  password: MyPassword
  #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: bt-mqtt-gateway         # 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:
    switchbot:
      args:
        devices:
          light: D3:A7:92:AA:6D:B3
        topic_prefix: switchbot/kitchen
        state_topic_prefix: switchbot/kitchen
      topic_subscription: switchbot/+/+/set
      update_interval: 60

Anyone got anyway idea why isnt this isnt working?

Regards

Matt

Subscribing to command topics seems broken

Hello,

I'm having difficulties sending commands to a thermostat, perhaps similar to #33. The topic subscription succeeds, but the callback is never executed.

I enabled debug logging for mqtt via self.mqttc.enable_logger(logger=_LOGGER) in mqtt.py. These are my observations:

  1. The mqtt client reconnects to the mqtt server right after each update interval, thereby replacing the previous connection:
# ./gateway.py -d
Starting
Added: thermostat with 20 seconds interval
Subscribing to: thermostat/+/+/set
Sending CONNECT (u1, p1, wr0, wq0, wf0, c0, k60) client_id=b'bt-mqtt-gateway-ham'
Sending SUBSCRIBE (d0, m1) [(b'bmg-ham/thermostat/+/+/set', 0)]
Received CONNACK (1, 0)
Received SUBACK
Updating all workers
[{'topic': 'thermostat/wohnen/low_battery', 'payload': False}, {'topic': 'thermostat/wohnen/valve_state', 'payload': 13}, {'topic': 'thermostat/wohnen/target_temperature', 'payload': 21.0}, {'topic': 'thermostat/wohnen/window_open', 'payload': False}, {'topic': 'thermostat/wohnen/locked', 'payload': False}, {'topic': 'thermostat/wohnen/mode', 'payload': 'manual'}, {'topic': 'thermostat/wohnen/away', 'payload': 'off'}]
Sending CONNECT (u1, p1, wr0, wq0, wf0, c0, k60) client_id=b'bt-mqtt-gateway-ham'
Received CONNACK (0, 0)

This corresponds with the logfiles from mosquitto. On these reconnects, the subscriptions are not renewed. This behavior seems to be incorrect, as there should't be made any new connections. Mosquitto log:

1544870901: New connection from 172.19.0.1 on port 1883.
1544870901: Socket error on client bt-mqtt-gateway, disconnecting.
1544870901: New client connected from 172.19.0.1 as bt-mqtt-gateway (c0, k60, u'bt-mqtt-gateway').
1544870904: New connection from 172.19.0.1 on port 1883.
1544870904: Client bt-mqtt-gateway already connected, closing old connection.
1544870904: Socket error on client bt-mqtt-gateway, disconnecting.
1544870904: New client connected from 172.19.0.1 as bt-mqtt-gateway (c1, k60, u'bt-mqtt-gateway').
1544870904: Client bt-mqtt-gateway disconnected.
1544870905: New connection from 172.19.0.1 on port 1883.
1544870905: New client connected from 172.19.0.1 as bt-mqtt-gateway (c0, k60, u'bt-mqtt-gateway').
  1. If I replace self.mqttc.loop_start() in mqtt.py with self.mqttc.loop_forever() the callbacks are processed:
# ./gateway.py -d
Starting
Added: thermostat with 20 seconds interval
Subscribing to: thermostat/+/+/set
Sending CONNECT (u1, p1, wr0, wq0, wf0, c0, k60) client_id=b'bt-mqtt-gateway-ham'
Sending SUBSCRIBE (d0, m1) [(b'bmg-ham/thermostat/+/+/set', 0)]
Received CONNACK (1, 0)
Received SUBACK
Received PUBLISH (d0, q0, r0, m0), 'bmg-ham/thermostat/wohnen/target_temperature/set', ...  (4 bytes)
on command wrapper for with bmg-ham/thermostat/wohnen/target_temperature/set: b'20.0'

However, as self.mqttc.loop_forever() is a blocking call, the scheduled worker updates aren't running.

For reference, this is my config:

mqtt:
  host: ***
  port: 1883
  username: bt-mqtt-gateway
  password: ***
  topic_prefix: bmg-ham
  client_id: bt-mqtt-gateway-ham

manager:
  workers:
    thermostat:
      args:
        devices:
          wohnen: 00:11:22:33:44:55
        topic_prefix: thermostat
      topic_subscription: thermostat/+/+/set
      update_interval: 20

Bluepy missing from requirements

Describe the bug
I installed bt-mqtt-gateway on a freshly installed Raspbian (latest release). When trying to launch the daemon, it complains about bluepy missing...
Installing it using sudo pip3 install bluepyworks :-)

Error

pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2019-06-26 19:38:04,114 INFO bt-mqtt-gw gateway.py:39:<module> - Starting
2019-06-26 19:38:04,120 DEBUG bt-mqtt-gw.mqtt mqtt.py:23:__init__ - Setting LWT to: router/lwt_topic
2019-06-26 19:38:12,025 INFO bt-mqtt-gw.workers.mithermometer mithermometer.py:18:_setup - Adding 1 mithermometer devices
2019-06-26 19:38:12,028 DEBUG bt-mqtt-gw.workers.mithermometer mithermometer.py:20:_setup - Adding mithermometer device 'living_room' (58:2D:34:10:40:D0)
2019-06-26 19:38:12,038 ERROR btlewrap.bluepy bluepy.py:101:check_backend - bluepy not found: No module named 'bluepy'
2019-06-26 19:38:12,043 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:60:register_workers - Added mithermometer config with a 2 seconds timeout
2019-06-26 19:38:12,045 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:65:register_workers - Added mithermometer worker with 300 seconds interval and a 35 seconds timeout
2019-06-26 19:38:12,075 DEBUG bt-mqtt-gw.mqtt mqtt.py:77:callbacks_subscription - Subscribing to: router/mithermometer/update_interval
2019-06-26 19:38:12,080 DEBUG bt-mqtt-gw.mqtt mqtt.py:77:callbacks_subscription - Subscribing to: router/homeassistant/status
2019-06-26 19:38:12,090 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:36:execute - Execution result of command MithermometerWorker.config: [{'topic': 'sensor/mithermometer_living_room_temperature/config', 'payload': '{"unique_id": "bt-mqtt-gateway_mithermometer_living_room_temperature", "state_topic": "mithermometer/living_room/temperature", "device_class": "temperature", "device": {"identifiers": ["58:2D:34:10:40:D0", "bt-mqtt-gateway_mithermometer_living_room"], "manufacturer": "Xiaomi", "model": "LYWSD(CGQ/01ZM)", "name": "Mithermometer Living_Room"}, "name": "mithermometer_living_room_temperature"}'}, {'topic': 'sensor/mithermometer_living_room_humidity/config', 'payload': '{"unique_id": "bt-mqtt-gateway_mithermometer_living_room_humidity", "state_topic": "mithermometer/living_room/humidity", "device_class": "humidity", "device": {"identifiers": ["58:2D:34:10:40:D0", "bt-mqtt-gateway_mithermometer_living_room"], "manufacturer": "Xiaomi", "model": "LYWSD(CGQ/01ZM)", "name": "Mithermometer Living_Room"}, "name": "mithermometer_living_room_humidity"}'}, {'topic': 'sensor/mithermometer_living_room_battery/config', 'payload': '{"unique_id": "bt-mqtt-gateway_mithermometer_living_room_battery", "state_topic": "mithermometer/living_room/battery", "device_class": "battery", "device": {"identifiers": ["58:2D:34:10:40:D0", "bt-mqtt-gateway_mithermometer_living_room"], "manufacturer": "Xiaomi", "model": "LYWSD(CGQ/01ZM)", "name": "Mithermometer Living_Room"}, "name": "mithermometer_living_room_battery"}'}]
2019-06-26 19:38:12,117 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:116:update_all - Updating all workers
2019-06-26 19:38:12,120 INFO bt-mqtt-gw.workers.mithermometer mithermometer.py:39:status_update - Updating 1 mithermometer devices
2019-06-26 19:38:12,122 DEBUG bt-mqtt-gw.workers.mithermometer mithermometer.py:42:status_update - Updating mithermometer device 'living_room' (58:2D:34:10:40:D0)
2019-06-26 19:38:12,132 ERROR bt-mqtt-gw logger.py:48:log_exception - Fatal error while executing worker command: ModuleNotFoundError
Traceback (most recent call last):
  File "./gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/mithermometer.py", line 45, in status_update
    ret += self.update_device_state(name, data["poller"])
  File "/home/pi/bt-mqtt-gateway/workers/mithermometer.py", line 54, in update_device_state
    ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 136, in parameter_value
    self.fill_cache()
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 60, in fill_cache
    self.firmware_version()
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 109, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 44, in __enter__
    self._backend.connect(self._mac)
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 48, in connect
    from bluepy.btle import Peripheral
ModuleNotFoundError: No module named 'bluepy'
Traceback (most recent call last):
  File "./gateway.py", line 59, in <module>
    raise e
  File "./gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/mithermometer.py", line 45, in status_update
    ret += self.update_device_state(name, data["poller"])
  File "/home/pi/bt-mqtt-gateway/workers/mithermometer.py", line 54, in update_device_state
    ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 136, in parameter_value
    self.fill_cache()
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 60, in fill_cache
    self.firmware_version()
  File "/usr/local/lib/python3.7/dist-packages/mithermometer/mithermometer_poller.py", line 109, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 44, in __enter__
    self._backend.connect(self._mac)
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 48, in connect
    from bluepy.btle import Peripheral
ModuleNotFoundError: No module named 'bluepy'

Server (please complete the following information):

  • OS: [Linux]
  • Distro: [Raspbian]
  • Version [June 2019]

Trying to add Xiaomi BLE Temperature and Humidity sensor

So I am pretty new at this stuff but I was really interested in the project. I tried really hard to figure this out on my own without bothering you first. I bought one of these so I could monitor my back room temperature: https://www.home-assistant.io/components/mitemp_bt/.

The problem is the Pi I run Home Assistant on doesn't have the bluetooth range to read it from the back room. I tested it at short range and it works great. I found a few people say they are using this project to get around that. I bought a Pi zero and started to work on implementing this project.

Here are the issues I have. When I run the ./gateway.py command I get this as the reply:

18:36:35 Starting
18:36:48 Adding 1 mithermometer devices
Traceback (most recent call last):
File "./gateway.py", line 43, in
manager.register_workers().start(mqtt)
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 101, in start
mqtt.callbacks_subscription(self._mqtt_callbacks)
File "/home/pi/bt-mqtt-gateway/mqtt.py", line 73, in callbacks_subscription
self.mqttc.connect(self.hostname, port=self.port)
File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 962, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python3.5/socket.py", line 712, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 703, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

I am not really sure what to do to get around that. Things I am not really clear on as well:

host: 192.168.1.1 <-- Is this local host or where the messages will be accepted
port: 1883 <-- do I use this port for home assistant?
username: user <-- Is this username to connect to home assistant or local host
password: password <-- same as username concerns

I commented out user name and password for now as I wasn't sure.

I am also not sure if I am supposed to use mithermometer: or blescanmulti: to capture this data I've tried both with no success. I see the correct MAC from the Pi when running sudo hcitool lescan. Any ideas? Here is my current config:

host: x.x.x.x #home assistant IP
port: 1883
#username: user
#password: password
topic_prefix: bkrmmqqt # 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:
# mysensors:
# command_timeout: 35 # Optional override of globally set command_timeout.
# args:
# port: /dev/ttyUSB0
# baudrate: 9600
# topic_prefix: mysensors/out
# thermostat:
# args:
# devices:
# bedroom: 00:11:22:33:44:55
# topic_prefix: thermostat
# topic_subscription: thermostat/+/+/set
# update_interval: 60
# miscale:
# args:
# mac: 00:11:22:33:44:55
# topic_prefix: miscale
# update_interval: 1800
# linakdesk:
# args:
# mac: 00:11:22:33:44:55
# topic_prefix: linak_desk
# update_interval: 1800
# miflora:
# args:
# devices:
# herbs: 00:11:22:33:44:55
# topic_prefix: miflora
# update_interval: 300
mithermometer:
args:
devices:
back_room: XX:XX:XX:XX:XX:XX <-- ommited MAC of Thermometer
topic_prefix: mithermometer
update_interval: 300
# blescanmulti:
# args:
# devices:
# mlethermometer : XX:XX:XX:XX:XX:XX <-- ommited MAC of Thermometer
# smartwath: 00:11:22:33:44:55
# topic_prefix: blescan
# available_payload: home
# unavailable_payload: not_home
# available_timeout: 0
# unavailable_timeout: 60
# scan_timeout: 10
# scan_passive: true
# update_interval: 60
# toothbrush:
# args:
# devices:
# ix: 00:11:22:33:44:55
# ia: 11:22:33:44:55:66
# topic_prefix: toothbrush
# update_interval: 10
# toothbrush_homeassistant:
# args:
# autodiscovery_prefix: homeassistant
# topic_prefix: toothbrush
# devices:
# ix:
# name: IX
# mac: 00:11:22:33:44:55
# ia:
# name: IA
# mac: 11:22:33:44:55:66
# update_interval: 10
# switchbot:
# args:
# devices:
# heater: 00:11:22:33:44:55
# topic_prefix: switchbot/bathroom
# state_topic_prefix: switchbot/bathroom
# topic_subscription: switchbot/+/+/set
# update_interval: 60

Here is what the code looks like in home assistant:

#MQTT
mqtt:
broker: !secret mqtt_broker_ip
birth_message:
topic: 'homeassistant/status'
payload: 'online'

Any Ideas? I have reimaged this SD card a few times thinking I just messed up installing bluez or bluepy but everything seems fine as far as I can tell. I have also tried making the host the local address but no dice there either.

error on start

When I try to start with sudo ./gateway.py

I get this error:

Traceback (most recent call last):
File "./gateway.py", line 13, in
from config import settings
File "/home/pi/bt-mqtt-gateway/config.py", line 1, in
import yaml
ImportError: No module named 'yaml'

Docker: multiarch build

Is your feature request related to a problem? Please describe.

the generated docker image runs only on amd64 systems.

Describe the solution you'd like
we need a build for aarch64 and armv7 to support raspberry pis.

Additional context
i never tried multiarch builds, but i'll read through and try to create it "soon"😅

How can i now when hostname is offline

Buenas noche. primero queria mucho agradecerlo para el grande proyecto y me gustaria preguntarle si el host se apaga como puedo saber lo en homeassitant. gracias

key error when thermostat not found in config

I get my logs flooded by bt-mqtt when I have MQTT messages referring to thermostats that do not exist in workers config.

Because I cannot cover my whole flat with one gateway I have two gateways, each handling different areas/thermostats.

I would expect that bt-mqtt handles this gracefully and just ignores keys which are not found in the config.

● bt-mqtt-gateway.service - Bluetooth MQTT gateway
   Loaded: loaded (/etc/systemd/system/bt-mqtt-gateway.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-02-26 04:00:01 UTC; 13h ago
     Docs: https://github.com/zewelor/bt-mqtt-gateway
 Main PID: 9973 (python3)
   CGroup: /system.slice/bt-mqtt-gateway.service
           └─9973 /usr/bin/python3 /home/pi/bt-mqtt-gateway/gateway.py

Feb 26 17:22:35 kitchentunes python3[9973]: KeyError: 'BedroomL'
Feb 26 17:22:35 kitchentunes python3[9973]: 'BedroomL'
Feb 26 17:22:35 kitchentunes python3[9973]: Traceback (most recent call last):
Feb 26 17:22:35 kitchentunes python3[9973]:   File "/home/pi/bt-mqtt-gateway/gateway.py", line 37, in <module>
Feb 26 17:22:35 kitchentunes python3[9973]:     mqtt.publish(_WORKERS_QUEUE.get(block=True).execute())
Feb 26 17:22:35 kitchentunes python3[9973]:   File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 26, in execute
Feb 26 17:22:35 kitchentunes python3[9973]:     messages = self._callback(*self._args)
Feb 26 17:22:35 kitchentunes python3[9973]:   File "/home/pi/bt-mqtt-gateway/workers/thermostat.py", line 78, in on_command
Feb 26 17:22:35 kitchentunes python3[9973]:     thermostat = self.devices[device_name]
Feb 26 17:22:35 kitchentunes python3[9973]: KeyError: 'BedroomL'

__init__() takes 2 positional arguments but 3 were given

I've just tried installing on a RPi 3B+ running Ubuntu Server 18.04.3 from here. Following the instructions for installation of bt-mqtt-gateway, I encounter the issue shown below:

(.venv) ubuntu@ubuntu:~/bt-mqtt-gateway$ sudo ./gateway.py -d
2019-10-16 10:27:29,252 INFO bt-mqtt-gw gateway.py:61: - Starting
2019-10-16 10:27:29,254 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:init - Setting LWT to: lwt_topic
2019-10-16 10:27:29,592 INFO bt-mqtt-gw.workers.miflora miflora.py:23:_setup - Adding 11 miflora devices
2019-10-16 10:27:29,592 DEBUG bt-mqtt-gw.workers.miflora miflora.py:25:_setup - Adding miflora device 'rosemary' (C4:7C:8D:66:2F:D0)
Traceback (most recent call last):
File "./gateway.py", line 67, in
manager.register_workers(global_topic_prefix).start(mqtt)
File "/home/ubuntu/bt-mqtt-gateway/workers_manager.py", line 88, in register_workers
command_timeout, global_topic_prefix, **worker_config["args"]
File "/home/ubuntu/bt-mqtt-gateway/workers/base.py", line 7, in init
self._setup()
File "/home/ubuntu/bt-mqtt-gateway/workers/miflora.py", line 28, in _setup
"poller": MiFloraPoller(mac, BluepyBackend),
File "/usr/local/lib/python3.6/dist-packages/miflora/miflora_poller.py", line 37, in init
self._bt_interface = BluetoothInterface(backend, adapter)
TypeError: init() takes 2 positional arguments but 3 were given

My config is the same as what I had running and working on an Intel NUC running Ubuntu server, so it shouldn't be an issue with my config:

mqtt:
  host: 192.168.1.135
  port: 1883
  username: username
  password: password
  #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 certi$
  #topic_prefix: homeassistant         # 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 suff$
  workers:
    miflora:
     args:
       devices:
         rosemary: C4:7C:8D:66:2F:D0
         oregano: C4:7C:8D:66:35:6B
         mint: C4:7C:8D:66:2E:97
         thyme: C4:7C:8D:6A:15:29
         curry: C4:7C:8D:6A:A3:B3
         perennial_basil: C4:7C:8D:66:2D:79
         sweet_basil_and_habanero_orange_chilli: C4:7C:8D:66:36:D2
         asian_siam_yellow_chilli: C4:7C:8D:6A:09:2D
         tabasco_red_chilli: C4:7C:8D:6A:05:27
         garlic_chives: C4:7C:8D:6B:26:75
         happy_plant: C4:7C:8D:6A:8E:0E
       topic_prefix: miflora
     update_interval: 60

Not sure what has gone wrong, please help!

socket error on client xxxx disconnecting with btmqttgateway and MIFLORA

bt-mqtt-gateway - > raspberry pi zero w
mosquitto 5.0 - > HASSIO 0.97.2

I have this error in the log of mosquitto:

1565967282: New client connected from 192.168.2.129 as bt-mqtt-gateway (p2, c0, k60, u'mqtt_user').
1565967283: Socket error on client bt-mqtt-gateway, disconnecting.
1565967310: New connection from 192.168.2.129 on port 1883.
1565967310: New client connected from 192.168.2.129 as bt-mqtt-gateway (p2, c0, k60, u'mqtt_user').
1565967311: Socket error on client bt-mqtt-gateway, disconnecting.
1565967338: New connection from 192.168.2.129 on port 1883.
1565967338: New client connected from 192.168.2.129 as bt-mqtt-gateway (p2, c0, k60, u'mqtt_user').
1565967339: Socket error on client bt-mqtt-gateway, disconnecting.
1565967366: New connection from 192.168.2.129 on port 1883.
1565967366: New client connected from 192.168.2.129 as bt-mqtt-gateway (p2, c0, k60, u'mqtt_user').
1565967367: Socket error on client bt-mqtt-gateway, disconnecting.

user e pw are ok
if run manually with ./gateway.py -d

pi@raspberrypi:~/bt-mqtt-gateway $ ./gateway.py -d
2019-08-13 20:44:48,206 INFO bt-mqtt-gw gateway.py:39: – Starting
2019-08-13 20:44:48,213 DEBUG bt-mqtt-gw.mqtt mqtt.py:28:init – Setting LWT to: btgateway/lwt_topic
2019-08-13 20:44:56,349 INFO bt-mqtt-gw.workers.miflora miflora.py:16:_setup – Adding 1 miflora devices
2019-08-13 20:44:56,352 DEBUG bt-mqtt-gw.workers.miflora miflora.py:18:_setup – Adding miflora device ‘herbs’ (C4:7C:8D:6A:5C:90)
2019-08-13 20:44:56,355 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:60:register_workers – Added miflora config with a 2 seconds timeout
2019-08-13 20:44:56,363 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:65:register_workers – Added miflora worker with 300 seconds interval and a 60 seconds timeout
2019-08-13 20:44:56,420 DEBUG bt-mqtt-gw.mqtt mqtt.py:97:callbacks_subscription – Subscribing to: btgateway/miflora/update_interval
2019-08-13 20:44:56,429 DEBUG bt-mqtt-gw.mqtt mqtt.py:97:callbacks_subscription – Subscribing to: btgateway/homeassistant/status
2019-08-13 20:44:56,460 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:36:execute – Execution result of command MifloraWorker.config: [{‘topic’: ‘sensor/C4-7C-8D-6A-5C-90/miflora_herbs_temperature/config’, ‘payload’: ‘{“unique_id”: “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs_temperature”, “state_topic”: “miflora/herbs/temperature”, “name”: “miflora_herbs_temperature”, “device”: {“identifiers”: [“C4:7C:8D:6A:5C:90”, “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs”], “manufacturer”: “Xiaomi”, “model”: “MiFlora”, “name”: “miflora_herbs”}, “device_class”: “temperature”, “unit_of_measurement”: “\u00b0C”}’}, {‘topic’: ‘sensor/C4-7C-8D-6A-5C-90/miflora_herbs_moisture/config’, ‘payload’: ‘{“unique_id”: “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs_moisture”, “state_topic”: “miflora/herbs/moisture”, “name”: “miflora_herbs_moisture”, “device”: {“identifiers”: [“C4:7C:8D:6A:5C:90”, “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs”], “manufacturer”: “Xiaomi”, “model”: “MiFlora”, “name”: “miflora_herbs”}, “icon”: “mdi:water”, “unit_of_measurement”: “%”}’}, {‘topic’: ‘sensor/C4-7C-8D-6A-5C-90/miflora_herbs_light/config’, ‘payload’: ‘{“unique_id”: “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs_illuminance”, “state_topic”: “miflora/herbs/light”, “name”: “miflora_herbs_light”, “device”: {“identifiers”: [“C4:7C:8D:6A:5C:90”, “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs”], “manufacturer”: “Xiaomi”, “model”: “MiFlora”, “name”: “miflora_herbs”}, “device_class”: “illuminance”, “unit_of_measurement”: “lux”}’}, {‘topic’: ‘sensor/C4-7C-8D-6A-5C-90/miflora_herbs_conductivity/config’, ‘payload’: ‘{“unique_id”: “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs_conductivity”, “state_topic”: “miflora/herbs/conductivity”, “name”: “miflora_herbs_conductivity”, “device”: {“identifiers”: [“C4:7C:8D:6A:5C:90”, “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs”], “manufacturer”: “Xiaomi”, “model”: “MiFlora”, “name”: “miflora_herbs”}, “icon”: “mdi:leaf”, “unit_of_measurement”: “\u00b5S/cm”}’}, {‘topic’: ‘sensor/C4-7C-8D-6A-5C-90/miflora_herbs_battery/config’, ‘payload’: ‘{“unique_id”: “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs_battery”, “state_topic”: “miflora/herbs/battery”, “name”: “miflora_herbs_battery”, “device”: {“identifiers”: [“C4:7C:8D:6A:5C:90”, “bt-mqtt-gateway/C4-7C-8D-6A-5C-90/miflora_herbs”], “manufacturer”: “Xiaomi”, “model”: “MiFlora”, “name”: “miflora_herbs”}, “device_class”: “battery”, “unit_of_measurement”: “%”}’}]
2019-08-13 20:44:56,522 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:116:update_all – Updating all workers
2019-08-13 20:44:56,530 INFO bt-mqtt-gw.workers.miflora miflora.py:76:status_update – Updating 1 miflora devices
2019-08-13 20:44:56,535 DEBUG bt-mqtt-gw.workers.miflora miflora.py:79:status_update – Updating miflora device ‘herbs’ (C4:7C:8D:6A:5C:90)
2019-08-13 20:44:58,222 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:36:execute – Execution result of command MifloraWorker.status_update: [{‘topic’: ‘miflora/herbs/temperature’, ‘payload’: 31.5}, {‘topic’: ‘miflora/herbs/moisture’, ‘payload’: 61}, {‘topic’: ‘miflora/herbs/light’, ‘payload’: 22}, {‘topic’: ‘miflora/herbs/conductivity’, ‘payload’: 375}, {‘topic’: ‘miflora/herbs/battery’, ‘payload’: 100}]

and the sensor are ok
Schermata 2019-08-16 alle 17 05 36

but the log of mosquitto show this error:

1565968007: New connection from 192.168.2.129 on port 1883.
1565968007: Client bt-mqtt-gateway already connected, closing old connection.
1565968007: New client connected from 192.168.2.129 as bt-mqtt-gateway (p2, c0, k60, u'mqtt_user').
1565968007: Socket error on client bt-mqtt-gateway, disconnecting.
1565968008: New connection from 192.168.2.129 on port 1883.
1565968008: New client connected from 192.168.2.129 as bt-mqtt-gateway (p2, c0, k60, u'mqtt_user').
1565968034: New connection from 192.168.2.129 on port 1883.
1565968034: Client bt-mqtt-gateway already connected, closing old connection.
1565968034: New client connected from 192.168.2.129 as bt-mqtt-gateway (p2, c0, k60, u'mqtt_user').

hci0 needs occasioanal reset

from time to time bt-mqtt-gateway produces errors because the bluetooth interface on my rpi3 gets unresponsive.

Failed to execute management command 'scanend' (code: 11, error: Rejected)
Traceback (most recent call last):
  File "bt-mqtt-gateway/gateway.py", line 39, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(block=True).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 27, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/toothbrush.py", line 28, in status_update
    devices = scanner.scan(5.0)
  File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 852, in scan
    self.start(passive=passive)
  File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 797, in start
    self._mgmtCmd(self._cmd()+"end")
  File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 312, in _mgmtCmd
    raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 11, error: Rejected)

resetting the interface helps:
sudo hciconfig hci0 reset

i made this into a cron job that runs 4 times a day and since have no problems.

anyone else experiencing related problems? if so, could reseting the bluetooth interface on a schedule be included into python code of bt-mqtt-gateway?

Bluetooth non-LE detection

Is your feature request related to a problem? Please describe.
I don't know all the bluetooth wording, so forgive me if I'm using the wrong descriptions for things.

I have several bluetooth LE devices that blescanmulti picks up perfectly. However, I have a few devices that don't do BLE broadcast/announcements. They are available in the "old" bluetooth manner, in the same way you'd connect to bluetooth speakers and such. And I would like to detect them.

Using bluetoothctl I can see them in a scan just fine. But, adding them to the blescanmulti config, they are never detected by bt-mqtt-gateway.

Is there already a feature to detect a device like this?

Describe the solution you'd like
To detect available "regular" bluetooth devices.

Describe alternatives you've considered
Running bt-mqtt-gateway to handle all the things it does, and running a separate gateway on another bluetooth device just to detect devices like this.

Additional context
In particular, a device I'm trying to detect is a One Plus 6T Mobile Phone.

Multithreading sensors instead of multithreading workers only

Is your feature request related to a problem? Please describe.
At this moment, bt-mqtt-gateway collects all data of any sensor and sends after collecting the data via mqtt and on a timeout error on one sensor the complete worker stops and no data are sended.

Describe the solution you'd like
With one worker per sensor instead of one worker for all sensors of a type, errors for single sensors don't mess up with other sensors.

Log
MiThermometer

2019-03-29 19:13:04,074 INFO bt-mqtt-gw.workers.mithermometer mithermometer.py:25:status_update - Updating 4 mithermometer devices
2019-03-29 19:13:04,078 DEBUG bt-mqtt-gw.workers.mithermometer mithermometer.py:28:status_update - Updating mithermometer device 'bath' (4C:65:A8:D9:B7:4D)
2019-03-29 19:13:39,075 ERROR bt-mqtt-gw logger.py:48:log_exception - Execution of command MithermometerWorker.status_update timed out after 35 seconds
Traceback (most recent call last):
  File "gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/alarm/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/alarm/bt-mqtt-gateway/workers/mithermometer.py", line 30, in status_update
    ret += self.update_device_state(name, poller)
  File "/home/alarm/bt-mqtt-gateway/workers/mithermometer.py", line 39, in update_device_state
    ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
  File "/usr/lib/python3.7/site-packages/mithermometer/mithermometer_poller.py", line 136, in parameter_value
    self.fill_cache()
  File "/usr/lib/python3.7/site-packages/mithermometer/mithermometer_poller.py", line 60, in fill_cache
    self.firmware_version()
  File "/usr/lib/python3.7/site-packages/mithermometer/mithermometer_poller.py", line 109, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/usr/lib/python3.7/site-packages/btlewrap/base.py", line 42, in __enter__
    self._lock.acquire()
  File "/usr/lib/python3.7/site-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Execution of command MithermometerWorker.status_update timed out after 35 seconds
2019-03-29 19:13:55,929 INFO bt-mqtt-gw.workers.thermostat thermostat.py:74:status_update - Updating 2 thermostat devices

MiFlora

2019-03-29 19:24:26,703 INFO bt-mqtt-gw.workers.miflora miflora.py:25:status_update - Updating 10 miflora devices
2019-03-29 19:24:55,002 DEBUG bt-mqtt-gw.workers.miflora miflora.py:28:status_update - Updating miflora device 'diddy' (C4:7C:8D:66:4D:35)
2019-03-29 19:25:01,709 ERROR bt-mqtt-gw logger.py:48:log_exception - Execution of command MifloraWorker.status_update timed out after 35 seconds
Traceback (most recent call last):
  File "gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/alarm/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/alarm/bt-mqtt-gateway/workers/miflora.py", line 30, in status_update
    ret += self.update_device_state(name, poller)
  File "/home/alarm/bt-mqtt-gateway/workers/miflora.py", line 39, in update_device_state
    ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
  File "/usr/lib/python3.7/site-packages/miflora/miflora_poller.py", line 132, in parameter_value
    self.fill_cache()
  File "/usr/lib/python3.7/site-packages/miflora/miflora_poller.py", line 61, in fill_cache
    firmware_version = self.firmware_version()
  File "/usr/lib/python3.7/site-packages/miflora/miflora_poller.py", line 103, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/usr/lib/python3.7/site-packages/btlewrap/base.py", line 44, in __enter__
    self._backend.connect(self._mac)
  File "/usr/lib/python3.7/site-packages/btlewrap/bluepy.py", line 26, in _func_wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.7/site-packages/btlewrap/bluepy.py", line 55, in connect
    self._peripheral = Peripheral(mac, iface=iface)
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 361, in __init__
    self._connect(deviceAddr, addrType, iface)
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 406, in _connect
    rsp = self._getResp('stat')
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 377, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 319, in _waitResp
    rv = self._helper.stdout.readline()
  File "/usr/lib/python3.7/site-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Execution of command MifloraWorker.status_update timed out after 35 seconds
2019-03-29 19:25:01,762 INFO bt-mqtt-gw.workers.mithermometer mithermometer.py:25:status_update - Updating 4 mithermometer devices

use bt-mqtt-gateway with standard Raspbian Strech

hi,
some days ago I had some problems with the gateway, I will write here the solution suitable for me :

  • the bt-mqtt-gateway was developed with Python 3.6 and use Pip with version>10
  • Raspbian Stretch comes wit Python 3.5.3 and Pip 9.01
  • upgrade Python is not fast with Pi Zero
  • upgrade only pip with commands like " pip install --upgrade" is not recommended and takes lot of problems (see pypa/pip#5599)
    SOLUTION:
    I changed line 4 and 98 of workers_manager.py with this code:
  • (4) from pip import main
  • (98) main(['install', '-q', package])

now the bt-mqtt-gateway works well with my Pi Zero W with last DietPi distribution (based on Stretch).
Bye

thermostat.py error after using the last version

I have a lot of error on thermostat.py module after the last modification in the repository:

on command wrapper for with thermostat/salotto1/target_temperature/set: b'16.0'
not enough values to unpack (expected 4, got 3)
Traceback (most recent call last):
  File "./gateway.py", line 37, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(block=True).execute())
  File "/home/dietpi/bt-mqtt-gateway/workers_manager.py", line 26, in execute
    messages = self._callback(*self._args)
  File "/home/dietpi/bt-mqtt-gateway/workers/thermostat.py", line 75, in on_command
    _, device_name, method, _ = topic[len(self.topic_prefix+"/"):].split('/')
ValueError: not enough values to unpack (expected 4, got 3)
not enough values to unpack (expected 4, got 3)
Traceback (most recent call last):
  File "./gateway.py", line 37, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(block=True).execute())
  File "/home/dietpi/bt-mqtt-gateway/workers_manager.py", line 26, in execute
    messages = self._callback(*self._args)
  File "/home/dietpi/bt-mqtt-gateway/workers/thermostat.py", line 75, in on_command
    _, device_name, method, _ = topic[len(self.topic_prefix+"/"):].split('/')
ValueError: not enough values to unpack (expected 4, got 3)
on command wrapper for with thermostat/salotto2/target_temperature/set: b'16.0'
not enough values to unpack (expected 4, got 3)
Traceback (most recent call last):
  File "./gateway.py", line 37, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(block=True).execute())
  File "/home/dietpi/bt-mqtt-gateway/workers_manager.py", line 26, in execute
    messages = self._callback(*self._args)
  File "/home/dietpi/bt-mqtt-gateway/workers/thermostat.py", line 75, in on_command
    _, device_name, method, _ = topic[len(self.topic_prefix+"/"):].split('/')
ValueError: not enough values to unpack (expected 4, got 3)
not enough values to unpack (expected 4, got 3)
Traceback (most recent call last):
  File "./gateway.py", line 37, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(block=True).execute())
  File "/home/dietpi/bt-mqtt-gateway/workers_manager.py", line 26, in execute
    messages = self._callback(*self._args)
  File "/home/dietpi/bt-mqtt-gateway/workers/thermostat.py", line 75, in on_command
    _, device_name, method, _ = topic[len(self.topic_prefix+"/"):].split('/')
ValueError: not enough values to unpack (expected 4, got 3)

OralB history

Will be possible to pull history data from OralB toothbrush? Like it does in OralB app. Toothbrush saves cca 30 sessions.

Problem install Miflora

Now that I have fun with the nuts finder and the scale I try to install the miflora but it does not work.

Do you have an idea with my log errors?

i tested live miflora demo.py on another install no link problem

root@DietPi:/home/dietpi/bt-mqtt-gateway# ./gateway.py -d 2019-10-13 00:32:16,746 INFO bt-mqtt-gw gateway.py:61:<module> - Starting 2019-10-13 00:32:16,758 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: btgateway/lwt_topic 2019-10-13 00:32:18,072 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:103:register_workers - Added miscale worker with 300 seconds interval and a 35 seconds timeout 2019-10-13 00:32:24,824 INFO bt-mqtt-gw.workers.blescanmulti blescanmulti.py:109:__init__ - Adding 2 blescanmulti devices 2019-10-13 00:32:24,838 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:103:register_workers - Added blescanmulti worker with 60 seconds interval and a 35 seconds timeout 2019-10-13 00:32:28,373 INFO bt-mqtt-gw.workers.miflora miflora.py:23:_setup - Adding 1 miflora devices 2019-10-13 00:32:28,392 DEBUG bt-mqtt-gw.workers.miflora miflora.py:25:_setup - Adding miflora device 'anthurium_salon' (c4:7c:8d:6a:ca:fb) Traceback (most recent call last): File "./gateway.py", line 67, in <module> manager.register_workers(global_topic_prefix).start(mqtt) File "/home/dietpi/bt-mqtt-gateway/workers_manager.py", line 88, in register_workers command_timeout, global_topic_prefix, **worker_config["args"] File "/home/dietpi/bt-mqtt-gateway/workers/base.py", line 7, in __init__ self._setup() File "/home/dietpi/bt-mqtt-gateway/workers/miflora.py", line 28, in _setup "poller": MiFloraPoller(mac, BluepyBackend), File "/usr/local/lib/python3.5/dist-packages/miflora/miflora_poller.py", line 37, in __init__ self._bt_interface = BluetoothInterface(backend, adapter) TypeError: __init__() takes 2 positional arguments but 3 were given

mithermometer: Use of interruptingcow leads to deadlock

The use of the timeout mechanism in mithermometer.py and workers_manager.py can lead to a deadlock when a BTLE operation fails to complete within 8 or 35 seconds respectively: When the timeout fires, a currently ongoing operation is not cleaned up properly and leaves behind a lock. The next BTLE operation uses the same locking object and therefore lands in a deadlock. Furthermore, the timeout mechanism of interruptingcow is unable to kill the deadlocked operation. As a result, the whole worker hangs. This might be related to #14.

You can see the behavior in the attached logfile. I added a couple of custom log statements. In line 6 the backend fails to connect to the device within 8 seconds and kills the operation, resulting in the exception until line 63. Note that there are no messages about releasing the lock.

The next operation then tries to acquire the same lock in line 69. This is the deadlock. As mentioned, interruptingcow is also unable to interrupt the deadlocked acquire-method. Note that for my testings I manually set an upper limit to acquire the lock as seen on line 102. After the 100 seconds passed, the timeout of interruptingcow fired immediately.

I'm unsure how to tackle this. In the case of mithermometer.py just removing the use of interruptingcow seems to do the trick. If a device is unresponsive, an internal timeout of 10 seconds still applies. However, removing the timeout in workers_manager.py doesn't seem to be a good idea.

Ultimately, the best approach would be to determine why resource-cleanup fails when a timeout fires. I'm guessing the thread hangs somewhere internally in lock.acquire() and is therefore not able to reach any cleanup code.

Let me know if you need any more information.

Docker container fails because it can't find sudo and hciconfig

Describe the bug
When I build my own Docker image for bt-mqtt-gateway, it fails to start because it doesn't find the sudo and hciconfig commands.

To Reproduce

  1. docker build -t bt-mqtt-gateway -f Dockerfile
  2. Create config file.
  3. Run Docker container
  4. See error "/bin/sh: sudo: not found" in output of docker logs bt-mqtt-gateway.

Expected behavior
The container starts correctly.

Server (please complete the following information):

  • OS: Linux
  • Distro: Ubuntu
  • Version: 19.10

The same happens on Raspbian Buster Lite on a Raspberry Pi 3B+ when I build and run the arm32v7 container image.

Additional context
When I add sudo to the last apk add line in the Dockerfile and rebuild the image, the container again gives an error message, this time complaining that it can't find hciconfig.

When I add bluez-deprecated to the last apk addline, the rebuilt image works correctly.

No module named 'pip._internal' on startup

running on raspbian jessie, python 3.4

Traceback (most recent call last):
  File "gateway.py", line 15, in <module>
    from workers_manager import WorkersManager
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 4, in <module>
    from pip._internal import main as pip_main
ImportError: No module named 'pip._internal'

Empty values on restart of Homeassistant with current service file

Hello,

your gateway is awesome. I've only found one little issue. Whenever I reboot my system the linked MQTT-Sensors in Homeassistant remain empty for the duration of the specified update_intervall. It seems that bt-mqtt-gateeway is loaded before Mosquitto broker and Homeassistant are running. Maybe you could adjust the service file to start the gateway only if the broker and Homeassistant are running. I currently don't know how to do this. Maybe with Require=x or After=x?

2 bt-mqtt-gateways on same broker

Can the client name be configured? I have two fo the bt-mqtt-gateways on the same broker and it seems to cause problems:

[INFO] found mqtt on Home Assistant
1541519833: Client bt-mqtt-gateway already connected, closing old connection.
1541519833: Client bt-mqtt-gateway disconnected.
1541519833: New client connected from 192.168.178.172 as bt-mqtt-gateway (c0, k60, u'mqtt').
1541519834: New connection from 172.30.32.1 on port 1883.
[INFO] found mqtt on Home Assistant
1541519836: Client bt-mqtt-gateway already connected, closing old connection.
1541519836: Client bt-mqtt-gateway disconnected.
1541519836: New client connected from 172.30.32.1 as bt-mqtt-gateway (c0, k60, u'mqtt').
1541519837: New connection from 192.168.178.172 on port 1883.
[INFO] found mqtt on Home Assistant
1541519840: Client bt-mqtt-gateway already connected, closing old connection.
1541519840: Client bt-mqtt-gateway disconnected.
1541519840: New client connected from 192.168.178.172 as bt-mqtt-gateway (c0, k60, u'mqtt').
1541519841: New connection from 172.30.32.1 on port 1883.
[INFO] found mqtt on Home Assistant
1541519843: Client bt-mqtt-gateway already connected, closing old connection.
1541519843: Client bt-mqtt-gateway disconnected.
1541519843: New client connected from 172.30.32.1 as bt-mqtt-gateway (c0, k60, u'mqtt').
1541519844: New connection from 192.168.178.172 on port 1883.
[INFO] found mqtt on Home Assistant
1541519846: Client bt-mqtt-gateway already connected, closing old connection.
1541519846: Client bt-mqtt-gateway disconnected.
1541519846: New client connected from 192.168.178.172 as bt-mqtt-gateway (c0, k60, u'mqtt').
1541519847: New connection from 172.30.32.1 on port 1883.

Cannot start gateway.py - error regarding paho mqtt

I'm trying to use the bt-mqtt-gateway to publish info from a Xiaomi Temperature and Humidity Sensor, but gateway.py cannot start:

$ sudo ./gateway.py -d
019-10-27 07:45:36,085 INFO bt-mqtt-gw gateway.py:61:<module> - Starting
2019-10-27 07:45:36,086 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: hostname/lwt_topic
2019-10-27 07:45:38,924 INFO bt-mqtt-gw.workers.mithermometer mithermometer.py:19:_setup - Adding 1 mithermometer devices
2019-10-27 07:45:38,925 DEBUG bt-mqtt-gw.workers.mithermometer mithermometer.py:21:_setup - Adding mithermometer device 'living_room' (58:2D:34:34:3B:DD)
2019-10-27 07:45:38,925 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:93:register_workers - Added mithermometer config with a 2 seconds timeout
2019-10-27 07:45:38,925 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:103:register_workers - Added mithermometer worker with 30 seconds interval and a 35 seconds timeout
Traceback (most recent call last):
  File "./gateway.py", line 67, in <module>
    manager.register_workers(global_topic_prefix).start(mqtt)
  File "/home/bt2mqtt/bt-mqtt-gateway/workers_manager.py", line 156, in start
    mqtt.callbacks_subscription(self._mqtt_callbacks)
  File "/home/bt2mqtt/bt-mqtt-gateway/mqtt.py", line 112, in callbacks_subscription
    self.mqttc.connect(self.hostname, port=self.port)
  File "/home/bt2mqtt/.local/lib/python3.6/site-packages/paho/mqtt/client.py", line 839, in connect
    return self.reconnect()
  File "/home/bt2mqtt/.local/lib/python3.6/site-packages/paho/mqtt/client.py", line 1009, in reconnect
    return self._send_connect(self._keepalive, self._clean_session)
  File "/home/bt2mqtt/.local/lib/python3.6/site-packages/paho/mqtt/client.py", line 2348, in _send_connect
    remaining_length += 2 + len(self._password)
TypeError: object of type 'int' has no len()
$

Here's the config.yaml:

$ cat config.yaml
mqtt:
  host: 192.168.200.100
  port: 1883
  username: bt2mqtt
  password: XXXXXXXXXXX
  #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: openhab
    retain: true
  topic_subscription:
    update_all:
      topic: openhab/status
      payload: online
  command_timeout: 35           # Timeout for worker operations. Can be removed if the default of 35 seconds is sufficient.
  workers:
    mithermometer:
      args:
        devices:
          living_room: 58:2D:34:34:3B:DD
        topic_prefix: mithermometer
      update_interval: 30

Bluetooth is running properly, 'cause I can run lescan OK:

$ sudo hcitool lescan
LE Scan ...
50:AE:91:0A:00:D8 (unknown)
50:AE:91:0A:00:D8 (unknown)
79:67:88:3E:3D:F0 (unknown)
79:67:88:3E:3D:F0 (unknown)
20:DA:22:1C:FC:AA (unknown)
58:2D:34:34:3B:DD (unknown)
58:2D:34:34:3B:DD MJ_HT_V1
6E:B8:33:22:45:1F (unknown)

As far as I can tell, that error is regarding paho mqtt client, but I cannot figure it out.
I can publish mqtt messages with no problem using the configured host, username and password:

$ mosquitto_pub -h 192.168.200.100 -u bt2mqtt -P XXXXXXXXX -t hostname/mithermometer -m TEST
bt2mqtt@bt2mqtt:~/bt-mqtt-gateway$ mosquitto_pub -h 192.168.200.100 -u bt2mqtt -P 152814441511 -t hostname/mithermometer -m TEST22
bt2mqtt@bt2mqtt:~/bt-mqtt-gateway$
$ mosquitto_sub -h 192.168.200.100 -u bt2mqtt -P XXXXXXXXX -t hostname/mithermometer
TEST
TEST22

I'm open to any ideas...
I'm pretty sure I'm missing something obvious...

Broken pipe errors when calling getServices()

I'm creating a new worker for Medisana scales, based on https://github.com/keptenkurk/BS440. So far everything seems pretty straight forward and similar to the ibbq. I will upload the first code asap but for now I'm having an issue when calling getServices() on a connected peripheral. I used the ibbq worker to test this, added btle.Peripheral(self.mac, btle.ADDR_TYPE_RANDOM) (which is required for the Medisana scale).

config entry:
ibbq:
args:
devices:
badkamer: 11:22:33:44:55:66
topic_prefix: medisanascale
update_interval: 10

Everything works fine until I call getServices(), after that I get this error:
Traceback (most recent call last): File "./gateway.py", line 67, in <module> manager.register_workers(global_topic_prefix).start(mqtt) File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 88, in register_workers command_timeout, global_topic_prefix, **worker_config["args"] File "/home/pi/bt-mqtt-gateway/workers/base.py", line 7, in __init__ self._setup() File "/home/pi/bt-mqtt-gateway/workers/ibbq.py", line 25, in _setup self.devices[name] = ibbqThermometer(mac, timeout=self.command_timeout) File "/home/pi/bt-mqtt-gateway/workers/ibbq.py", line 105, in __init__ self.device = self.subscribe() File "/home/pi/bt-mqtt-gateway/workers/ibbq.py", line 115, in subscribe services = self.device.getServices() File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 481, in getServices return self.services File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 477, in services self._serviceMap = self.discoverServices() File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 459, in discoverServices rsp = self._getResp('find') File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 407, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 361, in _waitResp self._stopHelper() File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 293, in _stopHelper self._helper.stdin.flush() BrokenPipeError: [Errno 32] Broken pipe Exception ignored in: <bound method Peripheral.__del__ of <bluepy.btle.Peripheral object at 0xb6a2e030>> Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 630, in __del__ self.disconnect() File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 453, in disconnect self._writeCmd("disc\n") File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 305, in _writeCmd self._helper.stdin.flush() BrokenPipeError: [Errno 32] Broken pipe

Does anybody have any idea how to fix this? It seems to me that the ibbq must have this issue as well.

[solved] Since the last version I have a problem blescanmulti

Hello,
I updated the maj. Since if the balance does not communicate BT-GATEWAY no longer works. I have to connect it for it to work.

I also have my two nut finder which stays in home and therefore does not spend more not_home.

sudo ./gateway.py -d 2019-09-05 21:03:26,223 INFO bt-mqtt-gw gateway.py:41:<module> - Starting 2019-09-05 21:03:26,232 DEBUG bt-mqtt-gw.mqtt mqtt.py:28:__init__ - Setting LWT to: btgateway/lwt_top ic 2019-09-05 21:03:27,255 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:77:register_workers - Add ed miscale worker with 300 seconds interval and a 35 seconds timeout 2019-09-05 21:03:30,025 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:77:register_workers - Add ed blescanmulti worker with 60 seconds interval and a 35 seconds timeout 2019-09-05 21:03:30,050 DEBUG bt-mqtt-gw.mqtt mqtt.py:100:callbacks_subscription - Subscribing to: bt gateway/miscale/update_interval 2019-09-05 21:03:30,056 DEBUG bt-mqtt-gw.mqtt mqtt.py:100:callbacks_subscription - Subscribing to: bt gateway/blescan/update_interval 2019-09-05 21:03:30,064 DEBUG bt-mqtt-gw.mqtt mqtt.py:100:callbacks_subscription - Subscribing to: bt gateway/homeassistant/status 2019-09-05 21:03:30,097 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:128:update_all - Updating all workers 2019-09-05 21:03:40,317 ERROR bt-mqtt-gw logger.py:48:log_exception - Fatal error while executing wor ker command: TimeoutError Traceback (most recent call last): File "./gateway.py", line 53, in <module> mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute()) File "/home/dckiller/bt-mqtt-gateway/workers_manager.py", line 41, in execute messages = self._callback(*self._args) File "/home/dckiller/bt-mqtt-gateway/workers/miscale.py", line 18, in status_update return [MqttMessage(topic=self.format_topic('weight/kg'), payload=self._get_weight())] File "/home/dckiller/bt-mqtt-gateway/workers/miscale.py", line 29, in _get_weight time.sleep(1) File "/usr/local/lib/python3.5/dist-packages/interruptingcow/__init__.py", line 74, in handler raise exception TimeoutError: Retrieving the weight from miscale device c8:47:8c:9f:7b:0a timed out after 5 seconds Traceback (most recent call last): File "./gateway.py", line 63, in <module> raise e File "./gateway.py", line 53, in <module> mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute()) File "/home/dckiller/bt-mqtt-gateway/workers_manager.py", line 41, in execute messages = self._callback(*self._args) File "/home/dckiller/bt-mqtt-gateway/workers/miscale.py", line 18, in status_update return [MqttMessage(topic=self.format_topic('weight/kg'), payload=self._get_weight())] File "/home/dckiller/bt-mqtt-gateway/workers/miscale.py", line 29, in _get_weight time.sleep(1) File "/usr/local/lib/python3.5/dist-packages/interruptingcow/__init__.py", line 74, in handler raise exception TimeoutError: Retrieving the weight from miscale device c8:47:8c:9f:7b:0a timed out after 5 seconds

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.