Device tracker for BT devices?

My (Android) phone has the HA app installed. My car has bluetooth. My phone typically connects to the car while driving.

Is it possible to create device tracker for the car that the app can update (ie with its own GPS coords) when it sees the car’s bluetooth MAC?

I suppose like a private and very limited version of Google’s “find my device” and Apple’s Tags networks. Obviously this would work for any BT device. I see HA has iBeacons already, but I’m not sure why “if phone sees an explicit bluetooth device nearby, then update its location” wouldn’t work for any device - in fact given the app can sense local bluetooth devices an automation to do this, if not already built in an automation should be able to handle it.

Not sure I understand you right, but why wouldn’t you use the coordinates from the app in that case? It must be in your car, so the coordinates should be exactly the same, shouldn’t they? :slight_smile:

You can track any BT device with the app, but I don’t see the use for it. If the phone is near the car, so it could be tracked, you have the data already from the phone?

If you could elaborate a little more, what’s your end goal here, it might be better understandable. :slight_smile: Thanks!

2 Likes

Yes, you can create custom device trackers and assign a location to them by using the device_tracker.see service call.

You will need to use some templating since the bluetooth connection is stored as a list. The following is untested:

trigger:
  - alias: Trigger when initial connection is made
    platform: template
    value_template: |
      {{ '1234YourBTMAC' in state_attr('sensor.YOURPHONE_bluetooth_connection', 'connected_paired_devices') }}
    variables:
      tracker_ent: |
        {{ device_entities(device_id(trigger.entity_id)) | select('match', 'device_tracker.') | first }}
condition: []
action:
  - alias: Update location every 5 minutes while phone is connected to car
    repeat:
      while: "{{ '1234YourBTMAC' in state_attr(trigger.entity_id, 'connected_paired_devices') }}"
      sequence:
        - service: device_tracker.see
          data:
            dev_id: your_car
            gps: "{{ [state_attr(tracker_ent, 'latitude'), state_attr(tracker_ent, 'longitude')] }}"
        - delay:
            minutes: 5

One modification to consider would be changing the repeat’s delay based on the speed reported by the phone’s tracker. If the delay’s length is set as a inverse of the speed, I think it might more reliably represent the vehicle’s location both during travel and after parking.

1 Like

Yeah, but why? It would be exactly the same as the app itself at that moment and that device_tracker is already there…

I assumed it was for a “Where did I leave my car?” kind of thing.

1 Like

Interesting idea! :+1: Haven’t thought of that use case. :thinking:

That would mean, one would need to safe the coordinates just before the phone looses the BT connection to the car. Sounds like a nice feature or an idea for a really cool automation. :slight_smile:

Interesting indeed, setting this topic on “watch” :smiley:

My aim is to track the car (which is useful for a variety of reasons, even if you know where you’ve parked it ;)).

The car itself has no way of reporting its location accurately, but there is almost always a phone with HA app installed in it when it is moving, so yes, I’m asking if there was a built in way to “proxy” device tracking of the car (or really, generic bluetooth devices) using the app. Sounds like there isn’t, but the automation makes for a great workaround which I’m eager to try.

So to answer “why not use the phone directly?”:

  1. Because I want to track the car, not the phone - and so would have to figure out when I’m in the car anyway.
  2. It might not be my phone that we’re using to proxy the car’s location.

This is kind of how the Apple and Google device tracking networks work, although of course this won’t be as expansive. But since we’re not in the habit of losing the car, I think a network of “a couple of phones” should be enough for some basic vehicle tracking. It would not work in all cases (eg theft) but that’s not the scope of this.

Could you elaborate on this? Maybe it does actually exist!

Going back to the automation:

  1. Couldn’t the location be updated each time the “donor” device tracker is updated?
  2. Can we use the beacon list instead of connected?
  3. We’d also need to cover the case when a different phone (or maybe even both?) are seeing the BT device (this alone may be a reason to stick to connected).

I’m actually a little surprised this isn’t built in already :smiley:

There is, but as you said, it depends on the phone, so the phone needs to be near the car for this to work.

