Need some help with with advanced if statement involving 3 entites

Im trying to create a sensor that will produce a url based on the status of 3 media players.

So i want to display the entity pic on my dashboard, I have this working great with sonos. However Id like the dashboard to display what Im watching if Im not listening to music. And since my directv box says playing all the time, I need the sensor to look first at my sonos entity (media_player.living_room), if that state is playing then grab the token attribute and stop if. If not playing look at media_player.plex_living_room. If that is playing grab that token, if not then display directv media info. Another Caveat is i need a condition to say if media_player.living_room or media_player.plex_living_room is playing and the attribute ‘source’ = TV then keep going.

This is what I have so far, but it is not returning any value. No errors in the log, the sensor shows up in entites, but the state is empty.

- platform: template
  sensors:
    lrplayingart:
      value_template: >-
        {% if is_state('media_player.living_room', 'playing') %}
          {{ states.media_player.living_room.attributes.token}}
        {% elif is_state('media_player.plex_living_room', 'playing') %}
          {{ states.media_player.plex_living_room.attributes.token}}
        {% elif is_state('media_player.liv', 'playing')  %}
          {{ states.media_player.liv.attributes.media_title}}
        {% else %}
            Not playing
        {% endif %}

If I can get this to work, then I will then take that value of the sensor and apped it to my ha url as a template that will go into a camera for the dashboard.

This is what I use now that works great. Solved the caching issue on dashboard .

  - platform: generic
    name: Living Room Sonos
    still_image_url: 'https://xxx.duckdns.org/api/media_player_proxy/media_player.living_room?{{ states.media_player.living_room.attributes.token }}'

anyone that could possibly help out here? I havent been able to make any progress. It seems when my tv is on it grabs that fine, but if it is not playing, it never looks to see if the next media player is…