Smarter way of checking if mediaplayers are active?

I’m working on some buttons for various media control, and I keep on writing stuff like this:

 "{{
        (
          is_state('media_player.all', 'playing') or 
          is_state('media_player.all', 'paused')
        )
        and not  
        (
          is_state('media_player.tramsosaurus', 'playing') or
          is_state('media_player.tramsosaurus', 'paused')
        )
      }}"

I can’t use state off, since chromecasts also have the state “Idle” is there any better way to check for attributes or can you create you own functions somehow? I know a little bit of python :slight_smile:

Not sure if this is what you’re looking for, but something like this is a little simpler:

states('media_player.all') in ['playing', 'paused'] and
states('media_player.tramsosaurus') not in ['playing', 'paused']

that’s exactly what i have been looking for, I have been googling for jinja2 arrays and such but didn’t find anything…

1 Like

It’s actually testing for inclusion in a list. Check out:

http://jinja.pocoo.org/docs/dev/templates/#other-operators

ah, ok, they are called lists, not arrays!