Tautulli REST End Point and custom-button-card

I’m still getting a ton of errors and I’m not sure how to fix it

Did you ever figure this out? I also dont have any images but also dont have any any session.thumbnail entities.

No. I have constant errors and warrings but only from the last sensor #4. None of the others cause me issues, and they are a literal copy and paste so not sure why this is happening.

Hi @XscarfX , @Tmatz and @al_bright -

Can you please share in this thread your latest config files? Please also share any error messages or warnings that you are getting in your logs. I’d be happy to take another look.

PLEASE MAKE SURE TO REMOVE ANY IPs or API KEYS FROM THE CONFIGS - thanks!

I am only getting errors and warnings from the last session currently #5. If i delete session 5 then i get the same errors and warnings for session 4. I added a session then the errors only present for session 5

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:197
integration: Template (documentation, issues)
First occurred: 9:30:36 AM (320 occurrences)
Last logged: 9:54:52 AM

TemplateError('UndefinedError: list object has no element 4') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].relayed }}{%endif%}) renders=139730>' for attribute 'relayed' in entity 'sensor.plex_session_5_tautulli'
TemplateError('UndefinedError: list object has no element 4') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].bandwidth }}{%endif%}) renders=139730>' for attribute 'bandwidth' in entity 'sensor.plex_session_5_tautulli'
TemplateError('UndefinedError: list object has no element 4') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].video_resolution }}{%endif%}) renders=139730>' for attribute 'video_resolution' in entity 'sensor.plex_session_5_tautulli'
TemplateError('UndefinedError: list object has no element 4') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].stream_video_resolution }}{%endif%}) renders=139730>' for attribute 'stream_video_resolution' in entity 'sensor.plex_session_5_tautulli'
TemplateError('UndefinedError: list object has no element 4') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].transcode_decision }}{%endif%}) renders=139730>' for attribute 'transcode_decision' in entity 'sensor.plex_session_5_tautulli'
Logger: homeassistant.helpers.template
Source: helpers/template.py:2629
First occurred: 9:30:36 AM (136012 occurrences)
Last logged: 10:11:52 AM

Template variable error: list object has no element 4 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].relayed }}{%endif%}'
Template variable error: list object has no element 4 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].bandwidth }}{%endif%}'
Template variable error: list object has no element 4 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].video_resolution }}{%endif%}'
Template variable error: list object has no element 4 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].stream_video_resolution }}{%endif%}'
Template variable error: list object has no element 4 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].transcode_decision }}{%endif%}'
sensor:
  - platform: rest
    unique_id: tautulli_activity
    name: Tautulli Activity
    icon: mdi:plex
    scan_interval: 5
    force_update: true
    resource: mydomain.org/tautulli/api/v2?apikey=(apikey here)=get_activity
    method: POST
    headers:
      Content-Type: application/json
    value_template: "{{ value_json.response.result }}"
    json_attributes_path: "$.response.data"
    json_attributes:
      - stream_count
      - sessions
      - stream_count_direct_play
      - stream_count_direct_stream
      - stream_count_transcode
      - total_bandwidth
      - lan_bandwidth
      - wan_bandwidth

template:
  - sensor:
      - unique_id: plex_session_1
        name: Plex Session 1 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 1)%}{{ state_attr('sensor.tautulli_activity','sessions')[0].state }}{%else%}off{%endif%}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].transcode_decision }}{%endif%}
  - sensor:
      - unique_id: plex_session_2
        name: Plex Session 2 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 1)%}{{ state_attr('sensor.tautulli_activity','sessions')[1].state }}{%else%}off{%endif%}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].transcode_decision }}{%endif%}
  - sensor:
      - unique_id: plex_session_3
        name: Plex Session 3 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 1)%}{{ state_attr('sensor.tautulli_activity','sessions')[2].state }}{%else%}off{%endif%}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].transcode_decision }}{%endif%}
  - sensor:
      - unique_id: plex_session_4
        name: Plex Session 4 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 1)%}{{ state_attr('sensor.tautulli_activity','sessions')[3].state }}{%else%}off{%endif%}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].transcode_decision }}{%endif%}
  - sensor:
      - unique_id: plex_session_5
        name: Plex Session 5 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 1)%}{{ state_attr('sensor.tautulli_activity','sessions')[4].state }}{%else%}off{%endif%}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[4].transcode_decision }}{%endif%}

