HI,
For my plex sensors, I use these 5 individual but almost the same template sensors:
watching_plex_safari:
friendly_name: 'Plex Safari'
value_template: >
{% if states('media_player.plex_safari') %}
{% if states('media_player.plex_safari')in ['playing','idle','paused','stopped']%}
{{states('media_player.plex_safari')}}
{% endif %}
{% else %} Offline
{% endif %}
entity_picture_template: >
{% if states('media_player.plex_safari') == 'playing' %}
{{state_attr('media_player.plex_safari','entity_picture')}}
{% else %} /local/various/plex.png
{% endif %}
watching_plex_ipad_red:
friendly_name: 'Plex iPad red'
value_template: >
{% if states('media_player.plex_ipad_red') %}
{% if states('media_player.plex_ipad_red')in ['playing','idle','paused','stopped']%}
{{states('media_player.plex_ipad_red')}}
{% endif %}
{% else %} Offline
{% endif %}
entity_picture_template: >
{% if states('media_player.plex_ipad_red') == 'playing' %}
{{state_attr('media_player.plex_ipad_red','entity_picture')}}
{% else %} /local/various/plex.png
{% endif %}
watching_plex_telefoon:
friendly_name: 'Plex Telefoon'
value_template: >
{% if states('media_player.plex_telefoon') %}
{% if states('media_player.plex_telefoon')in ['playing','idle','paused','stopped']%}
{{states('media_player.plex_telefoon')}}
{% endif %}
{% else %} Offline
{% endif %}
entity_picture_template: >
{% if states('media_player.plex_telefoon') == 'playing' %}
{{state_attr('media_player.plex_telefoon','entity_picture')}}
{% else %} /local/various/plex.png
{% endif %}
watching_plex_xbox:
friendly_name: 'Plex Xbox-one'
value_template: >
{% if states('media_player.plex_xbox') %}
{% if states('media_player.plex_xbox')in ['playing','idle','paused','stopped']%}
{{states('media_player.plex_xbox')}}
{% endif %}
{% else %} Offline
{% endif %}
entity_picture_template: >
{% if states('media_player.plex_xbox') == 'playing' %}
{{state_attr('media_player.plex_xbox','entity_picture')}}
{% else %} /local/various/plex.png
{% endif %}
watching_plex_auditorium:
friendly_name: 'Plex Auditorium'
value_template: >
{% if states('media_player.plex_auditorium') %}
{% if states('media_player.plex_auditorium')in ['playing','idle','paused','stopped']%}
{{states('media_player.plex_auditorium')}}
{% endif %}
{% else %} Offline
{% endif %}
entity_picture_template: >
{% if states('media_player.plex_auditorium') == 'playing' %}
{{state_attr('media_player.plex_auditorium','entity_picture')}}
{% else %} /local/various/plex.png
{% endif %}
As you can see the only difference is in the name, and the entities named in the templates.
Could I compress this to 1 sensor creating these automatically, with a for loop
referencing the names?
for plex entities with name in [‘safari’,‘iPad_red’,‘telefoon’,‘xbox’,‘auditorium’]
create sensor:
watching_plex_{{name}}:
friendly_name: 'Plex {{name}}'
value_template: >
{% if states('media_player.plex_{{name}}') %}
{% if states('media_player.plex_{{name}} ') in ['playing','idle','paused','stopped']%}
{{states('media_player.plex_{{name}} ')}}
{% endif %}
{% else %} Offline
{% endif %}
entity_picture_template: >
{% if states('media_player.plex_{{name}}') == 'playing' %}
{{state_attr('media_player.plex_{{name}} '','entity_picture')}}
{% else %} /local/various/plex.png
{% endif %}
above won’t work since it uses a template in a template, but is only to try to show what i am looking for.
@petro what would you suggest?
thanks for having a look