HomeHome AutomationNodeRED for beginners: 7. Tips & Tricks

NodeRED for beginners: 7. Tips & Tricks

Tips and Tricks to make your flows... flow better!

That’s the last post of this series with a couple of tips and tricks you might find handy while building your own flows. These will be totally random, this is why I left it to the end. Without further ado let’s jump to the tips

Tips & Tricks

Node Search

With time, your collection of nodes will grow and it’s going to be harder and harder to find all the nodes quickly. There are shortcuts you can use, especially one that no beginners tutorials mention it.

Ctrl+Left Mouse Click

This key shortcut will open an instant search window where nodes can be searched for and added to the flow. By the way, if you end up with the connecting line stuck to your mouse cursor, press Ctrl again to cancel the line.

Enable/Disable Flow

There might be a time when you need to enable or disable a particular flow for a reason. There is a very clever way of toggling this using only a couple of nodes. That toggle consists of two elements:

  • controller – it’s a node embedded into an existing flow that lets the messages go through based on a variable’s value
  • controlling flow – it’s a separate flow that sets the value, which is used to enable or disable the flow of the messages
Controlling flow

The controlling flow can be set in any way that suits you. The idea is to set a property: global.controller with a set node to true|false. You can use MQTT, HTTP, Timers or simple inject nodes to achieve this.

Once set, the property global.controller will be monitored by the controller node.

Controller node

This node should be inserted in such way, so it interrupts the stream of messages. It’s good to do this at the beginning of the flow to spare yourself processing an information that you will never send forward.

Based on the value of global.controller the change node lets the message true if the property of that variable is set to true.

Copy Nodes
[{"id":"d86084df.159b78","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"b672681a.7056b8","type":"inject","z":"d86084df.159b78","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":135,"wires":[["a525708e.8efe8"]]},{"id":"d4d819bd.156ff8","type":"inject","z":"d86084df.159b78","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["a525708e.8efe8"]]},{"id":"a525708e.8efe8","type":"change","z":"d86084df.159b78","name":"","rules":[{"t":"set","p":"controller","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":135,"wires":[[]]},{"id":"d3d3489c.863b58","type":"inject","z":"d86084df.159b78","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":240,"wires":[["8e00b4d0.f10a88"]]},{"id":"85e4ff93.c0c9d","type":"debug","z":"d86084df.159b78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":540,"y":240,"wires":[]},{"id":"8e00b4d0.f10a88","type":"switch","z":"d86084df.159b78","name":"","property":"controller","propertyType":"global","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":240,"wires":[["85e4ff93.c0c9d"]]}]

NodeRED Dashboard – set text colours dynamically

NodeRED Dashboard is great if you want to visualise your content quickly. One of the nodes available is a text node. Apart from setting the text node dynamically, you can change the colour of the text based on the property of the message sent.

You could use a Function node to select the values that Text Node should have:

switch (msg.payload) {

case true : 
    msg.color = "Green";
    msg.payload = "online";
    break;
    
case false : 
    msg.color = "Red";
    msg.payload = "offline";
    break;
    
default : 
    msg.color = "Gray";
    msg.payload = "not set";
    break;
}

return msg;

Formatted this way values can be passed over to the text node which has the Value Format set in the following way:

<font color= {{msg.color}} > {{msg.payload}} </font>

Doing so will change not only the text but also the colour of the text in your dashboard.

Copy Nodes
[{"id":"66dc2714.310a18","type":"ui_text","z":"fd7807e.3ae83f8","group":"205fd73e.b5c718","order":2,"width":"2","height":"1","name":"Desktop Staus","label":"","format":"<font color= {{msg.color}} > {{msg.payload}} </font>","layout":"row-spread","x":1175,"y":90,"wires":[]},{"id":"543091d5.79da6","type":"function","z":"fd7807e.3ae83f8","name":"Color Mapping","func":"switch (msg.payload) {\n\ncase true : \n    msg.color = \"Green\";\n    msg.payload = \"online\";\n    break;\n    \ncase false : \n    msg.color = \"Red\";\n    msg.payload = \"offline\";\n    break;\n    \ndefault : \n    msg.color = \"Gray\";\n    msg.payload = \"not set\";\n    break;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":965,"y":90,"wires":[["66dc2714.310a18"]]},{"id":"205fd73e.b5c718","type":"ui_group","z":"","name":"Computers","tab":"95ed8000.75e99","disp":true,"width":"6","collapse":false},{"id":"95ed8000.75e99","type":"ui_tab","z":"","name":"DIY Smart Socket","icon":"dashboard","order":2}]

Comments

Never underestimate the power of comments. Things that are obvious to you while working on a project, can become the puzzles again if you have to fix or improve a project year down the line.

Making appropriate comments in the Flow and using Comments Nodes to leave snippets of information, makes the troubleshooting and sharing your creations much easier. Double click on the Flow tab to open the Flow menu. There is plenty of space to explain how your flow should work, and what key features it contains.

Working with flows imported from the internet is so much easier once it consists the information about the structure.

Building your own library

Flow library

Once you get better with NodeRED, you will start copying previously solved problems into your new flows. While the copy and paste technique works, it might be easier for you to simply save the interesting flow into a library.

This way you can bring it back to any Flow space in no time! Select the nodes you want to save, then go to the export menu and pick library option to save it for a later use.

Function Library

The same can be done for all the snippets of code. The Function node allows you to export your snippets and save it in the library. If you forgot how the code should look like for composing an HTTP POST, or case snippet for the text colour, you can simply save the code for later.

End of the NodeRED Tutorial

Feel free to check out my other NodeRED resources, there is a designated menu just for the NodeRED projects!  I hope this tutorial helped you, and you are ready to build awesome home automation setups.

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

DIY Smart Washing Machine – for about 15 bucks!

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

Sonoff Zigbee Bridge – review

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

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.