This is the idea behind these FMDN, there need to be a trusted phone nearby.

But maybe I don’t understand your goal, let me try an example:
You put a BT beacon (doesn’t matter for now what exactly that should be) in your car. Now you have the HA app on your phone to track this beacon. The app recognizes, when this specific beacon is nearby and gives that data to HA. How would you want to track that beacon, if your phone isn’t nearby? You need a phone with the HA app, and the UUID from that beacon. So even if you configure the app on many different phones, you’d set these apps up in your HA installation.

My question is: how would you like to track the beacon, if none of these phones is around? You see where I’m going with this? If the phone is not nearby, you don’t have a chance to track anything…if the phone is nearby, you already have the position from the phone.

Or do I get you totally wrong? You’re talking about a proxy, but that would imply, you have a proxy (aka. the HA app on a phone) nearby.

The app has a specific setting called “Beacon monitor”. If you enable the monitor, the app recognizes all BT devices nearby by a UUID and gives you an estimate of how far the BT device is away (eg. 1,5m). The only thing you need to do, is find out the UUID of your device. I recommend the good old chips bag. Put the beacon and the phone in the bag, chances are very high that the only device shown on the phone is your beacon. :slight_smile:

The “Beacon monitor” gives you a nice entity_id in HA, and all UUIDs nearby are set as an attribute in that sensor. If you are interested, I can post screenshots and/or code. :slight_smile:

If you want to dig deeper here, let me know, I have this system setup for my presence detection and can share the code. :wink:

Yes, you could… it just seems less efficient since the trigger would fire so many times during the day when you’re not in the car. Whenever possible I try to use the event most proximal in time to what I am interested in as the trigger.

Maybe… I’ve only played with the beacon monitor sensor a little and it seemed pretty “bouncy”. If it’s stable and reliable for you, try it.

Add an or in the example above’s template trigger:

{{ '1234CarsBTMAC' in state_attr('sensor.A_PHONE_bluetooth_connection', 'connected_paired_devices') or 
'1234CarsBTMAC' in state_attr('sensor.B_PHONE_bluetooth_connection', 'connected_paired_devices') }}

Why? … At best this is a bit of a hack. I wouldn’t recommend it to anyone who wasn’t interested in tinkering or needed something really reliable and accurate. There are a number of devices that could be permanently left in a vehicle to provide actual tracking.

I have an automation like this.
It gives a device tracker on a map card like this

What Didgeridrew posted is good but there is a few considerations to keep in mind.
Either you have the phone in high accuracy mode while driving or, you use what paddy hinted at and only save the position when you disconnect and use the single accurate position notification thing to make sure the position is accurate.

I use high accuracy and save the position at disconnect (when engine turns off)

1 Like

How does high accuracy work with the battery? I never tried, because I got the feeling, it’s quite hungry. Shouldn’t be a big problem within a car though. :slight_smile:

Anyway, you use this is a “where did I park my car” function?

You might not even need to activate the beacon. If the mobile phone always connects to the car for handsfree calling, the you can check the mobile’s sensor with the bluetooth connections. It has an attribute naming the devices. So you could see if the car is connected, and copy the phone gps location only if that is the case. You could even do it for multiple phones.

It’s not for me, it’s for my spouse.
And yes it’s to know where she parked the car.
Battery is not that noticable. Not on my phone at least.
But most of the time my phone is on charge in the phone, but even without it’s not that bad.

1 Like

Well not that it’s entirely relevant here, but it’s any participating phone. Essentially each time a participating phone sees a beacon (associated with the phone’s owner or not), it updates the location of that beacon in a database that the owner of the beacon can look up. That’s essentially what I want to do here (although the pool of participating phones will of course be smaller). EDIT: I see from another thread that you know all this already :wink:

I don’t need to (as I would know where the car will be parked, so wouldn’t need updates). I agree (and as I mentioned before) this wouldn’t be useful (for example) in a theft situation. But for things like automating things when a car is approaching or has left a zone, this should be extensive enough.

