node-red-contrib-openbeken-subflow 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gparduino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  node-red-contrib-openbeken-subflow
2
2
  ==================================
3
3
 
4
- A high-performance Node-RED node designed specifically for **OpenBeken** flashed hardware. This node simplifies the integration of devices using **Flag 10** (immediate MQTT state feedback) and includes a built-in watchdog timer to monitor device health.
4
+ A high-performance Node-RED subflow designed specifically for **OpenBeken** flashed hardware. This node simplifies the integration of devices using **Flag 10 and Flag 2** (immediate MQTT state feedback), provides built-in watchdog monitoring, and supports **Cross-Device Synchronization** for 3-way switch configurations.
5
5
 
6
6
  Features
7
7
  --------
@@ -10,36 +10,54 @@ Features
10
10
 
11
11
  * **Watchdog Timer:** Monitors device activity and updates the node status to "Offline" if no heartbeat is detected within 5 minutes.
12
12
 
13
- * **Smart Sanitization:** Accepts Booleans (true/false), Strings ("on"/off"), or Numbers (1/0) and converts them to the correct format for OpenBeken.
13
+ * **State-Sync Groups:** Support for multi-way (3-way/4-way) switching. Link multiple devices via a Global context to ensure states match even if UDP packets are dropped or firewalled.
14
14
 
15
- * **Zero-Config UI:** Designed to work out of the box with Node-RED Dashboard 2.0.
15
+ * **Smart Sanitization:** Accepts Booleans (true/false), Strings ("on"/"off"), or Numbers (1/0) and converts them to the correct format for OpenBeken.
16
+
17
+ * **Dashboard 2.0 Ready:** Native support for UI updates including icon/color changes based on device connectivity.
16
18
 
17
19
 
18
20
  Hardware Requirements
19
21
  ---------------------
20
22
 
21
- For the best experience, ensure your OpenBeken device has **Flag 10** enabled. Open your device's web console and run:Backlog Flag 10 1; restart
23
+ For the best experience, ensure your OpenBeken device has **Flag 10 and Flag 2** enabled. Open your device's web console and run:Backlog Flag 10 1; Flag 2 1; restart
22
24
 
23
25
  Configuration
24
26
  -------------
25
27
 
26
28
  1. **Broker:** Select your MQTT Broker configuration node.
27
29
 
28
- 2. **Topic Base:** Enter the base MQTT topic of your device (e.g., BedroomFan). **Do not** include trailing slashes.
30
+ 2. **Topic Base:** Enter the base MQTT topic of your device (e.g., KitchenLights). **Do not** include trailing slashes.
31
+
32
+ 3. **Sync Group (Optional):** Enter a unique string (e.g., Kitchen3Way) to link multiple nodes together. Nodes sharing the same group name will stay synchronized automatically.
33
+
34
+
35
+ 3-Way Switching Setup (Cross-Sync)
36
+ ----------------------------------
37
+
38
+ To use this node as a backup for OpenBeken Device Groups (or when UDP is blocked):
39
+
40
+ 1. Give both nodes the same **Sync Group** name.
41
+
42
+ 2. Cross-connect the nodes in your flow: Wire **Output 1** of Node A to **Input 1** of Node B, and vice versa.
43
+
44
+ 3. The nodes use a source: "from\_hw" tag to prevent infinite relay loops.
29
45
 
30
46
 
31
47
  Input/Output
32
48
  ------------
33
49
 
34
- * **Input:** Send a boolean true/false or string "on"/off" to toggle the device.
50
+ * **Input:** Send a boolean true/false or string "on"/"off" to toggle the device.
51
+
52
+ * **Output 1:** Returns a clean boolean true/false based on the hardware's actual state. Perfect for updating Dashboard switches.
35
53
 
36
- * **Output 1:** Returns a clean boolean true/false based on the hardware's actual state.
54
+ * **Output 2:** MQTT output (Internal use, wire to MQTT Out node).
37
55
 
38
- * **Output 2:** (Optional) Provides detailed status objects for logging or advanced logic.
56
+ * **Output 3:** Status output for custom logging or dashboard indicators.
39
57
 
40
58
 
41
59
  ### Tips for Success
42
60
 
43
- * **Dashboard 2.0:** Simply wire a Dashboard "Switch" node to the input and back from the output for a perfectly synchronized UI.
61
+ * **Dashboard 2.0:** Wire a Dashboard "Switch" node to the input of any node in a Sync Group. To ensure the UI reflects changes from all physical switches, wire **Output 1** of _all_ grouped nodes back to the Dashboard Switch input.
44
62
 
45
- * **LWT:** This node relies on the device being "connected" to show online status. Ensure your MQTT Broker is configured to handle the device's Last Will and Testament (LWT).
63
+ * **LWT:** This node relies on the device being "connected" to show online status. Ensure your MQTT Broker is configured to handle the device's Last Will and Testament (LWT).
package/openbeken.js CHANGED
@@ -1,11 +1,10 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
1
4
  module.exports = function(RED) {
2
- const fs = require("fs");
3
- const path = require("path");
5
+ const subflowFile = path.join(__dirname, 'openbeken.json');
6
+ const subflowContents = fs.readFileSync(subflowFile, 'utf8');
7
+ const subflowJSON = JSON.parse(subflowContents);
4
8
 
5
- // Load the subflow JSON file
6
- const subflowPath = path.join(__dirname, "openbeken.json");
7
- const subflowData = JSON.parse(fs.readFileSync(subflowPath, "utf8"));
8
-
9
- // Register the subflow with Node-RED
10
- RED.nodes.registerSubflow(subflowData[0]);
9
+ RED.nodes.registerSubflow(subflowJSON);
11
10
  };
package/openbeken.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "287344f336f70f21",
4
4
  "type": "subflow",
5
5
  "name": "OpenBeken Optimized",
6
- "info": "Improved handling for Flag 10 devices with watchdog timer.",
6
+ "info": "Improved handling for Flag 10 + Flag 2 devices with watchdog timer and support for groups.",
7
7
  "category": "",
8
8
  "in": [
9
9
  {
@@ -44,12 +44,17 @@
44
44
  },
45
45
  "type": "conf-types"
46
46
  }
47
+ },
48
+ {
49
+ "name": "SYNC_GROUP",
50
+ "type": "str",
51
+ "value": ""
47
52
  }
48
53
  ],
49
54
  "meta": {
50
55
  "module": "node-red-contrib-openbeken-subflow",
51
56
  "type": "openbeken",
52
- "version": "1.0.0",
57
+ "version": "1.2.0",
53
58
  "author": "gparduino",
54
59
  "desc": "OpenBeken flashed module support",
55
60
  "keywords": "openbeken",
@@ -73,7 +78,7 @@
73
78
  "type": "function",
74
79
  "z": "287344f336f70f21",
75
80
  "name": "Process MQTT & UI",
76
- "func": "const topicBase = env.get(\"TOPIC_BASE\");\n\n// --- 1. WATCHDOG TIMEOUT ---\nif (msg.topic === \"watchdog\") {\n const s = { fill: \"red\", shape: \"ring\", text: \"Offline (Timeout)\" };\n node.status(s);\n return [null, null, { payload: s }];\n}\n\n// --- 2. INCOMING MQTT (Device -> Node-RED) ---\nif (msg.topic && msg.topic !== \"\") {\n if (msg.topic.endsWith('connected')) {\n const isOnline = (msg.payload === \"online\" || msg.payload === \"1\" || msg.payload === 1);\n const s = { fill: isOnline ? \"yellow\" : \"red\", shape: isOnline ? \"dot\" : \"ring\", text: isOnline ? \"Online\" : \"Offline\" };\n node.status(s);\n return [null, null, { payload: s }];\n }\n\n if (msg.topic.endsWith('1/get')) {\n const isOn = (msg.payload == 1 || msg.payload === \"on\" || msg.payload === true);\n const s = { fill: isOn ? \"green\" : \"grey\", shape: \"dot\", text: isOn ? \"On\" : \"Off\" };\n node.status(s);\n return [{ payload: isOn }, null, { payload: s }];\n }\n}\n\n// --- 3. UI COMMAND (Dashboard/Inject -> Device) ---\n// We handle booleans OR the strings \"on\"/\"off\"\nconst p = msg.payload;\nif (typeof p === \"boolean\" || p === \"on\" || p === \"off\" || p === \"1\" || p === \"0\") {\n const isTrue = (p === true || p === \"on\" || p === \"1\" || p === 1);\n const outTopic = `${topicBase}/1/set`;\n return [null, { topic: outTopic, payload: isTrue ? 1 : 0 }, null];\n}\n\nreturn null;",
81
+ "func": "const topicBase = env.get(\"TOPIC_BASE\");\nconst syncGroup = env.get(\"SYNC_GROUP\");\n\nconst uiReset = { \"offcolor\": \"\", \"officon\": \"\", \"onicon\": \"\" };\nconst uiOffline = { \"offcolor\": \"red\", \"officon\": \"wifi-strength-off-outline\", \"onicon\": \"wifi-strength-off-outline\" };\n\n// --- 1. WATCHDOG ---\nif (msg.topic === \"watchdog\") {\n const s = { fill: \"red\", shape: \"ring\", text: \"Offline\" };\n node.status(s);\n return [{ payload: false, ui_update: uiOffline }, null, { payload: s }];\n}\n\n// --- 2. INCOMING MQTT (Status confirmation from Device) ---\nif (msg.topic && msg.topic !== \"\") {\n \n // Connection Status\n if (msg.topic.endsWith('connected')) {\n const isOnline = (msg.payload === \"online\" || msg.payload === \"1\" || msg.payload === 1);\n const s = { fill: isOnline ? \"yellow\" : \"red\", shape: isOnline ? \"dot\" : \"ring\", text: isOnline ? \"Online\" : \"Offline\" };\n node.status(s);\n return [isOnline ? { ui_update: uiReset } : { payload: false, ui_update: uiOffline }, null, { payload: s }];\n }\n\n // Relay State Confirmation (1/get)\n if (msg.topic.endsWith('1/get')) {\n const isOn = (msg.payload == 1 || msg.payload === \"on\" || msg.payload === true);\n const s = { fill: isOn ? \"green\" : \"grey\", shape: \"dot\", text: isOn ? \"On\" : \"Off\" };\n node.status(s);\n\n if (syncGroup) {\n const contextKey = \"sync_\" + syncGroup;\n \n // USE GLOBAL CONTEXT - Works in all Node-RED configs\n const lastKnown = global.get(contextKey);\n \n // If the state is already recorded, stop the loop\n if (isOn === lastKnown) {\n return [null, null, { payload: s }];\n }\n\n // Update the global record\n global.set(contextKey, isOn);\n\n // Output 1: Sync partner + update UI\n return [{ payload: isOn, ui_update: uiReset, source: \"from_hw\" }, null, { payload: s }];\n }\n return [{ payload: isOn, ui_update: uiReset }, null, { payload: s }];\n }\n}\n\n// --- 3. COMMAND LOGIC (UI Switch or Sync Input) ---\nconst p = msg.payload;\nif (typeof p === \"boolean\" || p === \"on\" || p === \"off\" || p === \"1\" || p === \"0\") {\n const isTrue = (p === true || p === \"on\" || p === \"1\" || p === 1);\n const outTopic = `${topicBase}/1/set`;\n\n // THE FAIL-SAFE COMMAND: Always send the MQTT command to the device\n const mqttMsg = { topic: outTopic, payload: isTrue ? 1 : 0 };\n\n if (msg.source === \"from_hw\") {\n // Just command the hardware\n return [null, mqttMsg, null];\n } else {\n // UI Interaction: Command hardware, don't update context yet (wait for 1/get)\n return [null, mqttMsg, null];\n }\n}\n\nreturn null;",
77
82
  "outputs": 3,
78
83
  "timeout": "",
79
84
  "noerr": 0,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-red-contrib-openbeken-subflow",
3
- "version": "1.0.0",
4
- "description": "OpenBeken support for Node-RED",
3
+ "version": "1.2.0",
4
+ "description": "Optimized OpenBeken support for Node-RED with Dashboard 2.0 dynamic UI updates",
5
5
  "main": "openbeken.js",
6
6
  "node-red": {
7
7
  "nodes": {
@@ -11,8 +11,16 @@
11
11
  "keywords": [
12
12
  "node-red",
13
13
  "openbeken",
14
- "tuya"
14
+ "tuya",
15
+ "dashboard-2.0",
16
+ "mqtt"
15
17
  ],
18
+ "engines": {
19
+ "node": ">=14.0.0"
20
+ },
21
+ "peerDependencies": {
22
+ "node-red": ">=3.0.0"
23
+ },
16
24
  "author": "gparduino",
17
25
  "license": "MIT"
18
26
  }