{"id":13348,"date":"2021-12-01T10:47:54","date_gmt":"2021-12-01T10:47:54","guid":{"rendered":"https:\/\/www.rjt.org.uk\/home\/?post_type=home_assistant_tip&#038;p=13348"},"modified":"2021-12-01T10:49:45","modified_gmt":"2021-12-01T10:49:45","slug":"displaying-newsfeeds","status":"publish","type":"home_assistant_tip","link":"https:\/\/www.rjt.org.uk\/home\/archives\/home-assistant-tip\/displaying-newsfeeds\/","title":{"rendered":"Displaying Newsfeeds"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2021\/12\/2021-12-01_104850.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"556\" height=\"191\" src=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2021\/12\/2021-12-01_104850.jpg\" alt=\"\" class=\"wp-image-13349\" srcset=\"https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2021\/12\/2021-12-01_104850.jpg 556w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2021\/12\/2021-12-01_104850-300x103.jpg 300w, https:\/\/www.rjt.org.uk\/home\/wp-content\/uploads\/2021\/12\/2021-12-01_104850-150x52.jpg 150w\" sizes=\"auto, (max-width: 556px) 100vw, 556px\" \/><\/a><\/figure>\n\n\n\n<p>Home Assistant has the built in feedreader,  but this only acts as an event trigger for new items.  What I was looking for was an easy way to display the most recent feeds on my Dashboard.  Luckily there is a hacs intergration called <a href=\"https:\/\/github.com\/custom-components\/feedparser\" data-type=\"URL\" data-id=\"https:\/\/github.com\/custom-components\/feedparser\">feedparser<\/a> which does exactly that.<\/p>\n\n\n\n<p> It installs as a normal hacs option and once installed has to be added  to your configuration yaml or your sensor.yaml if you use one.<\/p>\n\n\n\n<p>For my use I added the Home Assistant blog and the Home Assistant Alerts options.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">- platform: feedparser\n  name: Home Assistant Alerts\n  feed_url: 'https:\/\/alerts.home-assistant.io\/feed.xml'\n  date_format: '%a, %b %d %I:%M %p'\n  inclusions:\n    - title\n    - link\n    - updated\n\n- platform: feedparser\n  name: Home Assistant Blog\n  feed_url: 'https:\/\/www.home-assistant.io\/atom.xml'\n  date_format: '%a, %b %d %I:%M %p'\n  inclusions:\n    - title\n    - link\n    - updated<\/pre>\n\n\n\n<p>Note only include the fields you need.  Also some feeds may use different names for the link or url value so the best thing is to view the feed in a web browser to decide what fields you want.   As I simply want to include links to open the web page I only included the title, link and updated fields.<\/p>\n\n\n\n<p>Restarting HA then created the two feed entities.<\/p>\n\n\n\n<p>To display the values I used a simple Markdown box as follows<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">**Alerts**\n{% set entries = state_attr('sensor.home_assistant_alerts','entries')%}\n{%- for id in entries -%}\n{%- if loop.index &lt; 4 -%}\n          [{{ id.title }}]({{ id.link }})   {{id.updated}} {{count}}    \n{%- endif %}\n{% endfor %}\n**Blog**\n{% set entries = state_attr('sensor.home_assistant_blog','entries')%}\n{%- for id in entries -%}\n{%- if loop.index &lt; 4 -%}\n          [{{ id.title }}]({{ id.link }})   {{id.updated}}    \n{%- endif %}  \n{% endfor %}<\/pre>\n\n\n\n<p>Note:  The use of <code data-enlighter-language=\"yaml\" class=\"EnlighterJSRAW\">loop.index<\/code> to limit the number of lines displayed to 3 for each output.  It is not possible to set a variable outside of a loop and increment it in the loop so you need to use the loop index option to track the loop.<\/p>\n","protected":false},"template":"","class_list":["post-13348","home_assistant_tip","type-home_assistant_tip","status-publish","hentry","comments-off"],"_links":{"self":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip\/13348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/home_assistant_tip"}],"about":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/types\/home_assistant_tip"}],"wp:attachment":[{"href":"https:\/\/www.rjt.org.uk\/home\/wp-json\/wp\/v2\/media?parent=13348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}