Local and national news on a dashboard?

Don’t use thumbnail, use the larger one and constrain to fixed size. I use decluttering templates, so the stories all look the same:

decluttering_templates:
  newsfeed_template:
    card:
      type: custom:auto-entities
      card:
        type: vertical-stack
        title: '[[title]]'
      card_param: cards
      filter:
        template: |
          {%- for story in state_attr('[[newsfeed]]','channel').item -%}
            {% set title = "<h3><a href='" + story.link + "'>" + story.title + "</a></h3>" -%}
            {% set table = "<font size='4'><table><tr><td width='50%'><p><img src='" + story['media:content']['@url'] + "'/></p></td><td width='2%'/><td width='48%'><p>" + story.description +"</p></td></tr></table></font>" -%}
            {% set content = title + table -%}
            {{-
              {"type": "markdown","content": content}
            -}},
          {%- endfor -%}

And you just call like this:

          - type: custom:decluttering-card
            template: newsfeed_template
            variables:
              - title: Headlines
              - newsfeed: sensor.fox_news_breaking
          - type: custom:decluttering-card
            template: newsfeed_template
            variables:
              - title: Sports
              - newsfeed: sensor.fox_news_sports

That looks fantastic, spent a little while trying to implement this, but my naivety is showing.
I downloaded declutter from HACS

In my configuration file I have added this

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

lovelace:
  mode: yaml
  resources:
    - url: /local/decluttering-card.js
      type: module

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml

Then at the top of the raw configuration file on the dashboard I have added the code provided

views:
  - title: Home
    badges: []
    decluttering_templates:
      newsfeed_template:
        card:
          type: custom:auto-entities
          card:
            type: vertical-stack
            title: '[[title]]'
          card_param: cards
          filter:
            template: |
              {%- for story in state_attr('[[newsfeed]]','channel').item -%}
                {% set title = "<h3><a href='" + story.link + "'>" + story.title + "</a></h3>" -%}
                {% set table = "<font size='4'><table><tr><td width='50%'><p><img src='" + story['media:content']['@url'] + "'/></p></td><td width='2%'/><td width='48%'><p>" + story.description +"</p></td></tr></table></font>" -%}
                {% set content = title + table -%}
                {{-
                  {"type": "markdown","content": content}
                -}},
              {%- endfor -%}
    cards:
      - type: custom:vertical-stack-in-card
        cards:

then I assume you add the declutter card as a manual with the following code (minus the

- type: custom:decluttering-card
  template: newsfeed_template
  variables:
    - title: Headlines
    - newsfeed: sensor.sky_news

So given that I probably made mistakes from the start, I cannot seem to progress this, I know you have made this decluttering way as you have multiple sources over multiple stacks, however I’m only interested in a few stories at a time, in fact, ideally I would love 1 story that cycles through the list, but thats another day

In your dashboard, decluttering templates are at the top level. Here is my whole dashboard (note you would in your case modify to move decluttering_templates to the top above views: at the same level):

decluttering_templates:
  newsfeed_template:
    card:
      type: custom:auto-entities
      card:
        type: vertical-stack
        title: '[[title]]'
      card_param: cards
      filter:
        template: |
          {%- for story in state_attr('[[newsfeed]]','channel').item -%}
            {% set title = "<h3><a href='" + story.link + "'>" + story.title + "</a></h3>" -%}
            {% set table = "<font size='4'><table><tr><td width='50%'><p><img src='" + story['media:content']['@url'] + "'/></p></td><td width='2%'/><td width='48%'><p>" + story.description +"</p></td></tr></table></font>" -%}
            {% set content = title + table -%}
            {{-
              {"type": "markdown","content": content}
            -}},
          {%- endfor -%}
views:
  - title: Home
    type: panel
    badges: []
    cards:
      - type: custom:layout-card
        layout_type: custom:grid-layout
        layout:
          max_cols: 2
          grid-template-columns: 50% 50%
        cards:
          - type: custom:decluttering-card
            template: newsfeed_template
            variables:
              - title: Headlines
              - newsfeed: sensor.fox_news_breaking
          - type: custom:decluttering-card
            template: newsfeed_template
            variables:
              - title: Sports
              - newsfeed: sensor.fox_news_sports
title: Newsfeed

@kbrown01

Sorry I know you have been patient, I had to restart from scratch as something went screwy last night and I had a load of work to recreate to get back to this point. May I check my config as it is still not recognising.
I downloaded declutter and auto-entities from HACS

In config I have added this

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes
  
lovelace:
  mode: yaml
  resources:
    - url: /local/decluttering-card.js
      type: module

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml

In my sensor.yaml I have added this

- platform: rest
  name: Sky News
  scan_interval: 3600
  unique_id: sensor.sky_news
  resource_template: https://feeds.skynews.com/feeds/rss/home.xml
  value_template: "{{ now() }}"
  json_attributes_path: "$.rss"
  json_attributes:
    - channel

At the top of my dashboard, through raw configuration editor

kiosk_mode:
  admin_settings:
    hide_header: true
    hide_sidebar: true
    frontend: null
    extra_module_url:
      - /local/card-mod.js
decluttering_templates:
  newsfeed_template:
    card:
      type: custom:auto-entities
      card:
        type: vertical-stack
        title: '[[title]]'
      card_param: cards
      filter:
        template: |
          {%- for story in state_attr('[[newsfeed]]','channel').item -%}
            {% set title = "<h3><a href='" + story.link + "'>" + story.title + "</a></h3>" -%}
            {% set table = "<font size='4'><table><tr><td width='50%'><p><img src='" + story['media:content']['@url'] + "'/></p></td><td width='2%'/><td width='48%'><p>" + story.description +"</p></td></tr></table></font>" -%}
            {% set content = title + table -%}
            {{-
              {"type": "markdown","content": content}
            -}},
          {%- endfor -%}
views:
  - path: main
    icon: mdi:gesture-tap-button
    badges: []
    cards:
      - type: vertical-stack

Then I put this code into a manual card

- type: custom:decluttering-card
  template: newsfeed_template
  variables:
    - title: Headlines
    - newsfeed: sensor.sky_news

The error I get is this

I did not set up auto-entities other than download it
I feel it’s fundamental and a little stupid, but would it be possible to glance over this, it looks really just about there and so close with all the help you have provided.
Thanks

New user here, and I fought long and hard with this as it looked good, and finally got somewhere. Firstly if you’re adding the card via the GUI, take out the hyphen, and subsequently correct the following lines indentation. So This;

type: custom:decluttering-card
template: newsfeed_template
variables:

  • title: Headlines
  • newsfeed: sensor.sky_news

haa would yah believe it :man_facepalming:

Will update once I have some pretty pics, thanks @ElGato + @kbrown01

Still very new to this and it took me a long while to figure out my biggest issue. It would not recognise the decluttering-card.js, kept telling me it wasn’t available despite me loading the .js into www. Turns out I had the code all wrong as in my haste didn’t find the download link so effectively made it up. It was late last night. Anyway seems a simple overwrite of the file isn’t enough, you have to convince HA it is in fact a new file and needs to be reloaded rather than drawn from it’s cache. You can do this by adding a version number to the end of the resource it seems.

Onwards and upwards.

It all appears to work as shown in the example.
The missus said that she does not want all the cards, just one card refreshed at a time, so I have adapted the code to reflect this. Yes it beats the whole point of declutter and everything else, but its still a learning win and I may implement this elsewhere.

So I have played around a bit with the formatting, but cannot get a decent size picture. I have been instructed by the OH she would like a picture and headline only. I assume the picture is being enlarged from the original thumbnail and may become pixilated

Any pointers as I’m also a beginner hacking away blindly trying to work things out.

decluttering_templates:
  newsfeed_template:
    card:
      type: custom:auto-entities
      card:
        type: vertical-stack
        title: '[[title]]'
      card_param: cards
      filter:
        template: |

          {%- for story in state_attr('[[newsfeed]]','channel').item -%}
          {% if (loop.index < 2) %}
            {% set title = "<h3><a href='" + story.link + "'>" + story.title + "</a></h3>" -%}
            {% set table = "<font size='4'><table><tr><td width='50%'><p><img src='" + story['media:content']['@url'] + "'/></p></td><td width='2%'/><td width='48%'><p>" + story.description +"</p></td></tr></table></font>" -%}
            {% set content = title + table -%}
            {{-
              {"type": "markdown","content": content}
            -}},
          {% endif %}            
          {%- endfor -%}

As you can see from the original card, I do not have a lot of room for it to fit in the tablet space which is mounted in the hallway

Original single card

Modified card

Picture is still small with lots of wasted space

I think I recall you using Sky News feeds? I just tried one for Sky News and I get the tiny image. Other news feeds I’ve used have the full image so it’s likely and issue with the feed itself. Maybe try a different feed as a test.

Finally!

And a big thank you to @kbrown01

Great that you got it. For my wallpads I was thinking of implementing a sensor that just rotates the news item every “X” seconds. Might do that in the future.

Hello, could someone help me?

I used the feedreader integration to see the 5 most important news from my RSS provider, however I have not been able to organize the code so that they can all be seen, it only prints the most recent one.

This is my code in yalm:

feedreader:
urls:
- rss | La FM
scan_interval:
minutes: 3
limit: 5

and this is my code for the card:

type: markdown
content: >-
{{ states(‘input_text.titulo_de_noticias’) }}

{{ states(‘input_text.descripcion_noticia’) }}

{{ as_datetime(states(‘input_datetime.fecha_de_noticias’)).strftime(‘%B %d, %Y
%H:%M:%S’) }} - [Read More]({{ states(‘input_text.link_noticia’) }})

{{ states(‘input_text.imagen_noticia’) }}
title: Noticias :radio:

I know I should have something with a for loop but I don’t know how to do it. I also used assistants to capture the items of each news item.

Hi there! This is amazing =) Worked like a charm the first time i tried it.

I tried to replicate it with a separate news source but didn’t think it was that straight forward.

May i seek your expertise in how to go about doing the same for the following RSS?

https://news.google.com/rss?hl=en-MY&gl=MY&ceid=MY:en

https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml

Much thanks!

Sample for Google News. Note there are no images in the feed, only bullet news stories. You can style as you wish, this is mostly just raw.

Create a sensor as (set the scan_interval to what you want):

- platform: rest
  name: Google Top Stories
  scan_interval: 36000
  unique_id: sensor.google_top_stories
  resource: https://news.google.com/rss?hl=en-MY&gl=MY&ceid=MY:en
  value_template: "{{ now() }}"
  json_attributes_path: "$.rss"
  json_attributes:
    - channel

In a dashboard (note this is setup so you cold easily add your other feed with 50%/50% split in a grid but you can layout as desired):

decluttering_templates:
  newsfeed_template:
    card:
      type: custom:auto-entities
      card:
        type: vertical-stack
        title: '[[title]]'
      card_param: cards
      filter:
        template: |
          {%- for story in state_attr('[[newsfeed]]','channel').item -%}
            {% set title = "<h3><a href='" + story.link + "'>" + story.title + "</a></h3>" -%}
            {% set table = "<font size='4'><table><tr><td width='100%'><p>" + story.description +"</p></td></tr></table></font>" -%}
            {% set content = title + table -%}
            {{-
              {"type": "markdown","content": content}
            -}},
          {%- endfor -%}
views:
  - title: Home
    type: panel
    badges: []
    cards:
      - type: custom:layout-card
        layout_type: custom:grid-layout
        layout:
          max_cols: 2
          grid-template-columns: 50% 50%
        cards:
          - type: custom:decluttering-card
            template: newsfeed_template
            variables:
              - title: Headlines
              - newsfeed: sensor.google_top_stories
title: Newsfeed

Result:

You could easily enhance some of this … I would use some CSS to eliminate the numbering, you could also use the tag “source” URL to get the source name and style differently but it is in every title anyway.

You’re a star! Very grateful for this. Much thanks!!

The second example is a little different so the template has to change. The RSS feed could have image (or not) and also could have description (or not). It also uses media:thumbnail and not media:content. So you should have another template for it, this would work:

decluttering_templates:
  newsfeed_template:
    card:
      type: custom:auto-entities
      card:
        type: vertical-stack
        title: '[[title]]'
      card_param: cards
      filter:
        template: >
          {%- for story in state_attr('[[newsfeed]]','channel').item
          -%}
            {%- if (story['media:thumbnail']) and (story['media:thumbnail']['@url'] | length) > 0 -%}
              {% set imgurl = story['media:thumbnail']['@url'] %}
            {%- else -%}
              {% set imgurl = "" %}
            {%- endif -%}
            {% set title = "<h3><a href='" + story.link + "'>" + story.title + "</a></h3>" -%}
            {%- if (story.description) and (story.description | length) > 0 -%}
              {% set table = "<font size='4'><table><tr><td width='50%'><p><img src='" + imgurl + "'/></p></td><td width='2%'/><td width='48%'><p>" + story.description +"</p></td></tr></table></font>" -%}
            {%- else -%}
              {% set table = "<font size='4'><table><tr><td width='50%'><p><img src='" + imgurl + "'/></p></td><td width='2%'/><td width='48%'><p></p></td></tr></table></font>" -%}
            {%- endif -%}
            {% set content = title + table -%}
            {{-
              {"type": "markdown","content": content}
            -}},
          {%- endfor -%}
views:
  - title: Home
    type: panel
    badges: []
    cards:
      - type: custom:layout-card
        layout_type: custom:grid-layout
        layout:
          max_cols: 2
          grid-template-columns: 50% 50%
        cards:
          - type: custom:decluttering-card
            template: newsfeed_template
            variables:
              - title: Headlines
              - newsfeed: sensor.channel_news_asia
title: Newsfeed

It yields this:

Top entry has no description but has an image.
Next two have no image nor description.
Last entry have both.

The sensor is no different than FoxNews ones:

- platform: rest
  name: Channel News Asia
  scan_interval: 36000
  unique_id: sensor.channel_news_asia
  resource: https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml
  value_template: "{{ now() }}"
  json_attributes_path: "$.rss"
  json_attributes:
    - channel

Of course you could considerably clean that up by not creating the table at all for anything without an image. I will leave that to you.

1 Like

Thanks and appreciate the assist kbrown01. Will play around with it. This has been the best upgrade to my dashboard this month =)

Hey @kbrown01, were you able to implement your news feed to rotate? Would you mind sharing your yaml? Thank you in advance!