I’m trying to solve a similar problem to the one here, but I don’t quite understand why my value template conditional doesn’t pass and hoping someone could help me, or point me to some references.
In my case, I’m wanting to check whether my phone is connected to my car via BT as an automation condition. I understand that the connected_paired_devices attribute will return a list. I’m trying to search for my car’s BT MAC address (60:38:0E:54:3C:CA) in the returned list like this but it never works and I don’t understand why (I’m a novice at this):
I always get “Condition did not pass” in the Visual Tester when I manually test (with my phone actively connected to my car of course). I’m guessing the way I’m searching for the MAC Address in the returned list isn’t valid, but I’m not sure of the right/best way to go about it. I’m a little confused as I’ve seen posts where other people used this same method and said it worked for them.
In HA, when I go to the sensor.ant_samsung_s22_sm_s901e_bluetooth_connection entity and check the Attributes, I do see my car’s MAC address (60:38:0E:54:3C:CA) in the list of Connected paired devices.
Any pointers greatly appreciated!
I’m running Home Assistant in a Hyper-V VM:
Core 2024.1.3
Supervisor 2023.12.0
Operating System 11.4
Frontend 20240104.0
Best thing to do in this case is test the value_template with the Developer Tools templating tool to check you receive a simple true / false return value.
A condition always has to be either true or false. And if it’s not true then it defaults to false by definition.
“Value: true” isn’t a valid boolean value. it’s a key value pair string.
the test you are using should work (it doesn’t need to be converted to a string since it already is a string in the attribute) as long as the MAC address string you are looking for is correct.
If the sensor you are using is from the HA Companion app then at some point in the past the string that is used in the “connected_paired_devices” attribute changed to include the device name. So at that time I needed to change my test to this:
"{{ '84:DD:20:AA:FF:EE (TOYOTA Tacoma)' in state_attr('sensor.my_mobile_app_bluetooth_connection', 'connected_paired_devices') }}"
you should check the attributes of your sensor to make sure you are checking for the right entire string not just the MAC portion.
- condition: template
value_template: >-
Value: {{ '28:3D:C2:A4:72:01 (Galaxy Watch5 Pro (7KKW))' in
state_attr('sensor.ant_samsung_s22_sm_s901e_bluetooth_connection',
'connected_paired_devices') }}
and when I test it I still get “Condition did not pass” in the Test so I’m absolutely baffled.
I should mention that I’m using the HA Companion app (2023.12.4-full) on an Android phone (Samsung Galaxy S22) as the source of the sensor.
Thank you for your feedback! This worked and solved my problem!
I’m still a little confused why what I had wasn’t working but clearly I have a lot more learning to do to understand this!