bt-mqtt-gateway icon indicating copy to clipboard operation
bt-mqtt-gateway copied to clipboard

Home Assistant auto discovery

Open twsl opened this issue 4 years ago • 10 comments

Is your feature request related to a problem? Please describe. Since Home Assistant is moving towards UI configuration and away from yaml files, having devices as entities in the UI would be nice.

Describe the solution you'd like I'd love to get the mqtt entities automatically discovered by home assistant.

Describe alternatives you've considered configuring them manually.

Additional context

twsl avatar Jan 17 '21 17:01 twsl

Hmm they should be auto discovered by mqtt ? Do you have mqtt autodiscovery on, and enabled in gateway ?

zewelor avatar Jan 17 '21 18:01 zewelor

They are visible in mqtt, but not as device in home assistant. Maybe i misconfigured the prefixes?

twsl avatar Jan 18 '21 13:01 twsl

Auto discovery works for me, devices are detected in Home Assistant, but the values are never received for some reason.

lepinkainen avatar Jan 22 '21 10:01 lepinkainen

@lepinkainen can you share your config?

twsl avatar Jan 26 '21 10:01 twsl

config.yaml:

mqtt:
  host: 192.168.1.12
  port: 1883
  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

  workers:
    ruuvitag:
      args:
        devices:
          livingroom: c3:b3:40:aa:71:23
          bedroom: d9:0b:7c:9c:56:2b
          balcony: fa:13:e6:13:62:aa
        topic_prefix: ruuvitag_ha
      update_interval: 30

docker-compose.yml:

version: '3.7'

services:
  bt-mqtt-gateway:
    image: zewelor/bt-mqtt-gateway
    container_name: bt-mqtt-gateway
    restart: always
    # Uncomment to enable debug
    environment:
      - DEBUG=true
    volumes:
      - ./config.yaml:/config.yaml
    privileged: true
    cap_add:
      - NET_ADMIN
      - NET_RAW
    network_mode: host

Alternating between privileged: true and the cap_add options seems to do nothing of value.

With this setup, everything appears on HA as they should, but the statuses never update. No messages are received in ruuvitag_ha/#. Running with debug=true doesn't log any errors at all.

The tags do work, I've got a similar system built by myself, but can't be arsed to code the HA autodiscovery part, so I'm trying this one. (Also this would allow me to combine the Xiaomi BLE meters in the same setup)

lepinkainen avatar Jan 26 '21 17:01 lepinkainen

Using mqtt-explorer for debugging MQTT is really helpful. One can easily see the published autodiscover configuration as well as the published sensor data. I suspect a miss-match regarding the MQTT topic prefixes.

cybe avatar Mar 14 '21 09:03 cybe

@twsl, not every worker currently supports autodiscovery, which one are you trying?

andrey-yantsen avatar Mar 27 '21 18:03 andrey-yantsen

What code do you need in the worker to support auto discovery? I found the code for inkbird IBS-TH1 posted in the issues section, and it works as a worker, but Home assistant does not auto discover. I also could not use docker container because I didn't know how to add it to the container before it was loaded....so i had to use venv. I see the data getting pulled (probably correctly) and published to MQTT, but so far i haven't pulled it into HA yet.

mike0xt avatar Apr 26 '21 09:04 mike0xt

@andrey-yantsen I tried this with miscale

twsl avatar Apr 26 '21 14:04 twsl

Well, yeah, both inkbord & miscale workers do not have the auto-discovery implemented. You need to implement something like https://github.com/zewelor/bt-mqtt-gateway/blob/master/workers/am43.py#L35-L86 there.

andrey-yantsen avatar Apr 26 '21 15:04 andrey-yantsen