Debugging of Error: e.g. list object has no element 1

Hi,

it’s more like a general question about debugging than a question for this special error message I get every minute:

2018-12-17 19:46:01 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: list object has no element 1

How can I debug that properly? Unfortunately no line number of the code or something like that is printed in the log so I find it nearly unpossible to know where the error comes from. Manually searching through all my automations and configurations did not help so far - even while seeing that it has something to do with templates and/or conditions.

Is there kind of a “advanced debug mode” that enables precise logging?

Thanks in advance,
luhu

Did you find a way to track this down? I now have one of these!

Unfortunately not. Still having that issue… :frowning:

I found my problem.

I use packages so I what I did was to remove them and do a restart until I found the offending one. then remove files from within that package, again until I found the offending one.

It is a pain with all those restarts but in case you don’t think of it, removing half at a time is the most efficient way.

Also I had a distinct advantage in that I had made a lot of changes in one package so I was fairly sure where to start looking.

For the record my issue was that I had a template that used an input_text which I had subtlety renamed elsewhere. I am still not exactly sure what the error message was telling me exactly but my error log is now a bit cleaner at startup!

Ha! I found my problem as well!

My template condition used the state of a sensor which did not always allow my string split operation on special conditions.
So I just wrapped it with an additional if clause:

'{% if states.sensor.alarmtime.state != "-"%}
{{ ... == states.sensor.alarmtime.state.split(":")[1] }}
{%else%}
False
{%endif%}'

Now the error messages are gone. :slight_smile:

Feels good doesn’t it!

Could you help me figure out how to do that with this sensor? This is one of the last errors I have yet to clean out in my log.

'{{ states.sensor.nhl_game_status.attributes["dates"][0]["games"][0]["gameDate"] }}'

I keep getting this in the template editor:
Error rendering template: UndefinedError: list object has no element 0

Currently when there is no data for the sensor it returns ‘unknown’