I think I see your problem.

In each of the sensors there is a state line.
For Plex Session 1 it is:

state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 1)%}{{ state_attr('sensor.tautulli_activity','sessions')[0].state }}{%else%}off{%endif%}

Note that in the “if” statement, we’re checking if the length of the main sensor.tautulli_activity sensor is >=1.
What this is doing is checking to see if the array in that main sensor has a length greater than or equal to 1. Meaning that one session is playing.

In the next sensor (Plex Sensor 2) you need to increase this value. You still have it as >= 1, but it needs to be >=2. This indicates that there is 2 or more sessions playing.
You need to increase this number in all of your templates, just like you incremented it for the [0] and [1], etc.

So anytime a single session was playing, it was trying to grab the 2nd, 3rd, 4th and 5th sessions which…technically didn’t exist in the array.

I had pointed this out in my 4/28/23 update, but I’ve added additional clarification in my original post in bold.

God i cant believe i missed that! thank you that was such a simple fix. you are seriously the best!

So I made those edits but still receiving the warnings and errors non stop

Ok - can you share your config/errors again? I’ll take another look.

Everything else works expect the artwork. I have the session thumbnails enabled but when I follow that link the picture is the users pictures. Any idea what I should check?

Also to add this did work until I accidently deleted the card.

Can you give me an example value of the “Plex Session 1” attribute of “grandparent_thumb” or “thumb” when playing something? This would be from the actual entity itself.

here is the config yaml, error messages, and the card. I haven’t had a single issue with the card though its been working flawlessly

