What's wrong with this icon template? nothing

Understood.

Sounds like the template itself works but home assistant couldn’t parse the entity to update it on.
This is why for template sensors themselves, there is an option to supply the entities to update on separately. Did you try the noninline if else block in the actual template (not the template editor)?

I should have asked if this entity is a template binary sensor, if so, you can supply those entities.

yeah, I have already tried that, and indeed have set entity_id’s. But of course this is quit silly. just made another one to experiment:

sensor:
  platform: template
  sensors:
    persistent_notifications:
      friendly_name: Persistent notifications
      value_template: >
        {{states.persistent_notification|list|length}}
      attribute_templates:
        notifications: >
          {{states.persistent_notification|list|join(',\n ')}}

doesn’t update, not even on startup, (maybe the notifications aren’t ready yet, but even when they arise, this template sensor stays 0.

and the reason I made this was to put in the binary_sensor above as an entity_id :wink:

You should specify which sensor should update the template into the entities section

The status of this states.persistent_notification probably never picks up as changing. At startup, your sensor night initiate before this entity too. Therefore it well never update unless manually.

That would be surprising wouldn’t it? Ive taken as complete as possible on purpose, so it would change in the minutest detail…in state or attributes.

guess Ill add sensor.time to this :wink:

answering

with the above too, thanks. Expected this not to be necessary.

states.persistent_notifications is actually the component that has entities inside. The component itself has no state that can change therefore the template doesn’t know that an entity inside changed.

before I have to enter all known entities, or sensor.time on all sensor, Ill just use thus automation I think:

automation:
  - 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

not sure if that takes less core cycles, or truly is lighter on the system, but it should do as I want… update 2 little sensors, on certain events. the creation of the feed and the dismissal of the persistent notification.

agree, generally the same as for group.xxx.

I’d prefer to see the whole sensor’s config… @Mariusthvdb ?

I agree. We seem to just get bits and pieces of this story. I do think that the entity update service is probably the right method here, but hard to say.

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

there was no need to post the whole package, really :wink:
As far as I can see, your problem is with sensor.rss_feeds, sensor.persistent_notifications and binary_sensor.rss_feeds.
They won’t work as you wish as already explained (basically - HA extracts what is after states., is_state() etc and treats it as entity_id. In case of states.persistent_notification it will lead you nowhere. And maybe because of that there will be no updates to attributes.

The easiest way is to add entity_id: sensor.time to your sensors as described in docs.
Or change your approach.

Tbh the whole config now works as desired.
No brute force updates per minute, but on event.

All sensors update accordingly and I’ve got a nice view in the frontend :wink:

Next up to try and create a button in the markdown config to dismiss the notifications, or, if not possible, add them to the entities of the entities card. Never finished…

so what did you change to make it work? homeassistant.update_entity on state changes?

I think the title of this post needs to be changed. :wink:

to…? (10 chars limit boo)

Why won’t these sensors update?

its in the package… update on feedreader event and dismissal of pers not.

what sensors? if you’re talking about your sensor.persistent_notifications and still are not convinced, read this explanation and have a look a bit down as it’s referenced from there:

p.s I’m not quite sure about the way you add icons but if it works… then I need to learn something new :wink:

This was a title change suggestion…

And I am sure about the icon changes :wink: