White Noise Machine Spotify Song

Hi everyone,

I’m relatively new to home assistant. What I want to do is create a white noise machine automation using a Spotify White Noise Track being played through a Google Nest Mini. I was able to create the automation and it works fine and can be launched through Home Assistant.

But what I want to do now is create a button that will indicate whether or not the white noise track is playing. I want the icon to show up in a different color whether or not it is playing. I created this template and it works and arrives at True in the Developer Tools Template Editor. But I can’t get it to work as part of my config.

{% set variable = state_attr('media_player.den_speaker', 'media_title')%}
{% for media_title in variable %}
  {% if 'Stuck In The Middle With You' in variable %}
   True
  {% else %}
   False
  {% endif %}
{% endfor %}

However I can’t get it to work in my configuration.yaml

binary_sensor:
  - platform: template
    sensors:
      stuckinthemiddle:
        value_template: >- 
          {% set variable = state_attr('media_player.den_speaker', 'media_title')%}
          {% for media_title in variable %}
            {% if 'Stuck In The Middle With You' in variable %}
              True
            {% else %}
              False
            {% endif %}
          {% endfor %}

The Sensor is showing up in my entities but it is showing up as off. Even while the song is playing.

Any help or guidance would be appreciated.