Thanks. My thought is that it’s a UI bug too, but I need to test it out in pure YAML. I hesitate to use that as a permanent solution because I’m making an effort to use more UI Automations where I can. I’ll raise the issue as a possible bug, if necessary.
Can the condition statement be modified in anyway, perhaps to easily strip out the colons before evaluating?
Thanks for heads up on the bug. I ignored it and sucessfully tested in Dev Tools… Unfortunately, in real life testing, the condition is still evaluating false!
Executed: August 5, 2022 at 6:44:39 AM
Result:
result: false
conditions/0
Executed: August 5, 2022 at 6:44:39 AM
Result:
result: false
entities:
- sensor.jason_s_phone_bluetooth_connection
Try this version; it’s essentially equivalent to tom_l’s suggestion to use replace but employs slugify.
It uses the slugify filter to convert the the value of connected_paired_devices to a slug (basic ASCII characters only) and then compares it to the desired string but represented as a slug.
By golly, you’ve helped me find the actual error! And, unfortunately, exposed a few problems…
Testing in the Dev Tools, I get the following error: “TypeError: decoding to str: need a bytes-like object, list found.” Seems this is returning a list (of one item), which is why I may have kept getting an evaluation of false.
I can reference the list’s first element, but if doesn’t exist (i.e., paired connection not present) I will still get an error. Also, there exists the possibility that I get get a list with an array length >1. Probably unlikely, but it exists. Therefore, a full and robust solution would require searching an array of undetermined length provided that its length is >0. Ugh.
Is it better to iteratively search the array or concatenate the elements and search for a substring? I’d think the latter because I can this disregard zero lengths.
Also, for anyone else following along, slugify strips CAPS. This is not apparent in my bogus sequentially numbered MAC address.
That’s definitely why all of the suggested comparison techniques failed to find a matching value.
Out of curiosity, what originally led you to believe the received value was simply a string?
What does the following template report in the Template Editor? Ensure it’s the only line you paste into the editing window (no other information or even blank lines).
Honestly, it was just ignorance, really… I didn’t know and didn’t take the time to determine the datatype. However, with hindsight being what it is, in my original post, you’ll see that the trace DID place a dash in the state, which I assume did indicate that it was returning a list of 1. We all missed that!
With no connections, I get the following results:
[]
Using another attribute of this entity (paired_devices, meaning all stored pairings) with listed items, I get the following: