Local and national news on a dashboard?

A picture is worth a 1000 words, can you draw a mockup?

What do i do wrong getting just one sensor but no two

Please do not post screenshots of code it’s impossible to read on mobile. Please go back and use the preformatted code feature (under the gear icon I the editor) of the forum to post the code itself…

Hi,

I have issues to extract the channel from a RSS as it looks like that:
„channel rdf:about=“tagesschau.de - Die Nachrichten der ARD | tagesschau.de”“

I set up the sensor template as in the Fox News example but get the error „ ‘None’ has no attribute ‘item’“.

Any ideas?

@Stuart11181 You can use this yaml to create the sensor for feedparser, then create sensors for the title, URL, and Image for each news article:

sensor:
  - platform: feedparser
    name: Tagesschau News
    date_format: "%a, %d %b %Y %H:%M:%S %Z"
    feed_url: "https://www.tagesschau.de/infoservices/alle-meldungen-100~rss2.xml"
    inclusions:
      - title
      - content
      - published
      - updated
      - link
    exclusions: []
    scan_interval:
      minutes: 15
    show_topn: 20

##### 1st Item

    - platform: template
      sensors:
        tagesschau_news_attributes_0:
          friendly_name: "Tagesschau Content Title 0"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[0].title }}

    - platform: template
      sensors:
        tagesschau_news_attributes_link_0:
          friendly_name: "Tagesschau Content Link 0"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[0].link }}

    - platform: template
      sensors:
        tagesschau_news_attributes_image_0:
          friendly_name: "Tagesschau Content Image 0"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[0].content[0].value | regex_findall_index('<img.*?src="(.*?)".*?>') }}

    - platform: template
      sensors:
        tagesschau_news_attributes_description_0:
          friendly_name: "Tagesschau Content Description 0"
          value_template: >
              {{ states.sensor.tagesschau_news.attributes.entries[0].content[0].value | regex_replace('<[^>]*>', '') }}

##### 2nd Item

    - platform: template
      sensors:
        tagesschau_news_attributes_1:
          friendly_name: "Tagesschau Content Title 1"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[1].title }}

    - platform: template
      sensors:
        tagesschau_news_attributes_link_1:
          friendly_name: "Tagesschau Content Link 1"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[1].link }}

    - platform: template
      sensors:
        tagesschau_news_attributes_image_1:
          friendly_name: "Tagesschau Content Image 1"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[1].content[0].value | regex_findall_index('<img.*?src="(.*?)".*?>') }}

    - platform: template
      sensors:
        tagesschau_news_attributes_description_1:
          friendly_name: "Tagesschau Content Description 1"
          value_template: >
              {{ states.sensor.tagesschau_news.attributes.entries[1].content[0].value | regex_replace('<[^>]*>', '') }}

##### 3rd Item

    - platform: template
      sensors:
        tagesschau_news_attributes_2:
          friendly_name: "Tagesschau Content Title 2"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[2].title }}

    - platform: template
      sensors:
        tagesschau_news_attributes_link_2:
          friendly_name: "Tagesschau Content Link 2"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[2].link }}

    - platform: template
      sensors:
        tagesschau_news_attributes_image_2:
          friendly_name: "Tagesschau Content Image 2"
          value_template: >
            {{ states.sensor.tagesschau_news.attributes.entries[2].content[0].value | regex_findall_index('<img.*?src="(.*?)".*?>') }}

    - platform: template
      sensors:
        tagesschau_news_attributes_description_2:
          friendly_name: "Tagesschau Content Description 2"
          value_template: >
              {{ states.sensor.tagesschau_news.attributes.entries[2].content[0].value | regex_replace('<[^>]*>', '') }}

Thanks a lot! In the meantime I also managed to extract the data I needed👍

Any help would be appreciated, I cant get the images to display from the nytimes feed
https://rss.nytimes.com/services/xml/rss/nyt/US.xml

type: markdown
content: |-
  {% for story in state_attr('sensor.google_top_stories','channel').item %}
    <h2>{{story.title}}</h2>
    <table>
    <tr>
    <td>
        <p><img src="{{ story['media:content']['@url']}}"/></p>
    </td>
    <td>
       <p>{{story.description}}</p>
       <p><a href="{{story.link}}/">Link to Article</a></p>
    </td>
    </tr>
    </table>
    <hr/>
  {% endfor %}

which returns

