Add the state of a counter to a template

trying to add the state of a counter (number/integer) to a template.
tried these 2 options unsuccessfully; can you help pinpoint the issue(s) or suggest a better approach? Thanks!

- image:
    url: >-
       {% set N = states('counter.news_rss_counter') %}
       {{ state_attr('sensor.radio_canada_rss', 'entries')[N].image }}
    name: "test"
- image:
    url: "{{ state_attr('sensor.radio_canada_rss', 'entries')[{{ states('counter.news_rss_counter') }}].image }}"
    name: "test2"    

Try this:

- image:
    url: >-
       {% set N = states('counter.news_rss_counter')|int %}
       {{ state_attr('sensor.radio_canada_rss', 'entries')[N].image }}
    name: "test"

Thank you, that was it =)

1 Like

Everything works as expected but one more thing to improve my skills :

the “image.test” entity created will just contain the url/link and not the image file itself; so it is normal not to find the actual image under the local www folder and using the image entity in a card will just fetch the image from the url; are my assumptions correct?

Correct.

The image is fetched for display in the frontend when you put the entity in a picture card or similar and your web browser visits that page.

Perfect. Thanks for your support, much appreciated.