Plex shows even though 'unavailable' set in state_not

while specifically setting the condition:


  - type: conditional
    conditions:
      - entity: media_player.plex_telefoon
        state_not:
          - 'unavailable'
    card:
      type: media-control
      entity: media_player.plex_telefoon

this happens:

43

Is this a plex bug? Or is my config not correct.

added to that, if the system restarts and no media_player is available at all, (and it isnt unavailable either then) this results in the yellow card in the frontend.

If the device is not in the state machine, this won’t work. Change the condition to state and list the states.

thanks Petro, seems reasonable.

still, using this:

  - type: media-control
    entity: media_player.spotify

  - type: conditional
    conditions:
      - entity: media_player.plex_telefoon
        state:
          - 'playing'
          - 'paused'

wont show the player at all, while it in visible in the states, and the

  - type: entity-filter
    show_empty: false
    entities:
      - media_player.plex_telefoon
    state_filter:
      - 'on'
      - playing
      - paused

shows it alright

using this:

  - type: conditional
    conditions:
      - entity: media_player.plex_telefoon
        state: 'playing'
      - entity: media_player.plex_telefoon
        state: 'paused'

doesnt work either, but using only the ‘playing’ condition makes it appear

Well it depends on what the media player places in the main state. For example, my media player only has on/off as states.

seems we can’t use a list for the state condition, but can’t use multiple conditions for the same entity either, which is a bit silly especially with media_players.

would be very nice it these native cards would use the same logic/syntax…

this explains it I fear:

Note: Conditions with more than one entity are treated as an ‘and’ condition. This means that for the card to show, all entities must meet the state requirements set.

cant have multiple conditions for 1 entity…

Just make a is_visible sensor:

binary_sensor:
- platform: template
  sensors:
    plex_telefoon_is_visible:
      value_template: >
        {{ states('media_player.plex_telefoon') in ['on', 'playing', 'paused'] }}
  - type: conditional
    conditions:
      - entity: binary_sensor.plex_telefoon_is_visible
        state: 'on'

EDIT: It’s always better to have the backend do the work anyways. Then you’ll always know where to look to make changes.

1 Like

thanks, nice idea indeed.
It is what I find myself doing all the time these days… using backend logic, specifically made, to use in the Lovelace frontend cards that offer but limited possibilities, or unexpected behavior :wink:

still to get back to my first post, that would seem a bug. state was clearly showing ‘unavailable’ so it shouldn’t have been displayed in the frontend.

that doesn’t mean that’s the state inside the state machine. It’s most likely the string ‘None’.

that would then be a fine illustration of unexpected behavior… needing to use state_not: ‘none’ when in fact showing ‘unavailable’.

Ill give it a try and see what happens.

it only shows up as unavailable if it’s unavailable in the states page (i.e. unavailable, but in the state machine). If the device doesn’t show up at all in the states page, then nothing will work.

can confirm this to work:

binary_sensor:
  - platform: template
    sensors:
      plex_telefoon_available:
        friendly_name: Plex telefoon available
        value_template: >
          {{states('media_player.plex_telefoon') in ['playing','paused','idle','stopped'] }}
        entity_picture_template: >
          {% if states('media_player.plex_telefoon') in ['playing','paused'] %}
            {{state_attr('media_player.plex_telefoon','entity_picture')}}
          {% else %} /local/various/plex.png
          {% endif %}

with:

  - type: conditional
    conditions:
      - entity: binary_sensor.plex_telefoon_available
        state: 'on'
    card:
      type: media-control
      entity: media_player.plex_telefoon

13

Thank you. I can confirm this works correctly. However, it’s a bit of a hassle to do this for every single Plex media player. I have 10 of them… and, regularly add new plex players.

It’s significantly less hassle to just make cards without having to also create respective binary sensors in the configuration and restart Home Assistant for the binary sensor templates to take in effect. Is there a way to at least not restart Home Assistant after adding binary sensors in the configuration file?

use the template.reload service

1 Like

why not use an auto-entities card, no more need to create anything:

  - type: custom:auto-entities
    show_empty: false
    card:
      type: entities
      title: Plex Playing
    filter:
      include:
        - entity_id: 'media_player.plex*'
          state: /playing|paused|'on'/
          options:
            type: custom:hui-media-control-card

or list them like:

  - type: custom:auto-entities
    show_empty: false
    card:
      type: entities
      title: Plex Playing template
    filter:
      include:
        - entity_id: 'media_player.plex*'
          state: /playing|paused|'on'/
          options:
            type: custom:template-entity-row
            state: >
              {% set player = config.entity %}
              {%- for attr in states[player].attributes %}
                {%- if not attr in ['media_content_id','icon','entity_picture',
                                    'hide_attributes','media_position_updated_at',
                                    'is_volume_muted','username','friendly_name',
                                    'supported_features'] %}
                {{states[player].attributes[attr]}}
                {%- endif %}
              {% endfor %}
            secondary: >
              {{state_attr(config.entity,'username')}}
          sort:
            method: name

or play with the template some more:

            state: >
              {% set player = config.entity %}
              {%- for attr in states[player].attributes %}
                {%- if not attr in ['media_content_id','icon','entity_picture',
                                    'hide_attributes','media_position_updated_at',
                                    'media_duration','media_position','player_source',
                                    'media_content_rating',
                                    'is_volume_muted','username','friendly_name',
                                    'volume_level','supported_features'] %}
                {{attr|title|replace('_',' ')}}: {{states[player].attributes[attr]|title}}
                {%- endif %}
              {% endfor %}