I’m attempting to display multiple news stories using a max7219 matrix display using the feedparser custom component and I can select a single or random entry using
{{states.sensor.news_feed.attributes.entries[(1)]['title']}}
{{states.sensor.news_feed.attributes.entries[range(1,10) | random]['title']}}
and populate an input_text entity but what is the syntax for all the entries or a range of entries from the sensor?
I’m aware of the 255 character limit of input_text entities.
Use colons (:
) to define how to slice the array/list and use map()
to filter the desired attribute:
Titles of all entries:
{{state_attr('sensor.news_feed','entries')|map(attribute='title')|list}}
Titles of the first 5 entries:
{{ state_attr('sensor.news_feed','entries')[0:5]|map(attribute='title')|list }}
Titles of the last 2 entries:
{{ state_attr('sensor.news_feed','entries')[-2:]|map(attribute='title')|list }}
That’s weird. It works in the template designer but won’t pass HA yaml checks.
data:
value: '{{state_attr('sensor.news_feed','entries')|map(attribute='title')|list}}'
Giving the error:
"can not read an implicit mapping pair; a colon is missed at line 11, column 94:
… attribute=‘title’)|list}}’
You need "
on the outside of the template since there are '
on the inside.