Right. But that doesn’t give an actual device tracker for that beacon does it? I think those beacons are expected to not move. So we’d need an automation as above to “copy” the phone’s location - I don’t need to know when I’m close to a beacon with a known location, but almost want it the other way around - to set the location of a beacon in an arbitrary location.

I was thinking more of (pseudo):

trigger on bluetooth beacon
   while seeing beacon
      wait for phone location update
         update virtual device tracker

It would need some adjustments but it seems to get the highest accuracy for the most relevant time (and for free since the phone would be sending location updates anyway).

My main lightbulb here was that this was a) free b) uses no extra device or data connections c) requires no modification to the car. But I’d be interested in hearing about these alternatives - I know of GSM GPS trackers but they would need SIM cards and power etc.

Sure that’s possible, you could use a loop with a Wait for trigger action in it (and probably a short delay).

I don’t know of any alternative that meets all those requirements.

  • GSM GPS is going to be the most broadly usable and also the most costly.
  • For those who have access to an ISP that offers broad WiFi coverage, it should be possible to set up an ESPHome device that incorporates a GPS antenna and sends HTTP requests to HA.
  • For those in areas with a decent mesh, Meshtastic trackers are an option.

I have the red board here in our cars, an older version with USB micro.
Apart from getting a BT device in the car they work great as BT audio devices too if the car doesn’t have that.
https://nl.aliexpress.com/item/1005006686108158.html

They can be considered free given how cheap they are.

Hi thanks, but what would this add over built in Bluetooth?

Oh and fwiw, it seems that the beacon tracker doesn’t work with just any BT device, so it looks like I’ll have to use connected instead after all.

:slight_smile: I see, I misunderstood your intention, sorry for that! :slight_smile:

I hope I’m right now, but that shouldn’t be that hard to achieve. :laughing:

That’s right, it doesn’t. There you would need the already mentioned automation. But in regard to moving, they’re explicitly made for “moving around”.

Sidenote: ESPresense is using these beacons to calculate, where in a room the beacon is, and it’s surprisingly exact. :slight_smile: Might be an interesting read for a rainy day. :laughing:

As I said, now I think I understand, and yes, that should be doable.

So let’s go - finally! :laughing:

I’m assuming you have an ordinary BT beacon in your car, eg. something like Tile. I don’t know, if an AirTag or GoogleWhateverTag works as well, as I don’t know, if they send out the correct BT signals, but I guess they’d do as well.

First go to the settings of the companion apps, that you want to use as trackers. Enable the “Beacon Monitor” under Settings > Manage Sensors > Bluetooth Sensors. You can leave the standard settings for now, but take care, there is one button that generally enables the monitor, and a little downwards inside the settings is another button to enable the monitor.

You now should have a new entity, called something like sensor.your_phone_name_beacon_monitor. This sensor is holding the nearby beacons as an attribute with an UUID and a proximity, how far away the beacon is. You now need to find out the UUID of your beacon in the car (refer to the chips bag I mentioned earlier :laughing:).

The rest is fairly trivial, you need an automation that triggers on attribute changes of that sensor. Something like this:

{% if state_attr('sensor.your_phone_name_beacon_monitor', 'xxx_xxx_xx') != None %} 

The attribute with the UUID is only set, if the beacon is within range. So it’s just a check for “is here/is not here”.

If you set it up like this, you don’t need to check for any connections or things like that. If the attribute with the correct UUID is available, you set the phones location in a device_tracker (as shown above from @Didgeridrew with the device_tracker.see service).

So, is this, what you where after, or am I still wrong? :joy:


EDIT: I forgot to mention, why I’d go this way, and not with the connection. :wink: By tracking the UUID you don’t poll the device and it doesn’t need to be connected in any way. It’s just a beacon that you turn on by putting in a battery. I’m using this way as one part of my presence detection. :slight_smile:

But that’s me, it’s your choice and the version above should work as well as this one! :slight_smile: Your choice! :smiley:


EDIT2: Btw. you can use an old phone with installed companion app as a beacon as well! In the same settings segment is the “BLE Transmitter”. This makes your phone a beacon, and you wouldn’t even need to search for the UUID, as it would be set in this setting… :open_mouth: :laughing:

1 Like