WTH - smartphone app bluetooth sensor for device trackers

The smartphone app has a bluetooth sensor that lists connected devices MAC-addresses. Why can’t we reuse the smartphone apps device tracker state for those devices (if the MAC-address is e.g. listed in known_devices.yaml)?

This is an awesome use case for the BT sensor!

I’ve been toying with this one a little bit on the server side. I’ve created an automation that watches specific existing device_tracker.x (that happen to be mobile_app entities), and if a selected MAC address is in connected_paired_devices or connected_not_paired_devices attribute of sensor.x_bluetooth_connection, it calls device_tracker.see, feeding it the mobile app’s device tracker state, coordinates, and gps_accuracy + 10m (for Bluetooth range), e.g.:

- id: '1635451021845'
  alias: Update Example Device's location from connected bluetooth device
  description: ''
  trigger:
  - platform: state
    entity_id: device_tracker.example1,device_tracker.example2
  condition:
  - condition: template
    value_template: '{%- set entity_id=trigger.entity_id.replace(''device_tracker.'',
      ''sensor.'') ~ ''_bluetooth_connection'' %}

      {{ ''00:11:22:33:44:55'' in state_attr(entity_id, ''connected_paired_devices'')
      or  ''00:11:22:33:44:55'' in state_attr(entity_id, ''connected_not_paired_devices'')
      }}'
  action:
  - service: device_tracker.see
    data:
      mac: 00:11:22:33:44:55
      location_name: '{{ states(trigger.entity_id) }}'
      gps: '{{ state_attr(trigger.entity_id, ''latitude'') }}, {{ state_attr(trigger.entity_id,
        ''longitude'') }}'
      gps_accuracy: '{{ state_attr(trigger.entity_id, ''gps_accuracy'') + 10 }}'
  mode: single

When device_tracker.see is called, it creates the device_tracker entity (and entry in known_devices.yaml) if it doesn’t exist.

Abstracting this out with further templates and/or scripts will get a lot more complicated. Probably within the integration itself is the easiest place to implement this, with an extra control in the app to enable it. But the flow is basically:

When mobile app device_tracker entity is updated, for each connected_(not_)paired entry, call service device_tracker.see with the state and attributes of the mobile app device_tracker, and perhaps fudge gps_accuracy a bit to reflect that the Bluetooth device is within a predictable radius of the device running the mobile app.