HomeHome AutomationNodeRED 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.

Debugging

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"}

Conclusion

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.

PayPal

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

Patreon

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

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

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

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

Learn NodeRED

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

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

Best Automation Projects

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

Smart Home

Multi-lights for your ceiling from Aqara

0
This is the biggest light I held in my hands so far. It's ZigBee and it comes from Aqara - meet Aqara Ceiling Light T1M

Almost the fastest PIR sensor you can buy

0
ITEAD introduced a new ZigBee sensor - Sonoff PIR (SNZB-03P) which is also the fastest PIR sensor in their line up. Is it good? Read more!

Smart Panel automation by Tuya

0
I'm checking out two smart panels by Tuya. Both run Linux systems, fit inside the wall switch cavity and offer a range of automation options

Adding Matter to Sonoff BasicR4

0
Sonoff goes back to basics with Sonoff BasciR4 - a new and improved basic smart relay - and I'm about to add Matter to it (and Tasmota)

Sonoff Presence Sensor (SNZB-06P) is not what you think

0
This mm wave radar sensor combines cool tech and ZigBee 3.0, but it's not what you think it is. Closer look at Sonoff Presence Sensor