emplateError('TypeError: 'NoneType' object is not iterable') while processing template

Hi,

I has created this template, but i received the error (above) and i dont know why.
The template is working, but the error stay in home assistant.

template:
  - sensor:
      - name: "football"
        state: template
        attributes:
          football: >
            {% for game in state_attr('sensor.today_footbal_games','games') %}
            [{{game.time}}] {{game.homeTeam}} vs {{game.awayTeam}} [{{game.channel}}]
            {% endfor %}

Error:

2021-10-16 23:36:43 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{% for game in state_attr('sensor.today_footbal_games','games') %} [{{game.time}}] {{game.homeTeam}} vs {{game.awayTeam}} [{{game.channel}}] {% endfor %}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 397, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1604, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
TypeError: 'NoneType' object is not iterable
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 513, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 399, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: 'NoneType' object is not iterable
2021-10-16 23:36:43 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('TypeError: 'NoneType' object is not iterable') while processing template 'Template("{% for game in state_attr('sensor.today_footbal_games','games') %} [{{game.time}}] {{game.homeTeam}} vs {{game.awayTeam}} [{{game.channel}}] {% endfor %}")' for attribute 'football' in entity 'sensor.football'
2021-10-16 23:44:34 ERROR (Thread-113) [homeassistant.helpers.template] Template variable error: 'game' is undefined when rendering 'template:
- sensor:
- name: "football"
state: template
attributes:
football: >
{% if state_attr('sensor.today_footbal_games','games') %}{{game.time}} {{game.homeTeam}} vs {{game.awayTeam}} [{{game.channel}}]
{% endif %}'
2021-10-16 23:44:35 ERROR (Thread-114) [homeassistant.helpers.template] Template variable error: 'game' is undefined when rendering 'template:
- sensor:
- name: "football"
state: template
attributes:
football: >
{% if state_attr('sensor.today_footbal_games','games') %}{{game.time}} {{game.homeTeam}} vs {{game.awayTeam}} [{{game.channel}}]
{% endif %}'

Thanks

sensor.today_footbal_games

Looks like a misspelling.

I’m sorry for my english.
I’m just an enthusiast of things, this is the flow where the data is being pulled:

