Using bluetooth to rember parking location

Hi there,

I would like to use the bluetooth sensor of my Home Assistant companion app on android to remember my last parking location.

My plan is to do this via an automation. I think this is something that might be very helpful to other members as well.

In the android app I can see under Settings>Companion App>Manage Sensors>Bluetooth Connection under “paired_devices” that my car is known to the app. Also I can see which devices are currently connected under “connected_paired_devices”.

Also in HA I can see these states under developer tools.

When going in the automation section of HA (GUI not YAML) I can create a trigger from a change in state.
I can choose my smartphones sensor: [sensor.samsung_s_10_bluetooth_connection] and I can choose the attribute “connected paired devices”.
In the next field “From” I put in the MAC of my car’s bluetooth.
However, I struggle to get to the next step. I don’t know what to put into the attribute field for “To” . I tried to leave it blank or put in a zero but neither would trigger the automation.

I would appreciate your help to get this automation running.

1 Like

Since the connected_paired_devices attribute returns a list, not a string you will need to alter your approach. For your situation, you want to fire the automation whenever that list goes from containing your car’s MAC to not containing it. You can’t specify static to or from values because the list (at least in theory) could contain any number of other MAC values at the same time it contains your car’s MAC value. AFAIK, there isn’t a way to specify this trigger without using templating.

trigger:
  - alias: trigger on disconnect from car
    platform: template
    value_template: >
       {{ state_attr('sensor.samsung_s_10_bluetooth_connection'
       , 'connected_paired_devices') is not search('xx:xx:xx:xx:xx') }}
1 Like

Hi thanks a lot!
I have so far not been working with templates.
When I entered your code into the " When a template triggers" section of the automation wizard nothing happened on disconnecting the bluetooth device. I changed the MAC accordingly.

I used this code:
trigger:

  • alias: trigger on disconnect from car
    platform: template
    value_template: >
    {{ state_attr(‘sensor.samsung_s_10_bluetooth_connection’
    , ‘connected_paired_devices’) is not search(‘08:DF:1F:AA:BE:00’) }}

Do you have any idea where the problem lies? Does it work for you? I did not test it with a car but a bluetooth speaker to make it easier. In the states section under developer tools I can see it being listed as connected or not connected.

Without proper formatting it is difficult to tell where the issue might be. Post your whole automation instead of showing it piecemeal… that way we don’t have to guess about possible issues.

With the appropriate MAC for my device, what I posted has been tested and does work for me.

Sorry for the broken formatting.
Here is the version I use:

I put it into the trigger section of “when a template triggers” and the result should be that I get a message sent to my mobile, reproving to current location. I can trigger the action manually so the sending bit should be fine, however, it would just not trigger it.

Post your actual automation configuration. Re-posting what I posted will not give us any clues about what is happening in your automation. You can access it from the Automation editor by clicking on three dot menu at the top right hand of the page, then click “Edit in YAML”. Select the complete contents and paste it here.

OK, apologies:

alias: TEST BLUETOOTH Disconnected
description: ""
trigger:
  - platform: template
    value_template: |-
      trigger:
        - alias: trigger on disconnect from car
          platform: template
          value_template: >
             {{ state_attr('sensor.samsung_s_10_bluetooth_connection'
             , 'connected_paired_devices') is not search('08:DF:1F:AA:BE:00') }}
condition: []
action:
  - service: notify.mobile_app_samsung_s_10
    data:
      message: >-
        The car is parked at: {{ states('sensor.samsung_s_10_geocoded_location')
        }}
      data:
        "[object Object]": test bluetooth disconnected
mode: single


You made a copy/paste error… it’s easy to do with the way template triggers are shown in the UI automation editor.

alias: TEST BLUETOOTH Disconnected
description: ""
trigger:
  - alias: trigger on disconnect from car
    platform: template
    value_template: >
      {{ state_attr('sensor.samsung_s_10_bluetooth_connection'
      , 'connected_paired_devices') is not search('08:DF:1F:AA:BE:00') }}
condition: []
action:
  - service: notify.mobile_app_samsung_s_10
    data:
      message: >-
        The car is parked at: {{ states('sensor.samsung_s_10_geocoded_location') }}
mode: single
1 Like

Thanks, that sorted it.
Awesome!!!

I case you want a different approach this is what I’ve been using.

It creates a device tracker to show the vehicle location on the HA map instead of sending a notification of the location. But you can combine this with yours if you want both.

First you need to create a device tracker in your known_devices.yaml (create that file in your config directory if it doesn’t exist):

toyota_tacoma:
  icon:
  name: Toyota Tacoma
  picture: /local/tacoma.jpg
  track: true

then create a variable to save the GPS location. I use the custom integration hass-variables for this but you might be able to use your existing location sensor:

  tacoma_location_saved:
    value: 'unknown'
    attributes:
      latitude: ''
      longitude: ''
    restore: true

then you can use the following to update everything:

- alias: Set Tacoma Location
  trigger:
    - platform: state
      entity_id: sensor.my_mobile_app_bluetooth_connection
    - platform: state
      entity_id: person.me
      to: 'home'
  action:
    choose:
      - conditions:
          - "{{ trigger.entity_id == 'sensor.my_mobile_app_bluetooth_connection' }}"
          - "{{ '84:DD:20:62:AA:AA (TOYOTA Tacoma)' in trigger.from_state.attributes.connected_paired_devices }}"
          - "{{ '84:DD:20:62:AA:AA (TOYOTA Tacoma)' not in trigger.to_state.attributes.connected_paired_devices }}"
        sequence:
          - service: device_tracker.see
            data:
              dev_id: toyota_tacoma
              location_name: "{{ states('device_tracker.my_mobile_app') }}"
              gps: 
                - "{{ state_attr('device_tracker.my_mobile_app', 'latitude') }}"
                - "{{ state_attr('device_tracker.my_mobile_app', 'longitude') }}"
          - delay:
              seconds: 10
          - service: variable.set_variable
            data:
              variable: tacoma_location_saved
              value: "{{ states('device_tracker.toyota_tacoma') }}"
              attributes:
                latitude: "{{ state_attr('device_tracker.toyota_tacoma', 'latitude') }}"
                longitude: "{{ state_attr('device_tracker.toyota_tacoma', 'longitude') }}"
      - conditions:
          - "{{trigger.entity_id == 'person.me'}}"
        sequence:
          - service: device_tracker.see
            data:
              dev_id: toyota_tacoma
              location_name: home
              gps: [41.00000, -85.000000]
          - delay:
              seconds: 10
          - service: variable.set_variable
            data:
              variable: tacoma_location_saved
              value: "{{ states('device_tracker.toyota_tacoma') }}"
              attributes:
                latitude: "{{ state_attr('device_tracker.toyota_tacoma', 'latitude') }}"
                longitude: "{{ state_attr('device_tracker.toyota_tacoma', 'longitude') }}"
    
- alias: Restore Tacoma Location After Restart
  trigger:
    - platform: homeassistant
      event: start
  action:
    - delay:
        minutes: 1
    - service: device_tracker.see
      data:
        dev_id: toyota_tacoma
        location_name: "{{ states('variable.tacoma_location_saved') }}"
        gps: 
          - "{{ state_attr('variable.tacoma_location_saved', 'latitude') }}"
          - "{{ state_attr('variable.tacoma_location_saved', 'longitude') }}"

it’s a bit more involved but it gives you a marker on the map and it survives HA restarts.

1 Like

Oh, thanks for the inspiration! you are totally right, with the concept of a map rather than a push message. I was just not able to implement anything other than a message but I will give your approach a try!

1 Like

So basically the GUI doesn’t support the way that HA does Bluetooth reporting anymore?

I don’t understand what you are actually asking… Which part of the GUI? Which element of Bluetooth reporting? For that matter, OP’s question relates to the interaction between Home Assistant core and the Home Assistant Companion app, so which “HA” are you asking about?

I also don’t understand the “anymore”… as far as I can tell this is the way the referenced sensor attribute has worked since at least 2020.

His comment baffles me also!

What I’m trying to ask is this.
This doesn’t seem to work

It doesn’t help if I take the full name either

My conclusion is that the GUI doesn’t work or I’m doing something wrong.

Okay, now we know what you’re talking about.

I guess it’s a little bit of both. First, you’re comparing apples and oranges; trying to match a (partial) string to a list, which would never be true. Second, AFAIK the to and from are only set up to handle certain data types, and lists are not one of those.

If you want to use a State trigger with a specified attribute you can. Leave the to: field empty, then use a Template condition to search for your paired device within the attribute’s list.

trigger:
  - platform: state
    entity_id:
      - sensor.pixel_6a_bluetooth_connection
    attribute: connected_paired_devices
condition:
  - condition: template
    value_template: >-
      {{ '50:C2:ED:E5:4A:ED (Jabar Evolve2 85)' in
      trigger.to_state.attributes.connected_paired_devices }}

You might see this as it “not working”, but it may be the only practical solution to address a situation where HA has no way to guarantee the order or content of the list of connected devices coming from your phone. Even if State triggers accepted lists in the to: field, the State trigger is a very literal tool and you would need to include every combination of connected devices for reliable functioning.

Thanks for your answers, I still think the GUI should handle this.
if the Bluetooth connected_paired_devices returns a list, the GUI should handle that, either by saying it’s not supported or by just handling it. Right now it doesn’t give any hints to what is wrong.

Since I specifically want to trigger when I loose connection to my car I need to know that it was actually connected to the car before I trigger anything. Thus I want to use From:
From what I can understand from the value_template it only checks the current status.

If I understand things correctly this will trigger every time I loose or connect a BT-device to my phone and I’m not in my car.

alias: Uppdatera bilen när BT kopplas bort
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.pixel_6a_bluetooth_connection
    attribute: connected_paired_devices
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: template
    value_template: |
      {{ state_attr('sensor.pixel_6a_bluetooth_connection'
            , 'connected_paired_devices') is not search('00:92:A5:05:29:75 (Kia)') }}
action:
  - service: kia_uvo.force_update
    data:
      device_id: d92adcbbeac7763c72f8603919727ab6sdfsdf
mode: single

If you use the trigger variable in your template instead of using the state_attr() function you can access both the prior and new values for the attribute.

alias: Uppdatera bilen när BT kopplas bort
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.pixel_6a_bluetooth_connection
    attribute: connected_paired_devices
condition:
  - condition: template
    value_template: |
      {% set car = '00:92:A5:05:29:75 (Kia)' %}
      {{ car in trigger.from_state.attributes.connected_paired_devices and 
      not car in trigger.to_state.attributes.connected_paired_devices }}
action:
  - service: kia_uvo.force_update
    data:
      device_id: d92adcbbeac7763c72f8603919727ab6sdfsdf
mode: single

If you re-read the earlier posts on this thread you will see that @finity suggested a very similar condition in their solution for the original question.

1 Like

I created a binary sensor for my car’s bluetooth…

  - name: "Car Bluetooth"
    unique_id: phone_connected_to_car_bluetooth
    device_class: connectivity
    state: "{{ '28:38:5C:45:3E:2B (Mustang Mach-E)' in state_attr('sensor.my_phone_bluetooth_connection','connected_paired_devices') and state_attr('sensor.my_phone_bluetooth_connection','connected_paired_devices') != None }}"
    icon: "{{ iif('28:38:5C:45:3E:2B (Mustang Mach-E))' in state_attr('sensor.my_phone_bluetooth_connection','connected_paired_devices') and state_attr('sensor.my_phone_bluetooth_connection','connected_paired_devices') != None,'mdi:bluetooth-connect','mdi:bluetooth-off') }}"

I then use the binary sensor in my automations…

alias: Car Arrives
description: ""
trigger:
  - platform: state
    entity_id:
      - device_tracker.my_phone
    id: Zone Arrival
    from: not_home
    to: home
  - platform: state
    entity_id:
      - binary_sensor.vehicle_real_presence
    to: "on"
    id: Zigbee Presence
condition:
  - condition: state
    entity_id: binary_sensor.car_in_garage
    state: "off"
  - condition: state
    entity_id: cover.garage_door
    state: closed
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - condition: state
    entity_id: binary_sensor.clarity_bluetooth
    state: "on"
action:
  - parallel:
      - service: cover.open_cover
        data: {}
        target:
          entity_id: cover.garage_door
      - service: notify.mobile_app_my_phone
        data:
          message: TTS
          data:
            ttl: 0
            priotity: high
            media_stream: alarm_stream_max
            tts_text: Welcome home
      - service: notify.pushbullet
        data:
          title: Arrived - Door opened
          message: |
            Triggered by {{ trigger.id }}
            from {{ trigger.from_state.state }}
            to {{ trigger.to_state.state }}
      - service: input_text.set_value
        data:
          value: "{{trigger.id}}"
        target:
          entity_id: input_text.vehicle_arrived
        continue_on_error: true
      - service: alarm_control_panel.alarm_disarm
        data: {}
        target:
          entity_id: alarm_control_panel.alexa_guard_da03a
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.car_in_garage
        to: "on"
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
    enabled: true
  - service: script.activate_alexa_actionable_notification
    data:
      text: Shall I close the garage door?
      event_id: actionable_notification_garage_door_open
      alexa_device: media_player.garage_echo_dot
    enabled: true
  - wait_for_trigger:
      - platform: event
        event_type: alexa_actionable_notification
    timeout:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
trace:
  stored_traces: 15
mode: single
1 Like

Hi there,
I eventually used this post https://community.home-assistant.io/t/find-parking-location-using-bluetooth/665509
It is a very good step by step guide with plenty of additional settings and options