Mustache templates for entity id work in call service node but not server state changed node?

So I set some global variables that define various entity_ids.

If I use the call service node (api-call-service) and use mustache templates for the entity_id like this

{{global.kitchen_light}}

Everything works just as if I had put the entity id in directly.

But in the events: state node (server-state-changed) if I use the exact same mustache template for the entity_id field nothing works. No state change is ever registered.

Can I not use mustache templates in that node? Is there a workaround?

Mustache templates don’t work in event nodes entity id fields. There’s no workaround for it that I can think of and probably won’t be because at the time of deployment it needs to know what to listen for. There is no way to track when a global variable gets updated to then update the event node.

Interesting, and I guess that kind of makes sense the way you describe it. Because yeah, the global could change, but then the event node wouldn’t know that it changed, since it is initiated at deployment. The other nodes, like call service, get updated when something triggers them.

So maybe related then…is there a way to have a variable assigned to the entity id that would get updated just at deploy?

My main goal here is to have like something akin to an ‘environment’ table where I have variables with say ‘kitchen light’ and ‘bedroom light’. And then assign individual light bulbs to those variables. I would then build my flows using the variables ‘kitchen light’ or ‘bedroom light’, and then let that variable assign the corresponding entity_ids to those nodes. I can then have many flows that reference the ‘kitchen light’. But then, if I need to change bulbs around or buy a new one, I can just update the ONE kitchen light variable with the new entity_id of the new light bulb. Then re-deploy. And have everything upated in all the flows that reference that variable.

Right now I would have to hunt through and find all events for kitchen light. And then all events with bedroom light, and on and on for everything in multiple different flow if I ever change bulb location/identity id’s around.

In regular programing you would have some sort a variable declaration file and then everything would reference those variables. Right now I have to retype everything in multiple places to update changes to entity_ids.

Is there a better way to do this? Maybe something other than mustache templates, something I don’t know about.

You could try using environment variables. I use them for nodes that require lat and lon.

https://nodered.org/docs/user-guide/environment-variables

Awesome. Thank so much. This worked. I just put this at the top of my settings.js file

process.env.LIGHT_BEDROOM01_MAIN01 = "binary_sensor......";

And now in my events:state node I can just put the following for the entity_id field

${LIGHT_BEDROOM01_MAIN01}

And it picks it up. This is exactly what I needed. Thanks again.