type: custom:auto-entities
filter:
  exclude:
    - state: unknown
    - state: unavailable
    - state: 'off'
  include:
    - entity_id: '*plex*session*'
      options:
        entity: this.entity_id
        type: custom:button-card
        variables:
          entity: this.entity_id
        custom_fields:
          picture:
            card:
              type: picture
              image: |
                [[[
                  if (states[variables.entity].attributes.grandparent_thumb != ''){
                    return "https://mydomain.org/tautulli/api/v2?apikey=APIKEY&cmd=pms_image_proxy&img=" + states[variables.entity].attributes.grandparent_thumb + "&amp;width=300&amp;height=450&amp;fallback=poster&amp;refresh=true";
                  } else {
                    if (states[variables.entity].attributes.thumb != ''){
                      return "https://mydomain.orf/tautulli/api/v2?apikey=APIkey&cmd=pms_image_proxy&img=" + states[variables.entity].attributes.thumb + "&amp;width=300&amp;height=450&amp;fallback=poster&amp;refresh=true"                    
                    } else {
                      return states['sensor.' + states[variables.entity].attributes.user + '_session_thumbnail'].state
                    }
                  } 
                ]]]
              card_mod:
                style: |
                  ha-card {
                    box-shadow: 0;
                    border-radius: 0;
                    margin: 5px 0 0 -5px;
                  }
                  ha-card img {
                    min-height: 100px;
                    min-width: 100px;
                  }
          bar:
            card:
              type: custom:bar-card
              entities:
                - entity: this.entity_id
              attribute: progress_percent
              unit_of_measurement: '%'
              positions:
                icon: 'off'
                indicator: 'off'
                name: inside
              height: 19px
              color: |
                [[[
                   if (states[variables.entity].state == 'playing') {
                  return '#2986cc';
                } else if (states[variables.entity].state == 'paused') {
                 return '#e49f29';
                } else {
                 return '#000000'; // Default color if neither playing nor paused
                }
                ]]]
              card_mod:
                style: |-
                  ha-card {
                    --ha-card-background: none;
                    border: none;
                    box-shadow: none;
                  }
                  ha-card #states {
                    padding: 0;
                  }
                  bar-card-currentbar, bar-card-backgroundbar {
                    border-radius: 5px;
                    left: 0;
                  }
                  bar-card-name {
                    margin-left: 3%;
                    text-shadow: 1px 1px 1px #0003;
                  }
                  bar-card-value {
                    margin-right: 3%;
                    text-shadow: 1px 1px 1px #0003;
                  }
          user: |
            [[[
              return "<b>" + states[variables.entity].attributes.user + "</b>"
            ]]]
          title: |
            [[[
              if (states[variables.entity].state == 'playing') {
                return "<ha-icon icon='mdi:play' style='width: 15px; height: 15px; position: relative; top: -2px;'></ha-icon> " + states[variables.entity].attributes.full_title;
              } else {
                if (states[variables.entity].state == 'paused') {
                  return "<ha-icon icon='mdi:pause' style='width: 15px; height: 15px; position: relative; top: -2px;'></ha-icon> " + states[variables.entity].attributes.full_title;
                } else {
                  return states[variables.entity].attributes.full_title;
                }
              }

            ]]]
          stream_label: <b>Stream</b>
          stream: |
            [[[
              return states[variables.entity].attributes.video_resolution + " > " + states[variables.entity].attributes.transcode_decision + " > " +states[variables.entity].attributes.stream_video_resolution + ""
            ]]]
          product_label: <b>Product</b>
          product: |
            [[[
              return states[variables.entity].attributes.product
            ]]]
          media_detail: |
            [[[
              if(states[variables.entity].attributes.media_type == 'movie') {
                return "<ha-icon icon='mdi:filmstrip' style='width: 15px; height: 15px; position: relative; top: -2px;'></ha-icon> (" + states[variables.entity].attributes.year + ")";
              } else {
                return "<ha-icon icon='mdi:television-classic' style='width: 15px; height: 15px; position: relative; top: -2px;'></ha-icon> S" + states[variables.entity].attributes.parent_media_index + " • E" + states[variables.entity].attributes.media_index;
              }
            ]]]
          bandwidth_label: <b>Bandwidth</b>
          bandwidth: |
            [[[
              var bytes = states[variables.entity].attributes.bandwidth * 1000;
              var sizes = ['Bytes', 'Kbps', 'Mbps', 'Gbps', 'Tbps'];
              if (bytes == 0) return 'n/a';
              var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1000)));
              if (i == 0) return bytes + ' ' + sizes[i];
              return (bytes / Math.pow(1000, i)).toFixed(1) + ' ' + sizes[i];
            ]]]
        card_mod:
          style: |
            ha-card {
              box-shadow: 0;
              padding: 0;
              margin: 0;
              border: 0;
            }
            ha-card #container {
            margin: 5px 0 0 0;
            }
            #name {
              display:none;
            }
        styles:
          card:
            - height: 100x
            - padding: 0
          custom_fields:
            bar:
              - text-transform: capitalize
              - font-size: 13px
            user:
              - text-align: end
              - font-size: 15px
            title:
              - text-align: start
              - font-size: 13px
            stream:
              - text-transform: capitalize
              - text-align: start
              - font-size: 13px
            product:
              - text-transform: capitalize
              - text-align: start
              - font-size: 13px
            player:
              - text-transform: capitalize
              - text-align: start
              - font-size: 13px
            location:
              - text-transform: uppercase
              - text-align: start
              - font-size: 13px
            media_detail:
              - text-transform: uppercase
              - text-align: start
              - font-size: 13px
            bandwidth:
              - text-transform: capitalize
              - text-align: start
              - font-size: 13px
            product_label:
              - text-transform: uppercase
              - text-align: end
              - font-size: 10px
            player_label:
              - text-transform: uppercase
              - text-align: end
              - font-size: 10px
            stream_label:
              - text-transform: uppercase
              - text-align: end
              - font-size: 10px
            location_label:
              - text-transform: uppercase
              - text-align: end
              - font-size: 10px
            bandwidth_label:
              - text-transform: uppercase
              - text-align: end
              - font-size: 10px
          grid:
            - grid-template-areas: |
                "picture product_label product"
                "picture player_label player"
                "picture stream_label stream"
                "picture location_label location"
                "picture bandwidth_label bandwidth"
                "picture bar bar"
                "picture title title"
                "picture media_detail user"
            - grid-template-columns: 1fr 60px 3fr
            - grid-gap: 5px 10px
