Displaying Newsfeeds

Home Assistant Template

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 feedparser which does exactly that.

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.

For my use I added the Home Assistant blog and the Home Assistant Alerts options.

- platform: feedparser
  name: Home Assistant Alerts
  feed_url: 'https://alerts.home-assistant.io/feed.xml'
  date_format: '%a, %b %d %I:%M %p'
  inclusions:
    - title
    - link
    - updated

- platform: feedparser
  name: Home Assistant Blog
  feed_url: 'https://www.home-assistant.io/atom.xml'
  date_format: '%a, %b %d %I:%M %p'
  inclusions:
    - title
    - link
    - updated

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.

Restarting HA then created the two feed entities.

To display the values I used a simple Markdown box as follows

**Alerts**
{% set entries = state_attr('sensor.home_assistant_alerts','entries')%}
{%- for id in entries -%}
{%- if loop.index < 4 -%}
          [{{ id.title }}]({{ id.link }})   {{id.updated}} {{count}}    
{%- endif %}
{% endfor %}
**Blog**
{% set entries = state_attr('sensor.home_assistant_blog','entries')%}
{%- for id in entries -%}
{%- if loop.index < 4 -%}
          [{{ id.title }}]({{ id.link }})   {{id.updated}}    
{%- endif %}  
{% endfor %}

Note: The use of loop.index 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.