UndefinedError: 'dict object' has no attribute 'media:content'

but i can see the object in the attributes list

Here you go! Creating sensors and using Generic Camera is how I was able to do it. It’s a weird way to do it but it works just fine!

Here are the sensors for the first 5 articles, which includes the Title, Link to Article, Summary and the Image:

### New York Times News Sensors

    - platform: template
      sensors:
        new_york_times_news_attributes_title_1:
          friendly_name: "New York Times News Title 1"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[1].title }}

    - platform: template
      sensors:
        new_york_times_news_attributes_link_1:
          friendly_name: "New York Times News Link 1"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[1].link }}
    
    - platform: template
      sensors:
        ny_times_attributes_summary_1:
          friendly_name: "New York Times News Summary 1"
          value_template: >
            {{ states.sensor.ny_times.attributes.entries[1].summary }}

    - platform: template
      sensors:
        nyt_article_1_image_url:
          friendly_name: "NYT Article 1 Image URL"
          value_template: >
            {{ state_attr('sensor.nyt_us_news_images_all', 'image_urls')[1] | default('') }}

    - platform: template
      sensors:
        new_york_times_news_attributes_title_2:
          friendly_name: "New York Times News Title 2"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[2].title }}

    - platform: template
      sensors:
        new_york_times_news_attributes_link_2:
          friendly_name: "New York Times News Link 2"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[2].link }}

    - platform: template
      sensors:
        ny_times_attributes_summary_2:
          friendly_name: "New York Times News Summary 2"
          value_template: >
            {{ states.sensor.ny_times.attributes.entries[2].summary }}

    - platform: template
      sensors:
        nyt_article_2_image_url:
          friendly_name: "NYT Article 2 Image URL"
          value_template: >
            {{ state_attr('sensor.nyt_us_news_images_all', 'image_urls')[2] | default('') }}

    - platform: template
      sensors:
        new_york_times_news_attributes_title_3:
          friendly_name: "New York Times News Title 3"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[3].title }}

    - platform: template
      sensors:
        new_york_times_news_attributes_link_3:
          friendly_name: "New York Times News Link 3"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[3].link }}

    - platform: template
      sensors:
        ny_times_attributes_summary_3:
          friendly_name: "New York Times News Summary 3"
          value_template: >
            {{ states.sensor.ny_times.attributes.entries[3].summary }}

    - platform: template
      sensors:
        nyt_article_3_image_url:
          friendly_name: "NYT Article 3 Image URL"
          value_template: >
            {{ state_attr('sensor.nyt_us_news_images_all', 'image_urls')[3] | default('') }}

    - platform: template
      sensors:
        new_york_times_news_attributes_title_4:
          friendly_name: "New York Times News Title 4"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[4].title }}

    - platform: template
      sensors:
        new_york_times_news_attributes_link_4:
          friendly_name: "New York Times News Link 4"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[4].link }}

    - platform: template
      sensors:
        ny_times_attributes_summary_4:
          friendly_name: "New York Times News Summary 4"
          value_template: >
            {{ states.sensor.ny_times.attributes.entries[4].summary }}

    - platform: template
      sensors:
        nyt_article_4_image_url:
          friendly_name: "NYT Article 4 Image URL"
          value_template: >
            {{ state_attr('sensor.nyt_us_news_images_all', 'image_urls')[4] | default('') }}

    - platform: template
      sensors:
        new_york_times_news_attributes_title_5:
          friendly_name: "New York Times News Title 5"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[5].title }}

    - platform: template
      sensors:
        new_york_times_news_attributes_link_5:
          friendly_name: "New York Times News Link 5"
          value_template: >
            {{ states.sensor.new_york_times_news.attributes.entries[5].link }}

    - platform: template
      sensors:
        ny_times_attributes_summary_5:
          friendly_name: "New York Times News Summary 5"
          value_template: >
            {{ states.sensor.ny_times.attributes.entries[5].summary }}

    - platform: template
      sensors:
        nyt_article_5_image_url:
          friendly_name: "NYT Article 5 Image URL"
          value_template: >
            {{ state_attr('sensor.nyt_us_news_images_all', 'image_urls')[5] | default('') }}

1 Like

hey @kbrown01, since you seem knowledgeable in the subjet, I have a question.
I want to also add the image of each item in one of my .xml feeds, but the syntax is different, see https://www.lefigaro.fr/rss/figaro_actualites.xml