card:
  type: vertical-stack
card_param: cards
sensor:
  - platform: rest
    unique_id: tautulli_activity
    name: Tautulli Activity
    icon: mdi:plex
    scan_interval: 5
    force_update: true
    resource: https://mydomain.org/tautulli/api/v2?apikey=APIKEY&cmd=get_activity
    method: POST
    headers:
      Content-Type: application/json
    value_template: "{{ value_json.response.result }}"
    json_attributes_path: "$.response.data"
    json_attributes:
      - stream_count
      - sessions
      - stream_count_direct_play
      - stream_count_direct_stream
      - stream_count_transcode
      - total_bandwidth
      - lan_bandwidth
      - wan_bandwidth
template:
  - sensor:
      - unique_id: plex_session_1
        name: Plex Session 1 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 1)%}{{ state_attr('sensor.tautulli_activity','sessions')[0].state }}{%else%}off{%endif %}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[0].transcode_decision }}{%endif%}
  - sensor:
      - unique_id: plex_session_2
        name: Plex Session 2 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 2)%}{{state_attr('sensor.tautulli_activity','sessions')[1].state }}{%else%}off{%endif %}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[1].transcode_decision }}{%endif%}
  - sensor:
      - unique_id: plex_session_3
        name: Plex Session 3 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 3)%}{{ state_attr('sensor.tautulli_activity','sessions')[2].state }}{%else%}off{%endif%}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[2].transcode_decision }}{%endif%}
  - sensor:
      - unique_id: plex_session_4
        name: Plex Session 4 (Tautulli)
        icon: mdi:plex
        state: >
          {% if (state_attr('sensor.tautulli_activity','sessions')|length >= 4)%}{{ state_attr('sensor.tautulli_activity','sessions')[3].state }}{%else%}off{%endif%}
        attributes:
          user: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].user }}{%endif%}
          progress_percent: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].progress_percent }}{%endif%}
          media_type: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].media_type }}{%endif%}
          full_title: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].full_title }}{%endif%}
          grandparent_thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].grandparent_thumb }}{%endif%}
          thumb: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].thumb }}{%endif%}
          parent_media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].parent_media_index }}{%endif%}
          media_index: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].media_index }}{%endif%}
          year: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].year }}{%endif%}
          product: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].product }}{%endif%}
          player: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].player }}{%endif%}
          device: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].device }}{%endif%}
          platform: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].platform }}{%endif%}
          location: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].location }}{%endif%}
          ip_address: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].ip_address }}{%endif%}
          ip_address_public: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].ip_address_public }}{%endif%}
          local: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].local }}{%endif%}
          relayed: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].relayed }}{%endif%}
          bandwidth: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].bandwidth }}{%endif%}
          video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].video_resolution }}{%endif%}
          stream_video_resolution: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].stream_video_resolution }}{%endif%}
          transcode_decision: >
            {% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[3].transcode_decision }}{%endif%}
2 more sensors after this
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:197
integration: Template (documentation, issues)
First occurred: 11:48:47 AM (132 occurrences)
Last logged: 11:48:47 AM

TemplateError('UndefinedError: list object has no element 5') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].relayed }}{%endif%}) renders=4>' for attribute 'relayed' in entity 'sensor.plex_session_6_tautulli'
TemplateError('UndefinedError: list object has no element 5') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].bandwidth }}{%endif%}) renders=4>' for attribute 'bandwidth' in entity 'sensor.plex_session_6_tautulli'
TemplateError('UndefinedError: list object has no element 5') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].video_resolution }}{%endif%}) renders=4>' for attribute 'video_resolution' in entity 'sensor.plex_session_6_tautulli'
TemplateError('UndefinedError: list object has no element 5') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].stream_video_resolution }}{%endif%}) renders=4>' for attribute 'stream_video_resolution' in entity 'sensor.plex_session_6_tautulli'
TemplateError('UndefinedError: list object has no element 5') while processing template 'Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].transcode_decision }}{%endif%}) renders=4>' for attribute 'transcode_decision' in entity 'sensor.plex_session_6_tautulli'
Logger: homeassistant.helpers.template
Source: helpers/template.py:2652
First occurred: 11:48:47 AM (264 occurrences)
Last logged: 11:48:47 AM

Template variable error: list object has no element 5 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].relayed }}{%endif%}'
Template variable error: list object has no element 5 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].bandwidth }}{%endif%}'
Template variable error: list object has no element 5 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].video_resolution }}{%endif%}'
Template variable error: list object has no element 5 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].stream_video_resolution }}{%endif%}'
Template variable error: list object has no element 5 when rendering '{% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].transcode_decision }}{%endif%}'Logger: homeassistant.helpers.event
Source: helpers/template.py:606
First occurred: 11:48:47 AM (132 occurrences)
Last logged: 11:48:47 AM
Error while processing template: Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].relayed }}{%endif%}) renders=2>
Error while processing template: Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].bandwidth }}{%endif%}) renders=2>
Error while processing template: Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].video_resolution }}{%endif%}) renders=2>
Error while processing template: Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].stream_video_resolution }}{%endif%}) renders=2>
Error while processing template: Template<template=({% if this.state !='off'%}{{ state_attr('sensor.tautulli_activity','sessions')[5].transcode_decision }}{%endif%}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 604, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2639, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 327, in getattr
    value = getattr(obj, attribute)
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2671, in _fail_with_undefined_error
    return super()._fail_with_undefined_error(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: list object has no element 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 716, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 606, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: list object has no element 0

Im getting the below error in my logs. ive done all the above

Logger: homeassistant.components.recorder.db_schema
Source: components/recorder/db_schema.py:616
integration: Recorder (documentation, issues)
First occurred: 21:12:54 (369 occurrences)
Last logged: 21:23:05

State attributes for sensor.tautulli_activity exceed maximum size of 16384 bytes. This can cause database performance issues; Attributes will not be stored

So this one seems like a recorder issue with storing the attributes. I’m not sure you’d want the history on this because it’s not really that useful? Like something like kWh or temperature makes sense for trending data in recorder. Not this sensor.

I’d look into the “exclude:” for recorder and exclude the main sensor and all the smaller ones. Or better yet, only “include:” certain domains like I have.

i will look into this, thank you

Hi there! So the image has a nested IF statement. First it checks to see if the grandparent_thumb is empty, if it is, then it checks if the thumb is empty - and if that is true, it’ll return the user’s session thumbnail (their pic/image).
What is weird is that you are seeing those attributes, so it should be showing at least one of those.
If you replace the domain and key in the link below, do you see the thumb?

https://[YOUR DOMAIN]/api/v2?apikey=[YOUR API KEY HERE]&cmd=pms_image_proxy&img=/library/metadata/23376/thumb/1719055178&width=300&height=450&fallback=poster&refresh=true

In your shared code, you have “2 more sensors after this” at the bottom of the template sensors.

Can you paste the sensor for plex_session_6? Sounds like that one needs to be updated in that “length >=” portion so that its looking for a length >= 5

OK! In doing some testing, and looking at my logs, I found another bug with the template sensors.
Basically was watching a serial show, and during the countdown to the “next” episode, saw errors in my log. It looks like it was trying to pull null values slightly before the state was updated.
I’ve figured out a patch, and I’m going to rework all 10 plex template sensors. I’ll add ALL 10 to the original post, since asking folks to copy/paste and adjust values seems to cause some issues. Might as well just give you the whole thing :slight_smile: - makes this fix easier to update too!
Will be posting shortly…

1 Like