ok ok . I hear ya. here’s the full package:
##########################################################################################
# Feedreader
# @mariusthvdb 26022020
##########################################################################################
homeassistant:
customize:
binary_sensor.rss_feeds:
templates:
icon: >
if (state == 'on') return 'mdi:rss';
return 'mdi:rss-off';
icon_color: >
if (state == 'on') return 'green';
return 'grey';
sensor.persistent_notifications:
templates:
icon: >
if (state > '0') return 'mdi:message-bulleted';
return 'mdi:message-bulleted-off';
icon_color: >
if (state > '0') return 'green';
return 'grey';
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'} %}
{{as_timestamp(now())|timestamp_custom('%X %d-%b-%Y', true)}}: 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'} %}
{% set object_id = 'rss-feed-' ~ source[url] if url in source else 'Unknown' %}
{% set object_id = object_id.replace('-','_').lower() %}
{% set object_ids = states.persistent_notification|map(attribute='object_id')|list %}
{% set found = namespace(values=[]) %}
{% for o_id in object_ids %}
{% if o_id.startswith(object_id) %}
{% set found.values = found.values + [ o_id.replace(object_id,'').replace('_','') | int ] %}
{% endif %}
{% endfor %}
{% if found.values %}
{% set next = found.values | max + 1 %}
{{ object_id ~ '_' ~ next }}
{% else %}
{{ object_id }}
{% endif %}
# https://community.home-assistant.io/t/how-to-add-unique-id-to-persistent-notification-and-binary-sensor/175066/4
# original id with suffix title[0:5]
# {% 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'}}
# {% 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'}}
- alias: Update Rss feed sensors
trigger:
- platform: event
event_type: feedreader
- platform: event
event_type: call_service
event_data:
domain: persistent_notification
service: dismiss
action:
service: homeassistant.update_entity
data:
entity_id:
- binary_sensor.rss_feeds
- sensor.persistent_notifications
#persistent_notification.home_assistant_podcast_60_0_103_sonos_takes_over_snips_and_ending_the_year_with_frenck
#
# {% set url = 'https://www.home-assistant.io/atom.xml'.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'}}
# {{url}}
#{{ states.persistent_notification|map(attribute='entity_id')|list}}
sensor:
platform: template
sensors:
persistent_notifications:
# entity_id: sensor.time
friendly_name: Persistent notifications
value_template: >
{{states.persistent_notification|list|length}}
attribute_templates:
notifications: >
{{states.persistent_notification|list|join(',\n ')}}
icon_template: >
{% if states('sensor.persistent_notifications') > '0' %} mdi:message-bulleted
{% else%} mdi:message-bulleted-off
{% endif %}
binary_sensor:
platform: template
sensors:
rss_feeds:
# entity_id:
# - sensor.persistent_notifications
# - 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'}}
and Lovelace card:
type: vertical-stack
cards:
- type: conditional
conditions:
- entity: binary_sensor.rss_feeds
state: 'on'
card:
type: markdown
# style: |
# ha-card {
# box-shadow: none;
# height: 33px;
# background: none;
# padding: 0px 10px;
# color: var(--header-color);
# }
content: >
**{{state_attr('binary_sensor.rss_feeds','count')}} Rss feed notification{{'' if is_state_attr('binary_sensor.rss_feeds','count','1') else 's'}}:**
{{'\n'}}{{'\n'}}
{% for state in states.persistent_notification %}
{% if 'rss_feed' in state.entity_id %}
{{'**' + state.attributes.message.split(',')[0] + ':**'}}{{'\n'}}
{{state.attributes.title}}{{'\n'}}
See: {{state.attributes.message.split('see ')[1] }}
{{'\n'}}{{'\n'}}
{% endif %}
{%- endfor %}
- type: entities
entities:
- entity: binary_sensor.rss_feeds
secondary_info: last-changed
- entity: sensor.persistent_notifications
secondary_info: last-changed
- type: divider
- entity: automation.notify_rss_feed_updated
secondary_info: last-triggered
- entity: automation.update_rss_feed_sensors
secondary_info: last-triggered