Automation Attribute Template

I know this question has been asked, I have roamed through several topics here but I still can’t seem to be able to solve my issue.
I am trying to condition an automation that will check my phone for a connected bluetooth device

Entity is [sensor.me_phone_bluetooth_connection] and attribute is a mac address that will go from attribute paired_devices(disconnected from Bluetooth) to connected_paired_devices(connected to Bluetooth)

I have the configuration below in my automation.yaml

alias: Getting to Work
  description: ''
  trigger: []
  condition: []
  action:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ is_state_attr(''sensor.me_phone_bluetooth_connection'',''connected_paired_devices'',
          ''6C:XX:XX:XX:XX:47'') }}'
      sequence:
      - device_id: device_id
        domain: mobile_app
        type: notify
        message: headphones connected
        title: connected
    - conditions:
      - condition: template
        value_template: '{{ is_state_attr(''sensor.me_phone_bluetooth_connection'',''paired_devices'',
          ''6C:XX:XX:XX:XX:47'') }}'
      sequence:
      - device_id: device_id
        domain: mobile_app
        type: notify
        message: headphones not connected
        title: not connected

Yet when I execute the automation to test it out nothing happens… what am I doing wrong?

The end goal is to control the media volume depending on devices that are connected (my car or headphones) using notification commands.

After some more troubleshooting I found that in the developer tools the value of the template is always “False” but changes to “True” when I include the entire string of an attribute, this means the brackets and all other mac addresses.

Is there an equivalent of a wild card that I can implement here? that way I can look for a specific mac address and ignore other parts of the string.

try it like this instead:

{{ '6C:XX:XX:XX:XX:47' in state_attr('sensor.me_phone_bluetooth_connection', 'connected_paired_devices') }}

I use something similar when testing to see if my phone is connected to the bluetooth in my vehicle.

Thanks @finity, this has worked wonderfully :slight_smile:

1 Like