Node-RED: Storing Bosch Smart Home Room Names in the Global Context
In this post, you’ll learn how to read the room names from your Bosch Smart Home system using Node-RED and store them in the global context. This lets you use clear, understandable room names instead of cryptic IDs in your flows, making your automations easier to follow and maintain.
Key Takeaways
- Clarity: Replace technical room IDs with readable names in your Node-RED flows.
- Global Context: Learn how to store data centrally so it’s accessible across different flows.
- Bosch Smart Home API: Use your Bosch Smart Home Controller’s local API to query room info.
- JavaScript in Node-RED: Understand the simple code that extracts and stores room names.
- Efficiency: Query room names once (e.g., daily) and reuse them from storage anytime.
Table of Contents
- What is Node-RED?
- What’s the Global Context in Node-RED?
- Why Store Room Names?
- Prerequisites
- The Node-RED Flow Explained
- How Do I Access the Stored Room Names?
- Use Cases
- Important Notes
- Complete Flow for Import
What is Node-RED?
Node-RED is a visual programming tool originally developed by IBM and now an open-source project. It allows you to connect hardware devices, APIs, and online services in creative ways. Think of it as a digital construction kit: you drag pre-built blocks (called “nodes”) onto a workspace and wire them together to build “flows.” These flows define how data is processed and what actions are triggered. This makes it super easy to create complex automations for your smart home or other IoT projects—often without writing a single line of code. It’s especially popular for making devices from different manufacturers work seamlessly together.
What’s the Global Context in Node-RED?
Node-RED provides a way to store information that can be shared between different nodes—or even different flows—without having to pass that data directly through messages (the “msg” objects). This is called context storage. There are three levels (scopes) of context:
- Node Context: Data is only available within the single node that stored it. Useful for internal state within a function node.
- Flow Context: Data is accessible to all nodes within the same flow (i.e., the same tab in the editor).
- Global Context: Data is available across all nodes in your entire Node-RED instance, spanning all flows.
For our goal—making Bosch Smart Home room names available system-wide—the global context is the way to go. This lets us fetch and store the names once, then access them from any other flow, such as notification flows or dashboard displays. We use global.set("variableName", value)
to save data and global.get("variableName")
to retrieve it from the global context.
The global context is perfect for managing system-wide info like configurations or rarely changing status data in one central place.
Why Store Room Names?
When you interact with the Bosch Smart Home Controller (SHC) via its API or special Node-RED nodes, many queries return technical room IDs (like “hz_123…”). While these IDs are unique, they’re not exactly user-friendly or easy to understand. If you want to send a notification like “Window opened in Room X,” you’d probably prefer to see “Window opened in the Living Room” rather than “Window opened in hz_123.”
By fetching the list of all rooms just once and saving the ID-to-name mapping (e.g., {"hz_10": "Living Room", "hz_24": "Kitchen"}
) in the global context, you create a kind of central “lookup table.” Any other flow can then simply take an ID, look up the matching room name in the global context, and produce human-readable output. This makes your flows easier to understand, debug, and maintain.
Prerequisites
Before getting started, make sure you have the following in place:
- A running Node-RED instance.
- A Bosch Smart Home Controller (SHC) that can be reached on the same network as your Node-RED setup.
- The IP address of your SHC.
- Credentials and/or certificates for the SHC’s local API. The Node-RED module node-red-contrib-bosch-shc is often helpful as it supports connection setup and pairing. Alternatively, as shown in this flow, you can talk directly to the API via HTTP Requests—but you’ll need valid certificates for that.
Note: Communication with the SHC’s local API happens over HTTPS (port 8444) and requires proper certificate configuration in Node-RED.
The Node-RED Flow Explained
At the heart of this project is a simple Node-RED flow that fetches and processes room info from the SHC.
Step 1: Fetch Rooms (HTTP Request Node)
The first active node in the flow is an HTTP Request Node. This node is responsible for querying data from the Bosch Smart Home Controller. It sends a GET request to the SHC’s local API.
- Method: GET
- URL:
https://<Your-SHC-IP-Address>:8444/smarthome/rooms/
(Replace<Your-SHC-IP-Address>
with your controller’s actual IP address.) - Return type: Select “a parsed JSON object” since the API returns data in JSON format.
- TLS Configuration: Here you need to select or create a TLS configuration that includes the required certificates to establish a secure connection to the SHC. This step is crucial because the connection uses HTTPS. The module
node-red-contrib-bosch-shc
can help with generating these certificates, or you can obtain and configure them manually in Node-RED.
If the request succeeds, msg.payload
will hold an array of objects, each representing a room with its ID, name, and other details.
Step 2: Process Data (Function Node)
The next node is a Function Node. This is where the main logic happens to process the incoming data and store it in the global context. The node takes the array from msg.payload
and executes the following JavaScript code:
// Initialize an empty object to store room names by their IDs
let roomNames_BSH = {};
// Check if msg.payload is an array
if (Array.isArray(msg.payload)) {
// Loop through each element (room) in the array
msg.payload.forEach(room => {
// Check if the room object has both 'id' and 'name' properties
if (room.id && room.name) {
// Assign the room name to the object using the room ID as key
roomNames_BSH[room.id] = room.name;
}
});
// Save the roomNames_BSH object into the global context
// so it can be accessed from other parts of the flow
global.set("roomNames_BSH", roomNames_BSH);
// Optional: Output a warning message to indicate the data was saved
node.warn("Rooms saved in global context under 'roomNames_BSH'");
} else {
// If msg.payload is not an array, log an error
node.error("msg.payload is not an array");
}
return msg;
What’s going on here, step-by-step?
let roomNames_BSH = {};
: Creates an empty JavaScript object calledroomNames_BSH
. This will hold our mapping of room IDs to room names.if (Array.isArray(msg.payload)) { ... }
: Checks to make suremsg.payload
really is an array, as we expect from the HTTP request. This is important validation.msg.payload.forEach(room => { ... });
: If it is an array, it loops through each room object in the array.if (room.id && room.name) { ... }
: For each room, it checks whether both anid
and aname
exists.roomNames_BSH[room.id] = room.name;
: When both are present, it adds an entry toroomNames_BSH
where the key is the room’s ID (e.g. “roomRoomOid_abc123”) and the value is the room’s name (e.g. “Living Room”).global.set("roomNames_BSH", roomNames_BSH);
: After all rooms are processed, it stores the entireroomNames_BSH
object in the global context under the key “roomNames_BSH”—making it accessible everywhere.node.warn(...)
: An optional warning message is output to the debug sidebar to confirm that the save was successful.else { node.error(...) }
: Ifmsg.payload
isn’t an array, it logs an error.return msg;
: Passes the original message on in case downstream nodes need it.
Step 3: Trigger (Inject Node)
The flow starts with an Inject Node. This node kicks off the entire process. In the example flow, it’s set to run once daily at noon (a “cron job”), but you can customize it however you like:
- Manual: Click the button on the node to trigger the flow on demand.
- On Startup: Configure it to trigger once when Node-RED starts or when the flow is deployed.
- Scheduled: Set a recurring interval (e.g., every 24 hours) or a specific time (like in the example) to regularly refresh room names. Since room names rarely change, a daily update is usually enough.
Step 4: Debugging (Debug Node)
At the end of the flow, there’s an optional Debug Node. This is very helpful during development as it shows the messages arriving at it. You can attach it right after the HTTP Request node to see the raw data from the SHC, or behind the Function node (as in the example, but disabled) to check that processing worked correctly and what the Function node outputs. To verify that the data actually landed in the global context, check the context data tab in Node-RED’s sidebar or add another node that uses global.get()
.
Accessing Stored Room Names in the Context
Once the flow has successfully run at least once, the room names are saved in the global context. You can now access them inside any Function Node throughout your Node-RED instance.

