esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
422 stars 27 forks source link

Something like "on tag" but for BLE, with some nice variable #288

Closed nerdosity closed 2 years ago

nerdosity commented 5 years ago

Describe the problem you have/What new integration you would like I would like to have an event that can fire an automation when a BLE device is found, and this automation should have access to another variable: distance from BLE device.

Please describe your use case for this integration and alternatives you've tried: I would like to be able to integrate my BLE devices with MQTT Room component of home assistant. So we should need to format a packet like this:

{ "id": "123testid", "name": "Test Device", "distance": 5.678 } and publish it to some topic.

Additional context https://www.home-assistant.io/components/mqtt_room/

I tried https://github.com/happy-bubbles/presence and https://github.com/mKeRix/room-assistant, they both work well but Happy Bubble project is dead and room-assistant is based on raspberry devices, it would cost much less and would be much easier using ESP32 instead of raspberry

animavitis commented 5 years ago

I was doing it some time ago

sensor:
   - platform: ble_rssi
    mac_address: 84:A4:66:89:75:8E
    id: rssi_sygonix
    internal: true
    on_value:
    - mqtt.publish_json:
        topic: home_presence/room_1
        payload: |-
          root["id"] = "84:A4:66:89:75:8E";
          root["name"] = "sygonix";
          root["distance"] = (0.89)* pow(id(rssi_sygonix).state/-59,7.7095) + 0.11;
nerdosity commented 5 years ago

That's good, but it's just for THAT value. It would be easier to get all values pushed to Home Assistant and manage everything just from there.

tlrobinson commented 5 years ago

Iā€™m looking to do something similar for integration with FIND3. I want to publish all BLE devices MAC addresses, their RSSI, and the ESPHome device name to a MQTT topic. Also it should happen periodically rather than just when the device is first seen.

Currently I'm just manually adding sensor entries for each device I want to track, which isn't a big deal with OTA updates and !include support, but it would be nice you could eliminate that step completely and push every device seen to FIND3.

Also currently I'm doing ESPHome -> Home Assistant -> Node-RED -> FIND3 but if https://github.com/schollz/find3/issues/135 is implemented I think I could do ESPHome directly to FIND3 via MQTT.

kmdm commented 3 years ago

Just to say I implemented something like this for iBeacons using the UUID instead of the BT MAC (which can be random). It sends all detected iBeacons to MQTT.

https://gist.github.com/kmdm/c01c0693b1380d826af200a3e9b2a656

It uses a different distance formula (the first one Google showed me šŸ˜†) and I have no issue changing it at all. (NB: The C++ could probably be better!)

I'd just like to mention what I've done, get any feedback and give my šŸ‘ for this being a "first class" feature instead of something needing to be implemented in lambdas.