Pass entity_id in msg.payload to Subflow parameter

Hello,

I apologize for the question, because I know the answer is going to be simple. But, I have looked and looked and have not found it.

I have 20 fans in my house. I want to run each fan for 2 minutes a day. (Tropical climate)

So, I created a simple flow that:
a) checks to see if fan is running, and if not
b) runs fan for 2 minutes,
c) stops fan.

Simple. But I am using this in a subflow, and I want to pass the entity_id of the fan to the subflow.

So in the calling flow, I use the “Current State” node to check if it is running. The msg.payload from this is the name of the fan.

In the subflow I have an environment variable:

FAN_NAME

So, my question is, how do I pass msg.payload to the environment variable FAN_NAME?

I have tried a zillion combinations of $msg.payload, or {msg.payload} or {"{{msg.payload}}"} and all of these without the “msg.” (only payload), and nothing seems to work.

I suspect this answer is one line.

Many thanks

1 Like

You don’t. There are other threads about env variables being constants. I understand they are evaluated when you deploy, and cannot be changed without another deploy.

Instead, change your subflow to use (for example) msg.entity_id if it exists, or $env('entity_id') if it doesn’t. Or the other way around if you would like the priority reversed.

EDIT: Actually here is a pretty definitive answer from the guy who started Node Red:

You cannot set environment variables at runtime. They are only evaluated when flows are started.