Many many logs from homeassistant.helpers.template

Hello,

I am using Home Assistant version 2026.2.0.

I am getting the following message in the log file every second and cannot figure out where it is coming from. Can you help me?

Logger: homeassistant.helpers.template

Source: helpers/template/init.py:1757

First occurred: 1:44:27 p.m. (73009 occurrences)

Last logged: 15:58:10

Template variable warning: list object has no element 5 when rendering ‘homeassistant/sensor/{{ trigger.topic.split(’/‘)[0]}}{{trigger.topic.split(‘/’)[1]}}{{trigger.topic.split(‘/’) [2]}}/{{trigger.topic.split(‘/’)[3]}}{{trigger.topic.split(‘/’)[4]}}{{trigger.topic.split(‘/’)[5]}}/config’

Thanks

Likely one of your automations is triggered by an MQTT trigger and somewhere in that automation that template logic is being used. If you can find that automation and post its YAML configuration here someone can likely help you sort out a better way to handle the MQTT topic so that it doesn’t throw errors.

Hello, thank you. The tip was just right. I found the following automation. Maybe someone can help me figure out why it’s not working:

alias: BSC discovery
description: ""
triggers:
  - alias: DataDevice
    topic: bsc/DataDevice/+/+
    enabled: true
    trigger: mqtt
    id: DataDevice
  - topic: bsc/DataDevice/+/cellVoltage/#
    enabled: true
    trigger: mqtt
    alias: Cell Voltages
    id: CellVoltages
  - topic: bsc/DataDevice/+/temperature/#
    enabled: true
    trigger: mqtt
    alias: DataDevice Temperatures
    id: DataDeviceTemperatures
  - alias: 1wire Temperature
    topic: bsc/temperatur/#
    enabled: true
    trigger: mqtt
    id: 1WireTemperature
  - alias: Inverter
    topic: bsc/inverter/#
    enabled: true
    trigger: mqtt
    id: Inverter
  - alias: Trigger
    topic: bsc/trigger/#
    enabled: true
    trigger: mqtt
    id: Trigger
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Inverter
        sequence:
          - action: mqtt.publish
            data:
              qos: 0
              topic: >-
                homeassistant/sensor/{{ trigger.topic.split('/')[0]}}/{{
                trigger.topic.split('/')[1]}}_{{
                trigger.topic.split('/')[2]}}/config
              retain: true
              payload: |-
                {
                  "name": "{{trigger.topic.split('/')[2]}}",
                  "state_topic": "{{ trigger.topic }}",
                  {% set d = { 'SoC': 'battery', 'chargeCurrentSoll': 'current', 'chargeVoltage': 'voltage', 'dischargeCurrentSoll': 'current', 'SoC': 'battery', 'temperature': 'temperature', 'totalCurrent': 'current', 'totalVoltage': 'voltage',} %}{% if d.get( trigger.topic.split('/')[2],'') %}"device_class":"{{ d.get( trigger.topic.split('/')[2]) }}",{% endif %}
                  "state_class": "measurement",
                  "unit_of_measurement": "{% set d = { 'chargeCurrentSoll': 'A', 'chargeVoltage': 'V', 'dischargeCurrentSoll': 'A', 'SoC': '%', 'temperature': '°C', 'totalCurrent': 'A', 'totalVoltage': 'V',} %}{{ d.get( trigger.topic.split('/')[2],'' ) }}",
                  "unique_id": "{{ trigger.topic.split('/')[0]}}_{{ trigger.topic.split('/')[1]}}_{{ trigger.topic.split('/')[2]}}",
                  "device": {
                    "identifiers": ["bsc_{{ trigger.topic.split('/')[0]}}"],
                    "name": "BSC",
                    "manufacturer": "BSC",
                    "model": "BSC",
                    "sw_version": "n/a",
                    "hw_version": "n/a",
                    "configuration_url": "https://github.com/dominikfe/ha_bsc_discovery_automation"
                  }
                }
            alias: Inverter
        alias: Inverter
      - conditions:
          - condition: trigger
            id:
              - Trigger
        sequence:
          - action: mqtt.publish
            data:
              qos: 0
              topic: >-
                homeassistant/sensor/{{ trigger.topic.split('/')[0]}}/{{
                trigger.topic.split('/')[1]}}_{{
                trigger.topic.split('/')[2]}}/config
              retain: true
              payload: |-
                {
                  "name": "Trigger {{trigger.topic.split('/')[2]}}",
                  "state_topic": "{{ trigger.topic }}",
                  "state_color": "true",
                  "unique_id": "{{ trigger.topic.split('/')[0]}}_{{ trigger.topic.split('/')[1]}}_{{ trigger.topic.split('/')[2]}}",
                  "device": {
                    "identifiers": ["bsc_{{ trigger.topic.split('/')[0]}}"],
                    "name": "BSC",
                    "manufacturer": "BSC",
                    "model": "BSC",
                    "sw_version": "n/a",
                    "hw_version": "n/a",
                    "configuration_url": "https://github.com/dominikfe/ha_bsc_discovery_automation"
                  }
                }
            alias: Inverter
        alias: Trigger
      - conditions:
          - condition: trigger
            id:
              - DataDeviceTemperatures
        sequence:
          - action: mqtt.publish
            data:
              qos: 0
              topic: >-
                homeassistant/sensor/{{ trigger.topic.split('/')[0]}}{{
                trigger.topic.split('/')[1]}}{{trigger.topic.split('/')[2]}}/{{trigger.topic.split('/')[3]}}{{trigger.topic.split('/')[4]}}/config
              retain: true
              payload: |-
                {
                  "name": "Temperature Sensor {{ trigger.topic.split('/')[4]|int +1}}",
                  "state_topic": "{{ trigger.topic }}",
                  "device_class": "temperature",
                  "state_class": "measurement",
                  "value_template": "{% raw %} {{ value }} {% endraw %}",
                  "unit_of_measurement": "°C",
                  "unique_id": "{{trigger.topic.split('/')[0]}}_{{trigger.topic.split('/')[1]}}_{{trigger.topic.split('/')[2]}}_{{trigger.topic.split('/')[3]}}_{{trigger.topic.split('/')[4]}}",
                  "device": {
                    "identifiers": ["{{trigger.topic.split('/')[0]}}_{{trigger.topic.split('/')[1]}}_{{trigger.topic.split('/')[2]}}"],
                    "name": "BSC {{trigger.topic.split('/')[1]}} {{trigger.topic.split('/')[2]}}",
                    "manufacturer": "BSC",
                    "model": "BSC",
                    "sw_version": "n/a",
                    "hw_version": "n/a",
                    "configuration_url": "https://github.com/dominikfe/ha_bsc_discovery_automation"
                  }
                }
            alias: Temperatures
        alias: Temperatures
      - conditions:
          - condition: and
            conditions:
              - condition: template
                value_template: "{{ trigger.payload != '0' }}"
          - condition: trigger
            id:
              - CellVoltages
        sequence:
          - action: mqtt.publish
            data:
              qos: 0
              topic: >-
                homeassistant/sensor/{{
                trigger.topic.split('/')[0]}}{{trigger.topic.split('/')[1]}}{{trigger.topic.split('/')[2]}}/{{trigger.topic.split('/')[3]}}{{trigger.topic.split('/')[4]}}{{trigger.topic.split('/')[5]}}/config
              retain: true
              payload: |-
                {
                  "name": "Cell {% if trigger.topic.split('/')[4]|int < 9 %}0{% else %}{% endif %}{{ trigger.topic.split('/')[4]|int +1}} Voltage",
                  "state_topic": "{{ trigger.topic }}",
                  "device_class": "voltage",
                  "state_class": "measurement",
                  "value_templatee": "{% raw %} {{ value|int / 1000 }} {% endraw %}",
                  "dsp_prc": "4",
                  "unit_of_measurement": "V",
                  "unique_id": "{{ trigger.topic.split('/')[0]}}_{{ trigger.topic.split('/')[1]}}_{{ trigger.topic.split('/')[2]}}_{{trigger.topic.split('/')[3]}}{% if trigger.topic.split('/')[4]|int < 9 %}0{% else %}{% endif %}{{ trigger.topic.split('/')[4]|int +1}}",
                  "device": {
                    "identifiers": ["{{trigger.topic.split('/')[0]}}_{{trigger.topic.split('/')[1]}}_{{trigger.topic.split('/')[2]}}"],
                    "name": "BSC {{trigger.topic.split('/')[1]}} {{trigger.topic.split('/')[2]}}",
                    "manufacturer": "BSC",
                    "model": "BSC",
                    "sw_version": "n/a",
                    "hw_version": "n/a",
                    "configuration_url": "https://github.com/dominikfe/ha_bsc_discovery_automation"
                  }
                }
            alias: cellVoltages
        alias: CellVoltages
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.topic.split('/')[3] != "cellVoltage" and
              trigger.topic.split('/')[3] != "valid"}}
        sequence:
          - action: mqtt.publish
            data:
              qos: 0
              topic: >-
                homeassistant/sensor/{{
                trigger.topic.split('/')[0]}}{{trigger.topic.split('/')[1]}}{{trigger.topic.split('/')[2]}}/{{trigger.topic.split('/')[3]}}/config
              retain: true
              payload: |-
                {
                  "name": "{{trigger.topic.split('/')[3]}}",
                  "state_topic": "{{ trigger.topic}}",
                  {% set d = { 'SoC': 'battery', 'balancingCurrent': 'current', 'cellVoltageMax': 'voltage', 'cellVoltageMin': 'voltage', 'cellVoltageMax': 'voltage', 'maxCellDifferenceVoltage': 'voltage', 'totalCurrent': 'current', 'totalVoltage': 'voltage'} %}{% if d.get( trigger.topic.split('/')[3],'') %}"device_class":"{{ d.get( trigger.topic.split('/')[3]) }}",{% endif %}      
                  "state_class": "measurement",
                  "unit_of_measurement": "{% set d = {'SoC': '%', 'balancingCurrent': 'A', 'cellVoltageMax': 'V', 'cellVoltageMin': 'V', 'cellVoltageMax': 'V', 'maxCellDifferenceVoltage': 'mV', 'totalCurrent': 'A', 'totalVoltage': 'V'} %}{{ d.get( trigger.topic.split('/')[3],'') }}",
                  "unique_id": "bsc_{{ trigger.topic.split('/')[2]}}_{{ trigger.topic.split('/')[3]}}",
                  "device": {
                    "identifiers": ["{{trigger.topic.split('/')[0]}}_{{trigger.topic.split('/')[1]}}_{{trigger.topic.split('/')[2]}}"],
                    "name": "BSC {{trigger.topic.split('/')[1]}} {{trigger.topic.split('/')[2]}}",
                    "manufacturer": "BSC",
                    "model": "BSC",
                    "sw_version": "n/a",
                    "hw_version": "n/a",
                    "configuration_url": "https://github.com/dominikfe/ha_bsc_discovery_automation"
                  }
                }
            alias: Rest
        alias: Rest
mode: parallel
max: 10

The sequence that catches the trigger id CellVoltages (it’s the only one that tries to access the 5th element as per the error). The CellVoltages topic does split into 5 elements, but indexes start with 0 so you can only access [0] through [4].

Just remove the {{trigger.topic.split('/')[5]}} immediately before /config and you should be set.

Edit: To be clear, don’t remove the /config part, just the template immediately before it.

1 Like

Greate!!! Thanks :slight_smile: