Template sensor help

I understand how to make sensors that get the attribute of another entity. But is it possible to get the attribute name? If it changes…example the tautulli sensor creates an entity with an attribute of each a time user. So say 3 people are watching it would look like …

Attr attr value
John Batman
Joe. Why him
Jake. Deadpool

There are 2 approaches here:

  1. Create template sensors that copy the value of an attribute
  2. Create an automation with a trigger from the template platform and directly act on attribute changes.

An example for the former:

sensor:
  - platform: template
    name: tautulli_john
    entity_id: sensor.tautulli
    value_template: '{{ state_attr("sensor.tautulli" , "John") }}'

You could read the Templating documentation where this is explained.

Thanks for helpin out. I have read those docs many times lol, its the when the attribute name is changing really throws me off i dont understand it quite well enough just yet. I appreciate your help though, that got me actually the value of the atrribute. I wanted to get the name of it, but I can at least just create the automations I wanted now with if statements. its going to be ugly, I didnt want to have to plug each user manually.

For some context…

I have a few remote plex users, when they are watching a movie the tautuli sensors grabs some info and brings it in ha.

Tautuille creates an entity “sensor.tautulli_total”. The state is always a number. the number of people watching.

the attributes when no one is watching:
image
and when someone is watching. when a second person joins it just adds another user right under Dustin

I wnat to create a sensor with just the names of who is watching.

you might be interested in this sensor…

  - platform: template
    sensors:
      watching_plex:
        friendly_name: "Watching Plex"
        value_template: >
          {% if not states.sensor.plex.state == '0' %}
            {%- for attr in states.sensor.plex.attributes %}
              {%- if not attr=="friendly_name" and not attr=="unit_of_measurement"
                                              and not attr=="custom_ui_state_card"
                                              and not attr=="icon"
                                              and not attr=="supported_features"
                                              and not attr=="entity_picture" %}
                  {{attr}} is watching {{states.sensor.plex.attributes[attr]}}
              {%- endif %}
            {%- endfor %}
          {% else %} Watching Plex: {{states.sensor.plex.state}}
          {% endif %}

some background: Print all the attributes and values of Plex sensor

for each player you can add:

  watching_plex_auditorium:
    friendly_name: "Plex Auditorium"
    value_template: >
      {% if states.media_player.plex_auditorium %}
        {% if states.media_player.plex_auditorium.state == 'playing'%} playing
        {% elif states.media_player.plex_auditorium.state == 'idle'%} idle
        {% elif states.media_player.plex_auditorium.state == 'paused'%} paused
        {% elif states.media_player.plex_auditorium.state == 'stopped'%} stopped
        {%  endif %}
      {% else %} Offline
      {% endif %}
    entity_picture_template: >
      {% if states.media_player.plex_auditorium.state == 'playing'%}
        {{states.media_player.plex_auditorium.attributes.entity_picture}}
      {% else %} /local/various/plex.png
      {% endif %}

and have it show the icon of the played stream :wink:

Thanks:) I actually have this as well. It pulls names right from plex, so i get email address’s. With Tautulli it pulls the nicknames

OMG. I swapped out the sensor name with tautullis and got EXACTLY what i have been trying to for days now lol.

Thank you buddy!

1 Like

Alright. One more question I’m giving in. Is it possible to just get the names? Instead on the output of that sensor looking like…

Dustin is watching Batman Joe is watching the league

Have it look like this…

Dustin
Joe

So it’s just names listed on top of each other

Change this line:

              {{attr}} is watching {{states.sensor.plex.attributes[attr]}}

to:

              {{attr}}