Using nested subflows with variables

Hello, I am using node-red with home assistant and I am trying to use subflows to simplify my flows. I am trying to add a subflow to another subflow and both these subflows have environment variables defined for specifying sensor parameters.

But the issue is that I am unable to pass the env variable specified on the first level subflow to the nested subflow. Please find below an example of what I am working on.

When the motion sensor in this flow generates the "off" event, the event is passed to the "is room occupied" subflow which using the motion sensor name as a parameter. But it appears like the actual value of the parameter is not configured on this subflow and the value '${MOTION_SENSOR_1}' is supplied as is which results in the debug message: "Entity could not be found in cache for entity_id: ${MOTION_SENSOR_1}".

What is the correct way for propagating the value of MOTION_SENSOR_1 to the nested subflow?

Thanks in advance

[{"id":"808dc246.b3abf8","type":"tab","label":"Flow 1","disabled":true,"info":""},{"id":"985d7a7d.046068","type":"tab","label":"Office","disabled":false,"info":""},{"id":"bf9df284.9fa81","type":"subflow","name":"light automation","info":"","category":"","in":[],"out":[],"env":[{"name":"MOTION_SENSOR_1","type":"str","value":""},{"name":"MOTION_SENSOR_2","type":"str","value":"input_boolean.placeholder_boolean"},{"name":"MOTION_SENSOR_3","type":"str","value":"input_boolean.placeholder_boolean"},{"name":"LIGHT_GROUP","type":"str","value":"light.office_lights"}],"meta":{},"color":"#DDAA99"},{"id":"3f75a7d0.20c568","type":"subflow","name":"is room occupied?","info":"","category":"","in":[{"x":60,"y":50,"wires":[{"id":"906ab448.d5eb98"}]}],"out":[{"x":823,"y":44,"wires":[{"id":"906ab448.d5eb98","port":0},{"id":"c369aefd.f4feb","port":0},{"id":"a9134e7f.8b0e2","port":0}]},{"x":822,"y":133,"wires":[{"id":"c369aefd.f4feb","port":1}]}],"env":[{"name":"MOTION_SENSOR_1","type":"str","value":""},{"name":"MOTION_SENSOR_2","type":"str","value":"input_boolean.placeholder_boolean"},{"name":"MOTION_SENSOR_3","type":"str","value":"input_boolean.placeholder_boolean"}],"meta":{},"color":"#3FADB5"},{"id":"c62c93aa.9ec778","type":"subflow","name":"room motion","info":"","category":"","in":[],"out":[{"x":340,"y":80,"wires":[{"id":"df6fb9e6.d79878","port":0},{"id":"eae79bb0.b3135","port":0},{"id":"e2551086.645f7","port":0}]},{"x":580,"y":160,"wires":[{"id":"a53a99be.1d4de","port":1}]}],"env":[{"name":"MOTION_SENSOR_1","type":"str","value":"input_boolean.placeholder_boolean"},{"name":"MOTION_SENSOR_2","type":"str","value":"input_boolean.placeholder_boolean"},{"name":"MOTION_SENSOR_3","type":"str","value":"input_boolean.placeholder_boolean"}],"meta":{},"color":"#3FADB5"},{"id":"101bc28b.114dad","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"88aa30df.1bab48","type":"ui_base","theme":{"name":"theme-light","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"themeState":{"base-color":{"default":"#0094CE","value":"#0094CE","edited":false},"page-titlebar-backgroundColor":{"value":"#0094CE","edited":false},"page-backgroundColor":{"value":"#fafafa","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#1bbfff","edited":false},"group-borderColor":{"value":"#ffffff","edited":false},"group-backgroundColor":{"value":"#ffffff","edited":false},"widget-textColor":{"value":"#111111","edited":false},"widget-backgroundColor":{"value":"#0094ce","edited":false},"widget-borderColor":{"value":"#ffffff","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey","palette":"light"}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"2fb9684.9ae8318","type":"debug","z":"808dc246.b3abf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":240,"wires":[]},{"id":"c000e57d.5b883","type":"api-call-service","z":"808dc246.b3abf8","name":"turn on light group","server":"101bc28b.114dad","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"light.office_lights","data":"{\"brightness_pct\":40,\"color_temp\":175}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":550,"y":140,"wires":[[]]},{"id":"906ab448.d5eb98","type":"api-current-state","z":"3f75a7d0.20c568","name":"motion sensor 1","server":"101bc28b.114dad","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"${MOTION_SENSOR_1}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":242,"y":50,"wires":[[],["a9134e7f.8b0e2"]]},{"id":"df6fb9e6.d79878","type":"server-state-changed","z":"c62c93aa.9ec778","name":"motion sensor 1","server":"101bc28b.114dad","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"${MOTION_SENSOR_1}","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":60,"wires":[[],["a53a99be.1d4de"]]},{"id":"a53a99be.1d4de","type":"subflow:3f75a7d0.20c568","z":"c62c93aa.9ec778","name":"","env":[{"name":"MOTION_SENSOR_1","value":"${MOTION_SENSOR_1}","type":"str"},{"name":"MOTION_SENSOR_2","value":"${MOTION_SENSOR_2}","type":"str"},{"name":"MOTION_SENSOR_3","value":"${MOTION_SENSOR_3}","type":"str"}],"x":410,"y":160,"wires":[[],[]]},{"id":"467f749e.e7f3ac","type":"subflow:c62c93aa.9ec778","z":"808dc246.b3abf8","name":"office motion","env":[{"name":"MOTION_SENSOR_1","value":"binary_sensor.0x158d0002c38026_motion","type":"str"},{"name":"MOTION_SENSOR_2","value":"binary_sensor.0x158d000549d043_motion","type":"str"}],"x":110,"y":140,"wires":[["90d7dce6.4380e"],[]]},{"id":"90d7dce6.4380e","type":"api-current-state","z":"808dc246.b3abf8","name":"is room dark?","server":"101bc28b.114dad","version":2,"outputs":2,"halt_if":"10","halt_if_type":"num","halt_if_compare":"lt","entity_id":"sensor.0x158d000549d043_illuminance","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":320,"y":140,"wires":[["c000e57d.5b883","2fb9684.9ae8318"],[]]},{"id":"4c39ab28.0ce44c","type":"api-call-service","z":"bf9df284.9fa81","name":"turn on light group","server":"101bc28b.114dad","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"${LIGHT_GROUP}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":110,"wires":[[]]},{"id":"e15212db.36ec7","type":"subflow:bf9df284.9fa81","z":"985d7a7d.046068","name":"office lights automation","env":[{"name":"MOTION_SENSOR_1","value":"binary_sensor.0x158d0002c38026_motion","type":"str"},{"name":"MOTION_SENSOR_2","value":"binary_sensor.0x158d000549d043_motion","type":"str"}],"x":140,"y":80,"wires":[]},{"id":"dd5e7149.2d285","type":"api-call-service","z":"bf9df284.9fa81","name":"turn off light group","server":"101bc28b.114dad","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"${LIGHT_GROUP}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":190,"wires":[[]]},{"id":"9e58900b.4d4da","type":"debug","z":"bf9df284.9fa81","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":270,"wires":[]},{"id":"c369aefd.f4feb","type":"api-current-state","z":"3f75a7d0.20c568","name":"motion sensor 3","server":"101bc28b.114dad","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"${MOTION_SENSOR_3}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":643,"y":126,"wires":[[],[]]},{"id":"a9134e7f.8b0e2","type":"api-current-state","z":"3f75a7d0.20c568","name":"motion sensor 2","server":"101bc28b.114dad","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"${MOTION_SENSOR_2}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":442,"y":86,"wires":[[],["c369aefd.f4feb"]]},{"id":"eae79bb0.b3135","type":"server-state-changed","z":"c62c93aa.9ec778","name":"motion sensor 2","server":"101bc28b.114dad","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"${MOTION_SENSOR_2}","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":120,"wires":[[],["a53a99be.1d4de"]]},{"id":"e2551086.645f7","type":"server-state-changed","z":"c62c93aa.9ec778","name":"motion sensor 3","server":"101bc28b.114dad","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"${MOTION_SENSOR_3}","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":180,"wires":[[],["a53a99be.1d4de"]]},{"id":"d6193011.c414c","type":"subflow:3f75a7d0.20c568","z":"bf9df284.9fa81","name":"","env":[{"name":"MOTION_SENSOR_1","value":"${MOTION_SENSOR_1}","type":"str"},{"name":"MOTION_SENSOR_2","value":"${MOTION_SENSOR_2}","type":"str"},{"name":"MOTION_SENSOR_3","value":"${MOTION_SENSOR_3}","type":"str"}],"x":580,"y":180,"wires":[[],["9e58900b.4d4da","dd5e7149.2d285"]]},{"id":"47981511.56352c","type":"server-state-changed","z":"bf9df284.9fa81","name":"motion sensor 1","server":"101bc28b.114dad","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"${MOTION_SENSOR_1}","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":70,"wires":[["4c39ab28.0ce44c","9e58900b.4d4da"],["d6193011.c414c","9e58900b.4d4da"]]},{"id":"9b9ce30.b37272","type":"server-state-changed","z":"bf9df284.9fa81","name":"motion sensor 2","server":"101bc28b.114dad","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"${MOTION_SENSOR_2}","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":130,"wires":[["4c39ab28.0ce44c","9e58900b.4d4da"],["d6193011.c414c","9e58900b.4d4da"]]},{"id":"46d6a8ad.cc9f58","type":"server-state-changed","z":"bf9df284.9fa81","name":"motion sensor 3","server":"101bc28b.114dad","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"${MOTION_SENSOR_3}","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":190,"wires":[["4c39ab28.0ce44c"],["d6193011.c414c"]]}]