Not showing all Template sensors after 2023.6

Hi all,
Quick question, i got this sensors that work fine from 1 to 5 but 6 and 7 shows unavailable.

#################################################
########### Home Cinema Sensors KODI  ###########
#################################################

##Movie 1
  - platform: template
    sensors:
      kodi_recently_movies_1:
        friendly_name: "Kodi Movie 1 Poster"
        icon_template: mdi:movie-roll
        value_template: >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[2].split('poster": "')[1].split('"},')[0]}}

      kodi_recently_movies_name_1:
        friendly_name: "Kodi Movie 1 name"
        icon_template: mdi:movie-roll
        value_template: >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[2].split('"title": "')[1].split('",')[0]}} 

      kodi_recently_movies_2:
        friendly_name: "Kodi Movie 2"
        icon_template: mdi:movie-roll
        value_template:  >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[3].split('poster": "')[1].split('"},')[0]}}

      kodi_recently_movies_3:
        friendly_name: "Kodi Movie 3"
        icon_template: mdi:movie-roll
        value_template:  >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[4].split('poster": "')[1].split('"},')[0]}}

      kodi_recently_movies_4:
        friendly_name: "Kodi Movie 4"
        icon_template: mdi:movie-roll
        value_template:  >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[5].split('poster": "')[1].split('"},')[0]}}
        
      kodi_recently_movies_5:
        friendly_name: "Kodi Movie 5"
        icon_template: mdi:movie-roll
        value_template:  >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[6].split('poster": "')[1].split('"},')[0]}}

      kodi_recently_movies_6:
        friendly_name: "Kodi Movie 6"
        icon_template: mdi:movie-roll
        value_template:  >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[7].split('poster": "')[1].split('"},')[0]}}
        
      kodi_recently_movies_7:
        friendly_name: "Kodi Movie 7"
        icon_template: mdi:movie-roll
        value_template:  >-
          {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[8].split('poster": "')[1].split('"},')[0]}}

image
the information exist
image

so why is it limiting me to 5 sensors?

Thank you all

Are there any related errors in Setings → System → Logs?

Yes i do, here:

Logger: homeassistant.helpers.event
Source: core.py:1255
First occurred: 10 June 2023 at 23:01:53 (3 occurrences)
Last logged: 10 June 2023 at 23:01:53

Error while dispatching event for sensor.kodi_recently_added_movies to <Job track state_changed event {'sensor.kodi_recently_added_movies'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[7].split('poster": "')[1].split('"},')[0]}}) renders=6>: <RenderInfo Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[7].split('poster": "')[1].split('"},')[0]}}) renders=6> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'sensor.kodi_recently_added_movies'}) rate_limit=None has_time=False exception=None is_static=False>, Template<template=(mdi:movie-roll) renders=4>: <RenderInfo Template<template=(mdi:movie-roll) renders=4> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset() rate_limit=None has_time=False exception=None is_static=True>}>>>
Error while dispatching event for sensor.kodi_recently_added_movies to <Job track state_changed event {'sensor.kodi_recently_added_movies'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[8].split('poster": "')[1].split('"},')[0]}}) renders=6>: <RenderInfo Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[8].split('poster": "')[1].split('"},')[0]}}) renders=6> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'sensor.kodi_recently_added_movies'}) rate_limit=None has_time=False exception=None is_static=False>, Template<template=(mdi:movie-roll) renders=4>: <RenderInfo Template<template=(mdi:movie-roll) renders=4> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset() rate_limit=None has_time=False exception=None is_static=True>}>>>
Error while dispatching event for sensor.kodi_recently_added_movies to <Job track state_changed event {'sensor.kodi_recently_added_movies'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[9].split('poster": "')[1].split('"},')[0]}}) renders=6>: <RenderInfo Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[9].split('poster": "')[1].split('"},')[0]}}) renders=6> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'sensor.kodi_recently_added_movies'}) rate_limit=None has_time=False exception=None is_static=False>, Template<template=(mdi:movie-roll) renders=4>: <RenderInfo Template<template=(mdi:movie-roll) renders=4> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset() rate_limit=None has_time=False exception=None is_static=True>}>>>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 274, in _async_dispatch_entity_id_event
    hass.async_run_hass_job(job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 618, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1154, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 618, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 349, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 711, in _async_write_ha_state
    hass.states.async_set(entity_id, state, attr, self.force_update, self._context)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1637, in async_set
    state = State(
            ^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1255, in __init__
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.kodi_recently_movies_6. State max length is 255 characters.
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:380
First occurred: 10 June 2023 at 23:01:30 (12 occurrences)
Last logged: 10 June 2023 at 23:01:30

TemplateError('UndefinedError: list object has no element 5') while processing template 'Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[5].split('poster": "')[1].split('"},')[0]}}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.kodi_recently_movies_4'
TemplateError('UndefinedError: list object has no element 6') while processing template 'Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[6].split('poster": "')[1].split('"},')[0]}}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.kodi_recently_movies_5'
TemplateError('UndefinedError: list object has no element 7') while processing template 'Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[7].split('poster": "')[1].split('"},')[0]}}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.kodi_recently_movies_6'
TemplateError('UndefinedError: list object has no element 8') while processing template 'Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[8].split('poster": "')[1].split('"},')[0]}}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.kodi_recently_movies_7'
TemplateError('UndefinedError: list object has no element 9') while processing template 'Template<template=({{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[9].split('poster": "')[1].split('"},')[0]}}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.kodi_recently_movies_8'
Logger: homeassistant.components.recorder.db_schema
Source: components/recorder/db_schema.py:585
Integration: Recorder (documentation, issues)
First occurred: 10 June 2023 at 23:01:40 (6 occurrences)
Last logged: 10 June 2023 at 23:01:53

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

It looks like the URL for the poster contains more than 255 characters so the state can’t be displayed or stored.

1 Like

Is there any way around it?

no. the state is always limited to 255 characters.

you can store longer strings in an entity’s attributes but I don’t know if that will help you.

do you know how i could make it in to a attribute?
like:
json_attributes:
- “url”

in case anyone has the same question, here is the working sensor:

  - platform: template
    sensors:
      kodi_recently_movies_1:
        value_template: 'ok'
        attribute_templates:      
          poster: >- 
             {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[2].split('poster": "')[1].split('"},')[0]}}
          name: >- 
            {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[2].split('"title": "')[1].split('",')[0]}}
          fanart: >- 
            {{ state_attr('sensor.kodi_recently_added_movies', 'data').split('{')[2].split('poster": "')[1].split('"},')[0]}}