Node-RED

Build a temperature reminder with simulated readings, readable debug output, and a rule that does not chatter near its threshold.

Node-RED logo

Ingredients

Follow a part’s name for an introduction and compatibility notes.

Node-RED passes messages between small connected blocks called nodes. A flow can receive a sensor reading, reject bad data, apply a rule, and send a notification. Start with numbers you control so that you can test the rule before connecting a sensor.

Run a local practice instance

Follow the installation instructions for your operating system, including its supported Node.js requirement. For this desktop exercise, start a separate user directory and bind the editor to loopback:

node-red --userDir ./novelide-node-red -D uiHost=127.0.0.1

Open http://127.0.0.1:1880 on that computer. The folder is created relative to your terminal’s working directory; use the same directory when restarting. Stop with Ctrl+C. If the port is busy, add --port 1881 and use that port in your browser. This command does not change an existing service installation.

Import or build the flow

Download the complete practice flow. In the editor choose Import, select the downloaded JSON, import it into a new flow, and click Deploy. It uses only built-in Inject, Function, and Debug nodes.

To build it manually, connect an Inject node to a Function node and then a Debug node. Set the Inject payload type to number, initially 25; set Debug to show msg.payload. Put the following code in the Function node. The downloadable flow provides five convenient test buttons.

const value = msg.payload;
if (typeof value !== "number" || !Number.isFinite(value)) {
    node.warn("Expected a finite numeric temperature");
    return null;
}
let warm = context.get("warm") === true;
if (value >= 28) warm = true;
else if (value <= 26) warm = false;
context.set("warm", warm);
msg.payload = { temperatureC: value, warm: warm };
return msg;

The incoming msg is an object, and payload is its data. Returning null stops an invalid message. Node context remembers the warm state between messages; the default in-memory context resets when the runtime restarts.

Test the threshold and the gap

Press the Inject buttons in this order: 25, 29, 27, 26. Debug should report warm states false, true, true, false. At 27 °C, the rule keeps its previous state. This gap between the on and off thresholds is hysteresis: it avoids rapid switching when a reading fluctuates around one boundary.

Press Invalid text. You should get a warning and no new result. A string containing “29” is also rejected on purpose; validate and convert a real sensor’s message in a separate step. Do not quietly treat a disconnected sensor as a temperature of zero.

Connect a real source later

Replace the Inject input with an MQTT input or another documented sensor interface after the sequence works. Preserve its unit, timestamp, and source ID. Add a timeout that marks the reading unavailable if updates stop. This sample emits a result for each valid message; add a change-detection stage before sending notifications so repeated readings do not spam you.

If Debug is empty, deploy changes, check the wire direction, enable the Debug node, and inspect the selected sidebar tab. If the state seems wrong at 27, remember that the previous value matters; send 25 to reset the experiment.

A Node-RED editor can change executable flows. Before allowing another device to reach it, configure authentication and transport security using the official security guide. Next, give a sensor and its reader separate MQTT permissions.