Feedreader: variables in Notification Message

Hi Guys,

I have read the docs about the feedreader but I couldn´t figure out/understand the “logic” behind the variables in the example.

I am starting with the AS IS - State:

I have configured a Feedreader in my configuration.yaml

feedreader:
  urls:
    - https://logbuch-netzpolitik.de/feed/m4a
  scan_interval:
    minutes: 30
  max_entries: 5

  1. I have successfully configured a very very basic automation which notifies me via Telegram:
alias: Auto_Feedreader_LNP_Notification
description: ""
trigger:
  - platform: event
    event_type: feedreader
    event_data:
      feed_url: https://logbuch-netzpolitik.de/feed/m4a
condition: []
action:
  - service: telegram_bot.send_message
    data:
      message: lnp
mode: single

and it is working very solid (but not very elegant).

My Problem:

The Docs say

Any field under the <entry> tag in the feed can be used for example trigger.event.data.content will get the body of the feed entry.

What do they mean with “entry tag”?

I looked in the feed_url of the example Home Assistant Podcast but I could not find anything with “entry” I also looked for something like data.content, still having no clue.

I simply cannot figure out to how to get the link for example from Logbuch:Netzpolitik

grafik

How should the variable in my message look like, especially in my case and especially how can you find it out?

ATOM feeds use <entry> tags, while RSS feeds use <item> tags.

In general, the RSS structure is transformed into a data structure that you can access.

Title: {{ trigger.event.data.title }}
Link: {{ trigger.event.data.link }}

Now, that does not work for all tags in the RSS, for example pubDate is actually transformed into published. The only reason I know this is because I worked with the underlying Python library in the past - and there is some more documentation available.

To understand what’s actually in the event data you could just log the raw data in your automation:

...
action:
  - service: system_log.write
    data:
      level: error
      message: "{{ trigger.event.data.content }}"
...
1 Like

Thanks for the very structured solution and your time. Gonna test it out…
Thanks!

1 Like

Update: Didnt work out for now, but I think it was my Problem… will test again and provide the logs because there was an error but I lost the errorlog.

I just created 3 testautomations to find out which trigger should work out.

It is hard to debug this whole thing, because I need to wait for the feedreader event and I just simply cannot rerun the automation because it looks like the automation can just fetch the variables when it has legitimately been triggered. When running it manually via “run”-Button there do not seem to be any Data available… grafik


for further testing I also added the system_log.write service in another automation.

That’s correct - running an automation manually basically just skips the defined trigger, and there is no way to define sample trigger event data.

1 Like

Update:

It took half an eternity. :slight_smile:

  1. I have received some notifications:

service: telegram_bot.send_message
data:
  message: lnp 1 {{trigger.event.data.title}}
service: telegram_bot.send_message
data:
  message: lnp 2 {{trigger.event.data.link}}

Following message didnt work though:

service: telegram_bot.send_message
data:
  message: lnp 3  {{trigger.event.data.content}}

So this is a great success!
grafik

Nevertheless I still dont get it how to get the variable on my own, or is it really a “written rule” that data.title and data.link always work with rss feeds? If yes: are there any docs where I can get other vars?

  1. system_log.write gives me infos I cannot start with, but it gives me following:
    (uploaded on pastebin to prevent spam)
    lnp_log - Pastebin.com

Unfortunately this is not well documented. I had a look into the source code of the feedparser Python library to understand how the transformation of RSS/Atom feeds works and how information is then presented in this integration.

Comparing the log output with the actual feed, it looks like you get an array with 2 entries - the first entry is the item’s description, and the second entry is the the item’s content:encoded.

1 Like

Hi,
I try also to send news by telegram.
But I have issue with this automation :

- id: news
  alias: News
  description: News
  trigger:
  - platform: event
    event_type: feedreader
    event_data:
      feed_url: https://www.lemonde.fr/rss/une.xml
  condition: []
  action:
  - service: input_text.set_value
    data:
      value: "{{ trigger.event.data.title }}"
    target:
      entity_id: input_text.news_title
    enabled: true  
  - service: input_text.set_value
    data:
      value: "{{ trigger.event.data.description }}"
    target:
      entity_id: input_text.news
    enabled: true
  - service: input_text.set_value
    data:
      value: "{{ trigger.event.data.link }}"
    target:
      entity_id: input_text.news_link
    enabled: true
  - service: input_datetime.set_datetime
    data:
      value: "{{ trigger.event.data.date }}"
    target:
      entity_id: input_datetime.news_date
    enabled: true
  - service: notify.lilp_bot
    data:
      title: Batterie faible
      message: News "{{ trigger.event.data.title }}"

I have this message in Step details :

Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’

And in Trace TimeLine :

Triggered manually at 2 novembre 2023 à 10:44:28
Appeler le service “Saisie de texte: Définir” sur News Title
Stopped because an error was encountered at 2 novembre 2023 à 10:44:28 (runtime: 0.02 seconds)

Thanks for your help.

When you manually trigger this automation, there is no event fed into the actions, and thus the templates fail.

You always need to wait until the Feed comes “on its own”.
@lilp69

No possibility of manually triggering the sending of news at a specific time

Like i said: You always need to wait until the Feed comes “on its own”
This thread already says it multiple times.

Therefore you have 2 options:

  • Create your own feed and simulate a manual trigger.
  • or Wait.
1 Like