---
title: "Discussion on \"Creating subflows in Node-Red\" | Hashnode"
description: "Discussion on \"Creating subflows in Node-Red\". In my opinion, one of the most useful features that Node-Red has to offer is the ability to create subflows. According to the  official documentation , subflows are:\n\na collection of nodes that are collapsed into a single node in the workspace.\n\nI wo..."
url: "https://hashnode.com/posts/creating-subflows-in-node-red/5f909e006aa1ed54804ba01e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Creating subflows in Node-Red](https://bogdanbujdea.dev/creating-subflows-in-node-red?utm_source=hashnode&utm_medium=feed)

In my opinion, one of the most useful features that Node-Red has to offer is the ability to create subflows. According to the official documentation , subflows are: a collection of nodes that are collapsed into a single node in the workspace. I wo...

Oct 21, 2020 · 7 min read · bogdanbujdea.dev  
Read the article

-   [#programming](https://hashnode.com/tag/programming)
-   [#2articles1week](https://hashnode.com/tag/2articles1week)
-   [#smart-home](https://hashnode.com/tag/smart-home)

## Written by

[Bogdan Bujdea](https://hashnode.com/@bogdan)

@bogdan · Iasi, Romania

  
[View profile](https://hashnode.com/@bogdan)

.NET Developer

Expert generalist • Independent Contractor • Microsoft MVP • Home Assistant enthusiast Hi there! I'm Bogdan Bujdea, a software developer from Romania. I'm currently a .NET independent contractor, and in my free time I get involved in the local .NET community or I'm co-organizing the @dotnetdays conference. I consider myself an expert generalist, mostly because I enjoy trying out new stuff whenever I get the chance and I get bored pretty easily, so on this blog you'll see me posting content from programming tutorials to playing with my smart gadgets.

## Responses 3

Markdown supported · ⌘↵ to post

[John Dyer](https://hashnode.com/@johntdyer)

[Jul 13, 2023](https://hashnode.com/posts/creating-subflows-in-node-red/5f909e006aa1ed54804ba01e/comment/64b00f4c3910a270b4c98f3f)

Nice article, you should past a link to a gist w/ the json

[Casper Smits](https://hashnode.com/@caspersmits)

[Oct 23, 2020](https://hashnode.com/posts/creating-subflows-in-node-red/5f909e006aa1ed54804ba01e/comment/5f9289aec626a0545fb61f4c)

Great article! Last week I discovered two (advanced?) things that you might be interested in: getting flow variables in subflows and the status message

### Getting a flow variable from a subflow

The sun position dictates a flow variable in my lights automations. It sets a brightness modifier so I'm not blinded at night. This is how I format the JSONata for the `light.turn_on` service call:

```
{
   "transition": 2,
   "brightness_pct": ( 0.01 * $flowContext('$parent.sun_brightness_modifier') ) * $env('BRIGHTNESS_BASE')
}
```

Mind the `$flowContext('$parent.variable_name')` syntax: with $parent you get access to the subflows parent variables.

### Outputting a node status for a subflow:

The `status` node lets you update the message that's underneith the subflow node. Now, my formatting is not very pretty but the information is very useful!

![afbeelding.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603438971072/cbz_4r6VC.png)

![afbeelding.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603438906559/KV6xl8W34.png)

The JSONata for the message formatting:

```
{
  "fill": "green",
  "shape": "dot",
  "text": $join(['On:', $env('ENTITY_ID'), "at:", $now()], ' ')
}
```
