Help with a template sensor to find a string in an attribute

Hi there

I want an automation that is only executed when a bluetooth device is connected to my smartphone. I have enabled the sensor but i’m struggelin with the template and condition in my automation.
When i try the template

{{ '38:C0:44:3B:BB:CA' in state_attr("sensor.sm_g996b_bluetooth_connection", "connected_paired_devices") }}

this renders true or false and is working. But when i try to set this as a condition like this:

  - condition: template
    value_template: {{ '38:C0:96:3B:BB:AC' in state_attr("sensor.sm_g996b_bluetooth_connection", "connected_paired_devices") }}

it throws me an error when checking my configuration. Can anyone point me the right direction of the syntax?

Thanks Mike

It’s probably because of the :'s in the mac address, try it with quotes:

  - condition: template
    value_template: "{{ '38:C0:96:3B:BB:AC' in state_attr('sensor.sm_g996b_bluetooth_connection', 'connected_paired_devices') }}"

(it will probably replace the " with ’ when you save it)

Yes you’re right. Did not think it was that simple, many thanks!!!