Problem using rejectattr "generator object select_or_reject

Hi,

I configured a sensor using the Multiscrape add-on.
This sensor has 24 attributes (I am scraping a timetable).

To display the sensor’s attributes states in a markdown card I use the following template:

{% set d = states.sensor.tram_horaires2.attributes %}
{% for x in d %}
  {{ state_attr('sensor.tram_horaires2',x) |replace("\n"," ") | replace("tram_horaires2","")}}
{% endfor%}

By iterating through all attributes, I also bring in the “friendly_name” attribute which I don’t need.
So I replace it with an empty string in the result.
No very elegant.

I tried to use filter rather than a loop:

{{ states.sensor.tram_horaires2 | rejectattr('attributes.friendly_name','ne','tram_horaires2') }}

But this results in

<generator object select_or_reject at 0xffff7bb9c160>

Can you help me figure out how to use the rejectattr filter ?

Pipe that into list to see the output. You could then set a variable to that and do more code depending on what you want to do.

{{ states.sensor.tram_horaires2 | rejectattr('attributes.friendly_name','ne','tram_horaires2') | list }}

The propose line ends up with “Invalid key”.

What maybe weird is how the states looks:
This:

{{ states.sensor.tram_horaire2   }}

Returns this:
<template TemplateState(<state sensor.tram_horaire2=25/01/2024; tram_6h=6:00