Template sensor that will change to driving based on bluetooth connection in car

I copied a template sensor from a blog that shows my current room when i the house and home or away when I’m not. Now i want to change the template sensor to “driving” if i’m connected to my car. MAC addess contains the C2:D2 below. I think I have something wrong in my if elif else statements. could someone help me out please? thanks.

template:
  - sensor:
      - unique_id: "maciek_location"
        attributes:
          friendly_name: "maciek's Location"
          entity_picture: "/local/image/maciek.jpg"
        state: >-
          {% if states('sensor.maciek_current_room') != 'unknown' and states('sensor.maciek_current_room') != 'unavailable'%}
            {{ states('sensor.maciek_current_room') }}
          {% elif '2C:2D' in state_attr('sensor.rmx2170_bluetooth_connection', 'connected_paired_devices') %}
            {{ states('person.maciek').replace('not_home', 'Driving').title() }}
          {% else %}
            {{ states('person.maciek').replace('not_home', 'Away').title() }}
          {% endif %}

You output the same text from your presence instead of “driving”?

The attribute connected_paired_devices is always a list and can contain multiple strings, so it is better to use:

{% elif state_attr('sensor.rmx2170_bluetooth_connection', 'connected_paired_devices') is search('2C:2D') %}

sorry, typo, when the bluetooth check is true it should output “driving”. right now, when I’m not in one of the rooms it says Away, like it did before i added the elif statement. the rest of the code is from that blog post and worked perfectly.

This worked! thank you. much appreciated.

there is actually a sensor that has in_vehicle as a state, although probably not as precise as the bluetooth sensor :slight_smile:

https://companion.home-assistant.io/docs/core/sensors#activity-sensors