Question: Where's the best place to keep and match against a list?

I’d like to create an automation where, if the (bad) song being played on the radio matches a specific string, I trigger an automation. This automation would play a different sound source for a few minutes, just long enough so I’d miss the bad song on the radio.

My question is: Where’s the best place in Home Assistant to keep a list of song title strings that I could match against? And is there a “matches string in list” function like python has which could allow me to loop through the list and check against it?

Probably an input_text helper. That would enable easy on the fly editing.

Yes there is.

{{ 'something' in [ 'a', 'list', 'of', 'things' ] }}

or

{{ 'something' in states('input_text.bad_songs') }}

The input text does not even have to contain a list. Try this in the template editor:

{% set t = "one two three" %}
{{ 'one' in t }}
1 Like

This is an exceptional answer. Thank you, I will go try this out!

Hey @tom_l, as a follow-up question: it turns out input text helpers only store 255 characters – not enough characters! Are there any other helpers in Home Assistant that could store a longer string?

You could try the Dropdown helper. It’s designed for choice lists, but you could make every song a choice, and it looks like you can get back all the options as a list from the options attribute of the helper you create. Not sure how many entries you can have (or their length), so hopefully you don’t have a large number of songs you hate so much that you want to blot them from existence.

1 Like

This worked! Great suggestion. Took me 5 minutes to switch it over, and now my hate can grow and grow.

By the way, I block on bands, not songs, so it’s not that unmaintainable.

1 Like