Bluetouth automation with 2 mac address

Hello all,

First I want to thanks for the amazing community, this is exceptional.

Now let me write about my issue, I have the below automation and is working great:

alias: Open Gate BT Car
description: ''
trigger:
  - platform: state
    entity_id: sensor.sm_g973f_bluetooth_connection
    attribute: connected_paired_devices
    to: '[2C:4C:C6:B0:65:DF]'
condition:
  - condition: device
    device_id: d23b1f6636911bf3e36e59f0318ca95a
    domain: device_tracker
    entity_id: device_tracker.sm_g973f
    type: is_home
action:
  - type: toggle
    device_id: a2f40d9e66a767cb858ba14250b0f1b3
    entity_id: switch.gate_remote
    domain: switch
  - service: notify.mobile_app_sm_g973f
    data:
      message: Gate is opening by BT
mode: single

And all is working perfect. Now I have a smart-band that is connected to my phone all the time and I can hardcode the new mac address is the automations but this is not the normal way to solve this issue.

Now is the developer tolls tab the phone “sensor.sm_g973f_bluetooth_connection” shows [8C:CE:FD:13:6F:13] all the time connected:

connected_not_paired_devices: '[8C:CE:FD:13:6F:13]'
connected_paired_devices: '[8C:CE:FD:13:6F:13]'
paired_devices: '[2C:4C:C6:B0:65:DF, D0:6A:1F:00:7F:09, 8C:CE:FD:13:6F:13, C9:83:45:D2:25:1A]'
unit_of_measurement: connection(s)
friendly_name: SM-G973F Bluetooth Connection
icon: mdi:bluetooth

and when I am in my car and the phone is connected to the car BT and smart-band the “sensor.sm_g973f_bluetooth_connection” shows:

connected_not_paired_devices: '[8C:CE:FD:13:6F:13]'
connected_paired_devices: '[2C:4C:C6:B0:65:DF, 8C:CE:FD:13:6F:13]'
paired_devices: '[2C:4C:C6:B0:65:DF, D0:6A:1F:00:7F:09, 8C:CE:FD:13:6F:13, C9:83:45:D2:25:1A]'
unit_of_measurement: connection(s)
friendly_name: SM-G973F Bluetooth Connection
icon: mdi:bluetooth

I tried different templates but not are working and now I come with a request to help me solving this issue.

How can I set the automation to detect when the car BT mac address is the “connected_paired_devices” attribute.

Thank you in advance.

trigger:
  - platform: template
    value_template: "{{ '2C:4C:C6:B0:65:DF' in state_attr('sensor.sm_g973f_bluetooth_connection', 'connected_paired_devices') }}"

The in keyword will just check if the exact string is in another string and return True or False. So just see if the MAC you care about is ‘in’ the attribute you care about.

Thank you Jim,

I used your solution is a template sensors and is working perfectly.

  - platform: template
    sensors:
      sensor_number:
        friendly_name: in_car
        value_template: >
          {% if "2C:4C:C6:B0:65:DF" in state_attr('sensor.sm_g973f_bluetooth_connection', 'connected_paired_devices') -%}                
            in
          {% else -%}
            off
          {% endif -%}

My goal is to use a helper to define the MAC address of the car and use that helper is a automation.