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

Nora – Google Assistant in NodeRED

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

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

Smart Home

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?

Sonoff for households and gardens

0
ITEAD released two ZigBee devices to manage water in your household and gardens. Now you can monitor the flow and dispense water with Sonoff SWV and prevent water damage using the Sonoff Water Leak sensor with a twist.