How to use a dynamic entity_id in a "current state" node in Node Red?

If I use a static entity_id this simple automation works just fine:

As the debug message neatly contains the Kelvin value I am searching for:
image

This is the configuration of the “current state” node:
image

But when I change the “current state” node to have a dynamic entity_id, like this:
image

Then I get a “NaN” value…
image
And please note that the “msg.entity_id” value in the debug is exactly the same as the value for the static entity_id that I used previously.

I already looked at this answer here: Subflow with dynamic entity_id in curent_state
He uses “msg.entity_id” instead of “{{msg.entity_id}}” like I do. But that fails even harder. Then “msg.entity_id” is literaly interpreted as the entity_id and I get the error that this entity does not exist:
image

If i recall correctly, remove msg..
So {{ entity_id }}

3 Likes

That indeed does seem to do the trick. Thank you!

However, I keep wondering how I could have figured this out myself. Is there some documentation somewhere I missed?

Not that I’m aware of.
I believe I managed to find it by searching.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html

1 Like

Thanks! I haven’t seen that resource before, very handy.

Do you need more than {{ entity_id }} ?

When I enter this and deploy, it shows “not found” under the node.

When I excute the flow and trigger the node, I get:
msg : error
"InputError: "

sorry if this is a stupid question but do you have a node earlier in your flow that’s putting the entity id into msg.entity_id? If you’re not sure it’s going into the msg, or whether it’s in the right place use a debug node to check.

Thank you, yes I believe I do.

This is the debug output from the node feeding into the current_sate node:
image

well, that’s data.entity_id

@eggman That did the trick. Thank you :grinning_face_with_smiling_eyes: