Bluetooth condition

I created an automation to open my garage door if I enter home zone with a condition that my phone is connected to my truck’s bluetooth. I cannot figure out why it is evaluating false.

I saw this known issue, Automation Condition Improperly Evaluates False - #13 by 123, but my first thought is that this is not related. Because the trace details show the state and wanted state are identical.

I’m brand new to HA and this is my first post. Thank you all for your help.

alias: Open Garage Door
description: When entering home and connected to truck bluetooth
trigger:
  - platform: zone
    entity_id: person.andrew
    zone: zone.home
    event: enter
condition:
  - condition: state
    entity_id: sensor.pixel_4a_bluetooth_connection
    attribute: connected_paired_devices
    state: 04:A3:16:7D:74:12 (TOYOTA Tacoma)
action:
  - device_id: a2027347c51c2db0832ff397f64c1b2d
    domain: mobile_app
    type: notify
    title: "[TEST] Garage Door Open"
    message: >-
      If you are seeing this message, the the garage door should have opened
      correctly. Were you entering home and connected to truck bluetooth?
mode: single

Try this:

alias: Open Garage Door
description: When entering home and connected to truck bluetooth
trigger:
  - platform: zone
    entity_id: person.andrew
    zone: zone.home
    event: enter
condition:
  - condition: template 
    value_template: >
      {% set x = state_attr('sensor.pixel_4a_bluetooth_connection', 'connected_paired_devices') %}
      {% set x = x if x is string else x[0] %}
      {{ '04:A3:16:7D:74:12' in x }}
action:
  - device_id: a2027347c51c2db0832ff397f64c1b2d
    domain: mobile_app
    type: notify
    title: "[TEST] Garage Door Open"
    message: >-
      If you are seeing this message, the the garage door should have opened
      correctly. Were you entering home and connected to truck bluetooth?
mode: single

@123
That did it! I don’t fully understand what you did, though. Could you explain it? And why does the visual editor not work in this case? Thank you!

1 Like

If the Automation Editor played any part in causing the problem then I don’t know what it might have been.

  • The Template Condition first retrieves the value of the sensor’s connected_pairs_devices attribute and assigns it to the variable named x.

  • Just in case the retrieved value might be either a string or a list, it checks if it’s a string. If it is then the value of x is used as-is. However, if it’s not a string then it’s assumed to be a list so x is assigned the value of the first item in the list (list items are indexed starting with zero).

  • Finally, the template checks if the string 04:A3'16:7D:74:12 is within the value of x. If it is then the result is true otherwise false.