[{"id":"ef5efef0.d8e0a8","type":"ha-entity","z":"b2b3b890.cbc99","name":"","server":"","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Today Football Games"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload[0].date","stateType":"msg","attributes":[{"property":"date","value":"payload[0].date","valueType":"msg"},{"property":"games","value":"payload[0].games","valueType":"msg"},{"property":"updatedOn","value":"payload[0].updatedOn","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":850,"y":520,"wires":[[]]},{"id":"f6800d57.400f48","type":"ha-entity","z":"b2b3b890.cbc99","name":"","server":"","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Tomorrow Football Games"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload[1].date","stateType":"msg","attributes":[{"property":"date","value":"payload[1].date","valueType":"msg"},{"property":"games","value":"payload[1].games","valueType":"msg"},{"property":"updatedOn","value":"payload[1].updatedOn","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":1030,"y":360,"wires":[[]]},{"id":"a1263a91.9e7468","type":"inject","z":"b2b3b890.cbc99","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":420,"wires":[["3f072ab4.ba1496"]]},{"id":"3f072ab4.ba1496","type":"http request","z":"b2b3b890.cbc99","name":"Obter Jogos na TV","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://www.futebol365.pt/jogos-na-tv/","tls":"","persist":false,"proxy":"","authType":"","x":350,"y":260,"wires":[["d2136d3d.26309","d4859fee.65b8e8"]]},{"id":"d4859fee.65b8e8","type":"html","z":"b2b3b890.cbc99","name":"","property":"payload","outproperty":"payload","tag":".condensed-400.headerTitle.orange","ret":"html","as":"single","x":710,"y":180,"wires":[["78037343.d22454"]]},{"id":"d2136d3d.26309","type":"html","z":"b2b3b890.cbc99","name":"","property":"payload","outproperty":"payload","tag":".ink-table.alternating.ink-table-f365.double-bottom-space tbody","ret":"text","as":"single","x":750,"y":220,"wires":[["4bbff48a.d32534"]]},{"id":"b4f32ab2.973cc8","type":"join","z":"b2b3b890.cbc99","name":"Dates With Games","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":480,"y":360,"wires":[["831be36f.94dad8"]]},{"id":"831be36f.94dad8","type":"function","z":"b2b3b890.cbc99","name":"Merge Dates/Games","func":"var allGamesArr   = msg.payload[0];\nvar allDatesArr   = msg.payload[1].dates;\n\nvar allGamesByDate = [];\n\nvar date = new Date();\nvar dateStr =\n date.getFullYear()+ \"-\" +\n  (\"00\" + (date.getMonth() + 1)).slice(-2) + \"-\" +\n   (\"00\" + date.getDate()).slice(-2)  + \" \" +\n  (\"00\" + date.getHours()).slice(-2) + \":\" +\n  (\"00\" + date.getMinutes()).slice(-2) + \":\" +\n  (\"00\" + date.getSeconds()).slice(-2);\n\n\n\nfor(var i=0; i<allDatesArr.length; i++) {\n    \n    var dateInfo = {\n        'date' : allDatesArr[i].gamesDate,\n        'games' : [],\n        'updatedOn' :dateStr\n    };\n    \n    var dayGames = allGamesArr[i].games;\n    for(var t=0; t<dayGames.length; t++) {\n        dateInfo.games.push(dayGames[t]);\n    }\n    allGamesByDate.push(dateInfo);\n    \n    \n}\n\nreturn [{'payload': allGamesByDate}, null];","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":360,"wires":[["f6800d57.400f48","ef5efef0.d8e0a8"]]},{"id":"78037343.d22454","type":"function","z":"b2b3b890.cbc99","name":"Get Dates","func":"var currentDate   = msg.payload[0];\n\nvar dates = [];\n\nfor(var i=0; i<msg.payload.length; i++) {\n  \n     \n     var dayNumber =  msg.payload[i].substring(\n         msg.payload[i].indexOf(\",\")+2, msg.payload[i].indexOf(\" de\"));\n    \n    \n    var monthName =  msg.payload[i].substring(\n        msg.payload[i].indexOf(\" de\")+4,\n        msg.payload[i].length\n        );\n        \n    var gamesDate = \"\";\n    \n    var monthNumber = -1;\n    if(monthName == \"Janeiro\") {\n        monthNumber = \"01\";\n    } else if(monthName == \"Fevereiro\") {\n        monthNumber = \"02\";\n    }  else if(monthName.indexOf(\"Mar\")) {\n        monthNumber = \"03\";\n    }  else if(monthName == \"Abril\") {\n        monthNumber = \"04\";\n    }  else if(monthName == \"Maio\") {\n        monthNumber = \"05\";\n    }  else if(monthName == \"Junho\") {\n        monthNumber = \"06\";\n    }  else if(monthName == \"Julho\") {\n        monthNumber = \"07\";\n    }  else if(monthName == \"Agosto\") {\n        monthNumber = \"08\";\n    }  else if(monthName == \"Setembro\") {\n        monthNumber = \"09\";\n    }  else if(monthName == \"Outubro\") {\n        monthNumber = \"10\";\n    }  else if(monthName == \"Novembro\") {\n        monthNumber = \"11\";\n    }  else if(monthName == \"Dezemrbo\") {\n        monthNumber = \"12\";\n    } \n    gamesDate = new Date().getFullYear()+\"-\"+monthNumber+\"-\"+dayNumber;\n    \n    dates.push({\n       'date' : msg.payload[i],\n       'dayNumber' : dayNumber,\n       'monthName' : monthName,\n       'year' : new Date().getFullYear(),\n       'index': i,\n       'gamesDate' : gamesDate\n    })\n}\nreturn [{'payload': {'dates': dates}}, null];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1130,"y":180,"wires":[["b4f32ab2.973cc8"]]},{"id":"4bbff48a.d32534","type":"function","z":"b2b3b890.cbc99","name":"Get Games","func":"var allGames = [];\n\n\nfor(t=0; t<msg.payload.length; t++) {\n    var dayGamesArr = msg.payload[t].split(/\\r\\n|\\r|\\n/);\n    \n    var dayObj = {\n        'gameIndex': t,\n        'games' : []\n    };\n    \n    for(x=0; x<dayGamesArr.length; x++) {\n        \n        if(dayGamesArr[x] != null && dayGamesArr[x].length == 5 &&  dayGamesArr[x].indexOf(\":\") == 2 ) {\n       dayObj.games.push({\n           'time' : dayGamesArr[x],\n           'homeTeam' : dayGamesArr[x+1],\n           'awayTeam' : dayGamesArr[x+3],\n           'channel' : dayGamesArr[x+7]\n       });\n    }\n    }\n    allGames.push(dayObj);\n\n}\n\n\nreturn [{'payload': allGames}, null];","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1110,"y":240,"wires":[["b4f32ab2.973cc8"]]},{"id":"e56cba68.7d367","type":"cronplus","z":"b2b3b890.cbc99","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":120,"y":280,"wires":[["3f072ab4.ba1496"]]}]

if the data is showing up in the sensors, why are you giving me an error?
an error in HA bothers me because there are always new ones appearing, and if I don’t worry about eliminating them, then there are already too many…


Thanks

to update, already managed to change the sensor name to “football” well written… But I still have the same 2 errors. I wonder why? If everything is working fine?

template:
  sensor:
    - unique_id: football
      state: template
      attributes:
        football: >
          {% for game in state_attr('sensor.today_football_games','games') %}
          [{{game.time}}] {{game.homeTeam}} vs {{game.awayTeam}} [{{game.channel}}]
          {% endfor %}