using this small setup creates pers notifications for my feedreader urls:
feedreader:
urls:
- https://www.home-assistant.io/atom.xml
- https://hasspodcast.io/feed/podcast
- https://www.gdacs.org/xml/rss.xml
scan_interval:
minutes: 30
max_entries: 5
automation:
- alias: Notify RSS feed updated
trigger:
platform: event
event_type: feedreader
action:
service: persistent_notification.create
data_template:
title: >
{{ trigger.event.data.title }}
message: >
{% set url = trigger.event.data.feed_url.split('https://')[1] %}
{% set source = {'www.home-assistant.io/atom.xml':'Home-assistant',
'hasspodcast.io/feed/podcast':'Hass podcast',
'www.gdacs.org/xml/rss.xml':'GDACS'} %}
New Rss feed for {{source[url] if url in source else 'Unknown'}}, see
{{trigger.event.data.link}}
notification_id: >
{% set url = trigger.event.data.feed_url.split('https://')[1] %}
{% set source = {'www.home-assistant.io/atom.xml':'Home-assistant',
'hasspodcast.io/feed/podcast':'Hass podcast',
'www.gdacs.org/xml/rss.xml':'GDACS'} %}
rss-feed-{{source[url] if url in source else 'Unknown'}}
and the pers not id is in the form of persistent_notification.rss_feed_gdacs
which I thought was fine enough, but I hadn’t realized more than 1 notification could be created…
so I tried to add a few characters of the title to the template above, but though working fine, looks a bit hacky:
notification_id: >
{% set url = trigger.event.data.feed_url.split('https://')[1] %}
{% set source = {'www.home-assistant.io/atom.xml':'Home-assistant',
'hasspodcast.io/feed/podcast':'Hass podcast',
'www.gdacs.org/xml/rss.xml':'GDACS'} %}
{% set suffix = trigger.event.data.title[0:5] %}
rss-feed-{{source[url] + '-' + suffix if url in source else 'Unknown'}}
Made me wonder if I couldn’t just add a unique id to each notification. Maybe a random number, but, being random, that doesn’t exclude an identical id…
Probably just need some extra logic to add a suffix _2, _3, _4, in case a second/third etc notification should arise.
And for that I would need some assistance… please have a look if and how you can help me out here, thanks!
secondly, Id need a dynamic binary sensor for any persistent_notification.rss_feed_xxxx goin on.
I’d start with the hardcoded entity_id’s, but since they will be hopefully changed into dynamic ones, that wouldn’t suffice. So I should need some very simple (…) logic to test if a persistent_notification exists, starting with the string ‘rss_feed’ in the object_id
{%set feed = states.persistent_notification
|map(attribute='object_id')
|list %}
{{feed}}
{{'rss_feed' in feed }}
but this renders False:
this however:
{%set feed = states.persistent_notification
|map(attribute='object_id')
|join %}
{{feed}}
{{'rss_feed' in feed }}
seems to work, but it feels utmost hacky:
binary_sensor:
platform: template
sensors:
rss_feeds:
entity_id:
- automation.notify_rss_feed_updated
friendly_name: Rss feeds
icon_template: >
{{'mdi:rss' if is_state('binary_sensor.rss_feeds','on') else 'mdi:rss-off'}}
value_template: >
{% set feed = states.persistent_notification
|map(attribute='object_id')
|join %}
{{'rss_feed' in feed }}
attribute_templates:
count: >
{% for state in states.persistent_notification %}
{% if 'rss_feed' in state.entity_id %}
{% if loop.first %}{{loop.length}}
{% endif %}
{% endif %}
{% endfor %}
feeds: >
{% set feed = states.persistent_notification
|map(attribute='attributes.message')
|list|join(',\n ') %}
{{feed if feed and 'New Rss feed' in feed else 'No Rss feeds'}}
Hope you can check for better syntax/logic … again, please have a look