Use Cases
With stored room names, you can significantly enhance your smart home automations:
- Notifications: Send clear messages to your phone or via voice assistants: “Heating set to 22°C in the Bathroom,” instead of “… in hz_123…”
- Dashboards: Show device statuses in your Node-RED dashboard (or third-party systems like Grafana) using readable room names.
- Dynamic Control: Build flows that trigger different actions based on the room name (e.g., different lighting scenes in the “Bedroom” versus the “Living Room”).
- Logging: Write log files or database entries (e.g., InfluxDB) with room names for easier later analysis.
Important Notes
- Global Context Persistence: By default, the global context is stored in RAM and will be lost when Node-RED restarts. You’ll need to trigger the flow at least once after each restart (for example, using the Inject node’s “Trigger on start” option). Alternatively, you can configure context storage to save data to disk and reload it automatically after restarts. Search the Node-RED docs for “Context Storage” for details. There are also flows available to help back up and restore global variables.
- Error Handling: The sample code includes basic checks (is it an array? do rooms have both ID and name?). Extend error handling as needed—e.g., what happens if the SHC is unreachable or the API call fails.
- Security: API access to the SHC requires certificates. Make sure these are stored and handled securely. Restrict access to your Node-RED instance.
- Updates: If you rename or add rooms in the Bosch Smart Home app, you’ll need to rerun the flow manually or wait for the next scheduled run to update the global context accordingly.
Complete Flow for Import
Here is the full Node-RED flow in JSON format. You can copy and paste this into Node-RED via “Menu → Import.” Remember to adjust the IP address in the HTTP Request node URL and configure TLS accordingly!
[{"id":"e2b8a95a24281245","type":"inject","z":"f48cf010.9333b","g":"84c0a94210ead469","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"00 12 *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":3530,"y":800,"wires":[["b0b095d7ce2039f2","b368747f48ea99ae"]]},{"id":"b368747f48ea99ae","type":"http request","z":"f48cf010.9333b","g":"84c0a94210ead469","name":"Room Names","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://192.168.178.186:8444/smarthome/rooms/","tls":"9b926ab94fdcfb8e","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":3740,"y":800,"wires":[["7bd61fb2fc7c89b7"]]},{"id":"7bd61fb2fc7c89b7","type":"function","z":"f48cf010.9333b","g":"84c0a94210ead469","name":"roomNames","func":"// Initialize an object to store room IDs and names\nlet roomNames_BSH = {};\n\n// Check if msg.payload is an array\nif (Array.isArray(msg.payload)) {\n msg.payload.forEach(room => {\n if (room.id && room.name) {\n roomNames_BSH[room.id] = room.name;\n }\n });\n\n // Store the object in global context as \"roomNames_BSH\"\n global.set(\"roomNames_BSH\", roomNames_BSH);\n\n // Optional: Output for verification\n node.warn(\"Rooms saved in global context under 'roomNames_BSH'\");\n} else {\n node.error(\"msg.payload is not an array\");\n}\n\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3950,"y":800,"wires":[["71089ef5c87d35aa"]]},{"id":"71089ef5c87d35aa","type":"debug","z":"f48cf010.9333b","g":"84c0a94210ead469","name":"debug 1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":4140,"y":800,"wires":[]},{"id":"9b926ab94fdcfb8e","type":"tls-config","name":"Controller","cert":"","key":"","ca":"","certname":"client-cert.pem","keyname":"client-key.pem","caname":"","servername":"","verifyservercert":false,"alpnprotocol":""}]
Storing room names in the global context is a simple yet effective way to make your Node-RED flows related to Bosch Smart Home cleaner and more user-friendly. Have fun experimenting and expanding your smart home automations!
Add comment