What in the heck am I missing?

I used the Developer’s Tools template engine with this code:

sensors:
  justin_driving_car:
    value_template: |-
      {% set connect = state_attr('sensor.sm_s918u_bluetooth_connection', 'connected_paired_devices') %}
      {% set car = "['98:67:2E:C9:A6:A5 (Hesh ANC)']" %}
      
       {{connect}}
       {{car}}

      {% if connect == car %}
        Connected
      {% elif connect != car %}
        Not Connected
      {% endif %}

and it gives me this in return:

sensors:
  justin_driving_car:
    value_template: |-
     
      ['98:67:2E:C9:A6:A5 (Hesh ANC)']
      ['98:67:2E:C9:A6:A5 (Hesh ANC)']

              Not Connected

Clearly they’re identical, so it’s gotta be some formatting I’m doing wrong. I only did the {{connect}} and {{car}} lines to show you they’re returning the exact same thing.

Please tell me I’m an idiot and this is simple lol

Check in Dev tools under “States” what the attribute connected_paired_devices for the sensor actually is. Can they be the same?

It’s literally this:
[‘98:67:2E:C9:A6:A5 (Hesh ANC)’]

Should work. Double check that the strings are actually the same without extra spaces or anything.

I’ve got a car driving binary sensor helper. The template code is :

{{(state_attr('sensor.sm_s911b_bluetooth_connection','connected_not_paired_devices')!=None) and ('1C:50:1E:50:AA:29 (DMX5020DABS)' in state_attr('sensor.sm_s911b_bluetooth_connection','connected_paired_devices'))}}

And?
{{ state_attr('sensor.sm_s918u_bluetooth_connection', 'connected_paired_devices')}}

If I see it correctly both values are not a string, but an array containing an identical string. I think it is concluding the array is a different array, even though the contents are the same. Try to compare car[0] and connect[0].

3 Likes

This is probably it. I’m not going to mark a solution because I did a temporary workaround including double sensors (I think now they’re returning both as strings, and not arrays, so it’s showing as True), but I’m guessing this is the answer. Thanks! Once I get back to working on it this weekend, I’ll try this and mark as solution if it worked!

I’ll try and mess with this!

That seems like a great idea, once you have a binary sensor for it, you have a simple way to visualize and automate.

So much easier to just refer to a binary sensor as to or false rather than comparing MAC addresses every time lol