Unlike with foxnews, each <item> has another sub entity / group, <media:content> where the image is located, and I don’t know how to display that image in a markdown card.

Would you or someone else know how?

Thanks a lot :slight_smile:

@1aranzant … Use these:

Add these to your config:

- platform: template
  sensors:
    figaro_article_0_image_url:
      friendly_name: "Figaro Article 0 Image URL"
      value_template: >
        {{ state_attr('sensor.figaro_images_all', 'image_urls')[0] | default('') }}

    figaro_article_1_image_url:
      friendly_name: "Figaro Article 1 Image URL"
      value_template: >
        {{ state_attr('sensor.figaro_images_all', 'image_urls')[1] | default('') }}

(Rinse and repeat the template above for as many articles as you want to display)

- platform: rest
  name: figaro_images_all
  resource: https://www.lefigaro.fr/rss/figaro_actualites.xml
  value_template: "OK"
  json_attributes_path: "$.channel.item"
  json_attributes:
    - image_urls

Then add this in Generic Camera under still image:

{{ states('sensor.figaro_article_0_image_url') }}
1 Like

I’m not a SW guys but happen implement the rotate function here. There are 3 parts:

  • sensor.yaml: sensor template for automation.
- platform: rest
  name: Sky News RSS
  resource: https://feeds.skynews.com/feeds/rss/home.xml
  scan_interval: 3600
  value_template: "OK"
  unique_id: sensor.sky_news
  json_attributes_path: "$.rss"
  json_attributes:
    - channel

- platform: template
  sensors:
    dashboard_refresh_trigger:
      friendly_name: "Dashboard Refresh"
      value_template: "{{ now().timestamp() | int }}"
  • automation.yaml: setup the duration (10s) for rotating to the next
- id: update_refresh_trigger
  alias: Update Dashboard Refresh Trigger
  triggers:
  - seconds: /10
    trigger: time_pattern
  actions:
  - target:
      entity_id: sensor.dashboard_refresh_trigger
    action: homeassistant.update_entity
  • dashboard: since that all I want is a few news for my calendar, no more “decluttering_template” is needed. The index is obtained at step 3. There should be a better approach.
views:
  - path: main
    cards:
      - type: markdown
        content: |
          {# 1. Get the current time as a trigger (changes every 6s) #}
          {% set trigger_time = states('sensor.dashboard_refresh_trigger') %}
          {% set entries = state_attr('sensor.sky_news', 'channel').item %}

          {% if entries is defined and entries | length > 0 %}
            
            {# 2. Get the total count of stories #}
            {% set total_stories = entries | length %}
            
            {# 3. CRITICAL: Calculate a sequential index #}
            {# Convert the current time string to a Unix timestamp (integer seconds) #}
            {% set timestamp = as_timestamp(now()) | int(0) %}
            
            {# Use modulo (%) to cycle through the indices (0, 1, 2, ..., total_stories - 1) #}
            {# We divide the timestamp by 10 to make the index change every 10 seconds #}
            {% set index = (timestamp // 10) % total_stories %}
            
            {# 4. Select the story using the calculated sequential index #}
            {% set story = entries[index] %}
            
            {% set story_title = story.title | default('No Title') %}
            {% set story_link = story.link | default('#') %}
            {% set story_summary = story.description | default('No description available.') %}

            {# Extract image from media content or enclosures (using safe access) #}
            {% set image_url = '' %}
            {% if 'media:content' in story and '@url' in story['media:content'] %}
              {% set image_url = story['media:content']['@url'] | default('') %}
            {% endif %}  
            
            {% set title_html = "<h3><a href='" + story_link + "' target='_blank'>" + story_title + "</a></h3>" %}
            
            {% if image_url %}
              {% set table = "<font size='4'><table><tr><td width='40%'><p><img src='" + image_url + "' style='width:100%; border-radius:8px;'/></p></td><td width='2%'/><td width='58%'><p>" + story_summary + "</p></td></tr></table></font>" %}
            {% else %}
              {% set table = "<font size='4'><p>" + story_summary + "</p></font>" %}
            {% endif %}
            
            {# Output the combined HTML content #}
            {# {{ title_html + table }} #}
            - Total {{ total_stories }}
            - index {{ index }}
            {{ title_html + table }}

          {% else %}
            **ERROR:** No entries available
          {% endif %}

Thank kbrown01 and ColtonYYZ