zewelor / bt-mqtt-gateway

A simple Python script which provides a Bluetooth to MQTT gateway, easily extensible via custom workers. See https://github.com/zewelor/bt-mqtt-gateway/wiki for more information.
MIT License
550 stars 117 forks source link

lywsd03mmc works, but lywsd03mmc_homeassistant doesn't #215

Closed gingerlime closed 3 years ago

gingerlime commented 3 years ago

[x] I've read the Troubleshooting Wiki, my problem is not described there and I am already using the specified minimum bluez version.

Describe the bug the lywsd03mmc integration works great, but not the lywsd03mmc_homeassistant

Perhaps it's related to passive mode? I'm not sure

To Reproduce I have a lywsd03mmc with custom firmware from https://github.com/atc1441/ATC_MiThermometer set to update every 10 seconds. Plus 3 ruuvitags that were already working.

If I set it up as lywsd03mmc it works fine, and I can see values on the debug log. However, if I set it up with lywsd03mmc_homeassistant then it fails

Expected behavior It should work the same?

Config I added the new device to my config.yaml

mqtt:
  host: 192.168.x.x
  port: 1883
  username: btgateway
  password: ***************
  topic_prefix: pi         # 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:
    ruuvitag:
      args:
        devices:
          abc: F7:68:xx:xx:xx:xx
          xyz: F1:EE:F3:xx:xx:xx
          def: EF:B8:97:xx:xx:xx
        topic_prefix: ruuvitag
      update_interval: 60
    # changing this to lywsd03mmc_homeassistant breaks things
    lywsd03mmc:
      args:
        devices:
          living_room: a4:c1:38:xx:xx:xx
        topic_prefix: mijasensor_gen2
        passive: true
        scan_timeout: 20
      update_interval: 60

I'm running it on a raspberry pi with docker-compose

version: '3.3'
services:
  bt-mqtt-gateway:
    image: zewelor/bt-mqtt-gateway
    logging:
      driver: json-file
      options:
        max-size: "10m"
    environment:
      - TZ=Europe/Berlin
      - DEBUG=true
    network_mode: host
    cap_add:
      - NET_ADMIN
      - NET_RAW
    restart: unless-stopped
    volumes:
      - /path/to/bt-mqtt-gateway/config.yaml:/config.yaml

Debug gateway logs

with lywsd03mmc:

2021-02-17 20:27:01,368 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:39:status_update - a4:c1:38:xx:xx:xx - received scan data 1a18a4c1386a0d3d00d0445a0bcefe
2021-02-17 20:27:01,369 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:87:readAll - a4:c1:38:xx:xx:xx - found values 20.800000, 68, 90
2021-02-17 20:27:01,371 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/living_room', 'payload': '{"temperature": 20.8, "humidity": 68, "battery": 90}'}]

with lywsd03mmc_homeassistant:

2021-02-17 20:28:47,274 INFO bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:92:status_update - Updating 1 lywsd03mmc_homeassistant devices
2021-02-17 20:28:47,275 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:95:status_update - Updating lywsd03mmc_homeassistant device 'hu_mi_dor' (a4:c1:38:xx:xx:xx)
2021-02-17 20:28:47,276 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:170:connected - trying to connect to a4:c1:38:xx:xx:xx
2021-02-17 20:28:54,697 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:172:connected - connected to a4:c1:38:xx:xx:xx
2021-02-17 20:28:54,794 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:181:connected - failed to connect to a4:c1:38:xx:xx:xx : 1/4 attempt
2021-02-17 20:28:54,794 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:188:connected - waiting for next try...
2021-02-17 20:28:55,799 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:170:connected - trying to connect to a4:c1:38:xx:xx:xx
2021-02-17 20:28:55,822 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:172:connected - connected to a4:c1:38:xx:xx:xx
2021-02-17 20:28:55,922 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:181:connected - failed to connect to a4:c1:38:xx:xx:xx : 2/4 attempt
2021-02-17 20:28:55,922 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:188:connected - waiting for next try...
2021-02-17 20:28:56,927 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:170:connected - trying to connect to a4:c1:38:xx:xx:xx
2021-02-17 20:28:56,949 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:172:connected - connected to a4:c1:38:xx:xx:xx
2021-02-17 20:28:57,942 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:181:connected - failed to connect to a4:c1:38:xx:xx:xx : 3/4 attempt
2021-02-17 20:28:57,943 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:188:connected - waiting for next try...
2021-02-17 20:28:58,948 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:170:connected - trying to connect to a4:c1:38:xx:xx:xx
2021-02-17 20:28:58,970 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:172:connected - connected to a4:c1:38:xx:xx:xx
2021-02-17 20:28:59,972 DEBUG bt-mqtt-gw.workers.lywsd03mmc_homeassistant lywsd03mmc_homeassistant.py:181:connected - failed to connect to a4:c1:38:xx:xx:xx : 4/4 attempt
2021-02-17 20:28:59,977 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03Mmc_HomeassistantWorker.status_update: []

Server (please complete the following information):