Home Home Automation NodeRED for beginners: 3. Your First Flow

NodeRED for beginners: 3. Your First Flow

Time to build the first flow!

We talked about why you should get NodeRED in the first place, and how to get started with NodeRED, now it’s time for your first flow. The flow is not going to do anything amazing, other than illustrate the basics of how the nodes and flows work. You will be able to start your own automation setups. I’m using an example which won’t require any other devices or additional nodes to be installed.

NodeRED for beginners: 3. Your First Flow

It’s good to start somewhere and the input nodes are a good way to start your flow. The nodes will introduce some sort of data into the NodeRED server. You can use single or multiple nodes. In this example, I’m using 2 input nodes. These will enter a number (8 & 15) when a button is pressed, and this will represent a trigger.

When the button is pressed a message is created. This message often is referred to as the payload. I will cover the data processing in details in the next part of this series. Typically messages come with a payload and topic. You can assign these two in settings of the input node.

Both nodes are linked with a switch node which will evaluate the value and send it to correct output of the node. As you can see, it is possible to have multiple outputs from a single node depending on the outcome. You can do so by using “add” option at the bottom. I’m going to evaluate the numbers against the value 10 and send it one or the other direction.

The payload will reach one of the change nodes. These will, in this example, assign a new topic to the payload. You will see that you can simply overwrite the value stored as the topic. As we are only going to change the topic (msg.topic), the payload will be moved over further unchanged.  It’s important to know when the payload is modified.

Both change nodes come together to function node. It’s one of the most powerful and complicated nodes to use. The node is blank by default and allows you to enter the JavaScript code.  This node requires some programming experience, but for now, we will keep it very simple:

var value = msg.payload;
msg.value = value;
return msg;

Let’s quickly evaluate the script. I’m creating variable value, which will store the data from the payload.  In this case, it’s the number. Then, I’m saving this value as a part of the payload which is not going to be modified by normal nodes.

Lastly, the payload and the topic will be used to set a string using a template message. Template node is easy to use, as all you have to do is enclose the payload and topic with {{…}} (mustache template mode) and entire message will be stored as a new payload.


I have tested the flow and I know what will happen. To show you how the data is sent through the flows, I’m going to use debug nodes attached to each state of our transformations. The debug node can display the entire message (object) or a specific part of the message: msg.payload for payload and msg.topic for the topic.

We are going to monitor the topic and the payload. The last node will display the entire object message. The debug menu will let you know which message belongs to which node. Just highlight the node ID or give custom names to each node.

After deploying the flow, you can see when the inject node is activated, the number passes through each node, and the topic is changed accordingly. In addition, we have a payload as a result which is:

The new value is: high value and quals 15 !

or as an object:

{"_msgid":"18a7c16a.fd711f","topic":"high value","payload":"The new value is: high value and quals 15 !","value":"15"}


You should know the principles of working with NodeRED,  In the next part, I’m going to focus specifically on the data structure, how information is processed, stored and recalled. That’s going to be a very important part to truly understand the NodeRED and underlying principles.


Nothing says "Thank you" better than keeping my coffee jar topped up!


Support me on Patreon and get an early access to tutorial files and videos.


Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

To server or not to server? That's a very silly question!

Best Automation Projects

ESP8266 WIFI lights under $5

Your Sonoff device can't do this!

Free wireless doorbell (Amazon Dash button hack)

The most terrifying situation I can imagine* is missing a parcel

New Amazon Dash Buttons

You can teach new buttons old tricks!

ESP8266 ceiling light – demo

Testing the ESP8266 as a WIFI light controller

Try Tasker and Raspberry Pi for your home automation needs!

Raspberry Pi can help you with your Tasker profiles

Smart Home

Sonoff ZBMINI is in town!

ITEAD released a new product - Sonoff ZB Mini - a smarter twin brother of Sonoff Mini!

Testing 9 external antennas with CC2531 ZigBee coordinator

I have tested the range and the link quality of 9 external antennas with CC2531!

I have infinite buttons thanks to Aqara Opple

Gaming on Switch meets IoT - can you play games on Aqara Opple? Apparently you can! This and more uses of the connected wall switch

Smart lights won’t save you money

It's pretty clear how much power a smart light draws when turned on, but have you ever wonder how much do you pay to have it connected 24/7?

Alexa Routines: Setting volume on all Echos at once

Setting volumes on all Amazon Echo devices at once doesn't have to be a chore!