Error while trying to create Blueprint for Telegram notification

I want to create a simple blueprint to check that all my relevant entities are connected and not unknown or unavailable. I want to use a command within Telegram that returns a list of all the entities I have selected in a blueprint and shows whether each of them has_value or not. The message is composed of a for-loop that iterates through all the inputs of the blueprint. It sounded simple at first, but now I’ve been struggling for several hours and I just can’t figure out what the problem is.

Let’s say I have a variable called input_entities that contains all the entities I select in the blueprint. The for-loop to generate the message would look like this. It is simplified without the has_value check for the sake of this post.

message: >-
  {% for u in input_entities %}{{states.u.name}} >> {{has_value(u)}}
  
  {% endfor %}

I get the following result:

None >> True
None >> True

As you can see, it doesn’t give me the correct name, just “None”. If I take one of the values of u and put the exact same statement into the template editor in the developer tools, it returns the correct name. So there seems to be something wrong here.

At first I wasn’t sure how the for-loops were converting the provided list of entities into single items, since in the list itself each item is enclosed in inverted commas. So I tried using

{{states.u|safe.name}}

But it seems like whenever I use |safe anywhere in the loop, the creation of an automation from the blueprint fails with the following error message:

Message malformed: template value should be a string for dictionary value @ data[‘action’][0][‘data’]

Fun fact: Whenever I got this message, I had to do a quick reload of the YAML configuration in the admin tools to get rid of this error. If I don’t do that, I ALWAYS get this error, no matter how the message is composed. It took me quite some time to figure this one out…

So instead, I tried to remove the inverted commas that I wasn’t sure were really there:

{{states.u|replace("'", "").name}}

But I got the same error as above.

So yeah, right now I’m running out of ideas. Anything else I could try to make this finally work?

sounds like a fun learning activity.
I came up with something a bit simpler I use here at home. Watches 1 entity at a time and gives you several levels of action statements to fix it autonomously.

To help with the actual problem, I would jump over to configuration templates and one of the guru’s will see it faster and give you a hand. My Jinja-foo is not up to answering that question.