📋 サンプルフロー(クリックで展開)
参照元:NodeREDエディター内サンプルフロー
[
{
"id": "fb1ddbf0a34af21e",
"type": "tab",
"label": "trigger",
"disabled": false,
"info": "",
"env": []
},
{
"id": "ec5a531b.68b65",
"type": "inject",
"z": "fb1ddbf0a34af21e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 220,
"y": 120,
"wires": [
[
"cb5e0c78.4bf3d"
]
]
},
{
"id": "1b0f8c3e.1fd7e4",
"type": "debug",
"z": "fb1ddbf0a34af21e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 550,
"y": 120,
"wires": []
},
{
"id": "cb5e0c78.4bf3d",
"type": "trigger",
"z": "fb1ddbf0a34af21e",
"name": "",
"op1": "1",
"op2": "0",
"op1type": "str",
"op2type": "str",
"duration": "2",
"extend": "false",
"overrideDelay": "false",
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 380,
"y": 120,
"wires": [
[
"1b0f8c3e.1fd7e4"
]
]
},
{
"id": "4e5bf6b2.b4dd58",
"type": "comment",
"z": "fb1ddbf0a34af21e",
"name": "Oputputs two values with interval",
"info": "Outputs 1. Then output 0 after a certain period of time.\n\n*This could be used, for example, to blink an LED attached to a Raspberry Pi GPIO pin.*",
"x": 230,
"y": 60,
"wires": []
},
{
"id": "2751bcdba6c887ed",
"type": "comment",
"z": "fb1ddbf0a34af21e",
"name": "Trigger a flow if a message isn't received after a defined time",
"info": "Trigger node can be used to wait a specified amount of time to send a message.\n\nSee Node-RED [cookbook](https://cookbook.nodered.org/basic/trigger-timeout).",
"x": 320,
"y": 200,
"wires": []
},
{
"id": "9bac75033492118c",
"type": "debug",
"z": "fb1ddbf0a34af21e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 570,
"y": 260,
"wires": []
},
{
"id": "fdf7852aab7dded8",
"type": "inject",
"z": "fb1ddbf0a34af21e",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 220,
"y": 260,
"wires": [
[
"e4113ea63be8c6aa",
"9bac75033492118c"
]
]
},
{
"id": "e4113ea63be8c6aa",
"type": "trigger",
"z": "fb1ddbf0a34af21e",
"name": "Watchdog",
"op1": "",
"op2": "timeout",
"op1type": "nul",
"op2type": "str",
"duration": "5",
"extend": "true",
"overrideDelay": "false",
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 390,
"y": 300,
"wires": [
[
"579925f927a3db7e"
]
]
},
{
"id": "579925f927a3db7e",
"type": "debug",
"z": "fb1ddbf0a34af21e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 570,
"y": 300,
"wires": []
},
{
"id": "d55745be.e4ecd8",
"type": "inject",
"z": "fb1ddbf0a34af21e",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 220,
"y": 420,
"wires": [
[
"ecac46bf.9751c8",
"cf35bbed.ce1298"
]
]
},
{
"id": "ecac46bf.9751c8",
"type": "debug",
"z": "fb1ddbf0a34af21e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 730,
"y": 420,
"wires": []
},
{
"id": "cf35bbed.ce1298",
"type": "trigger",
"z": "fb1ddbf0a34af21e",
"name": "",
"op1": "reset",
"op2": "true",
"op1type": "str",
"op2type": "bool",
"duration": "2",
"extend": "true",
"overrideDelay": "false",
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 380,
"y": 460,
"wires": [
[
"febbebba.455238"
]
]
},
{
"id": "febbebba.455238",
"type": "trigger",
"z": "fb1ddbf0a34af21e",
"name": "",
"op1": "0",
"op2": "0",
"op1type": "num",
"op2type": "str",
"duration": "-2",
"extend": "false",
"overrideDelay": "false",
"units": "s",
"reset": "reset",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 540,
"y": 460,
"wires": [
[
"ecac46bf.9751c8"
]
]
},
{
"id": "4bad6a7.9a1d194",
"type": "comment",
"z": "fb1ddbf0a34af21e",
"name": "Send placeholder messages when a stream stops sending",
"info": "Trigger node can be used to detect when a message has not arrived after a defined interval and a second Trigger node to send the placeholder messages at a regular interval..\n\nSee Node-RED [cookbook](https://cookbook.nodered.org/basic/trigger-placeholder).",
"x": 310,
"y": 360,
"wires": []
},
{
"id": "d24083e7.fedc7",
"type": "comment",
"z": "fb1ddbf0a34af21e",
"name": "Timeout processing using trigger node",
"info": "It is possible to configure timeout processing by combining two Trigger nodes. \n\nIn the first Trigger node settings panel, `send second message to separate output` checkbox is checked. With this specification, this trigger node will have two output ports. When the node receives an input message, it outputs the message to the first port, and after a specified period of time, it outputs the specified message to the second port.\n\nThe second trigger node is specified to handle each message ID (`msg._msgid`). This means that only the first received message among the messages with the same ID is transmitted. The time specified for it represents the retention time of information for message filtering and must be longer than the processing time for the timeout.\n",
"x": 250,
"y": 540,
"wires": []
},
{
"id": "8dcb51d5.90fbb",
"type": "inject",
"z": "fb1ddbf0a34af21e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "num",
"x": 210,
"y": 640,
"wires": [
[
"69b526f1.347808"
]
]
},
{
"id": "3b2238f8.71f6c8",
"type": "debug",
"z": "fb1ddbf0a34af21e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 930,
"y": 680,
"wires": []
},
{
"id": "69b526f1.347808",
"type": "trigger",
"z": "fb1ddbf0a34af21e",
"name": "",
"op1": "",
"op2": "0",
"op1type": "pay",
"op2type": "str",
"duration": "3",
"extend": "false",
"overrideDelay": "false",
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 2,
"x": 380,
"y": 680,
"wires": [
[
"3802c45b.84121c"
],
[
"a3c01d51.86cbb"
]
]
},
{
"id": "7096b59a.c265fc",
"type": "trigger",
"z": "fb1ddbf0a34af21e",
"name": "",
"op1": "",
"op2": "",
"op1type": "pay",
"op2type": "nul",
"duration": "10",
"extend": "false",
"overrideDelay": "false",
"units": "s",
"reset": "",
"bytopic": "topic",
"topic": "_msgid",
"outputs": 1,
"x": 750,
"y": 680,
"wires": [
[
"3b2238f8.71f6c8"
]
]
},
{
"id": "3802c45b.84121c",
"type": "function",
"z": "fb1ddbf0a34af21e",
"name": "Target Process",
"func": "// Wait for a specified time period, then send a message.\n// Must preserve incoming message id.\nvar wait = msg.payload;\nsetTimeout(function() {\n msg.payload = \"done: \"+wait+\"s\";\n node.send(msg);\n}, wait*1000);\n",
"outputs": 1,
"timeout": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 560,
"y": 600,
"wires": [
[
"7096b59a.c265fc"
]
]
},
{
"id": "a3c01d51.86cbb",
"type": "change",
"z": "fb1ddbf0a34af21e",
"name": "Set timeout flag",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "timeout",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 560,
"y": 720,
"wires": [
[
"7096b59a.c265fc"
]
]
},
{
"id": "ae217597.bedf88",
"type": "inject",
"z": "fb1ddbf0a34af21e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "5",
"payloadType": "num",
"x": 210,
"y": 720,
"wires": [
[
"69b526f1.347808"
]
]
},
{
"id": "dc6f5bbe.dc8bd8",
"type": "comment",
"z": "fb1ddbf0a34af21e",
"name": "↓ target process",
"info": "",
"x": 560,
"y": 560,
"wires": []
},
{
"id": "fe41a803.a14158",
"type": "comment",
"z": "fb1ddbf0a34af21e",
"name": "↓ send second message after specified time",
"info": "",
"x": 490,
"y": 640,
"wires": []
},
{
"id": "fbb2dff0.0bacb",
"type": "comment",
"z": "fb1ddbf0a34af21e",
"name": "↓ pass first message with same ID",
"info": "",
"x": 820,
"y": 640,
"wires": []
}
]
送信データ(1つ目): 何も送らない
送信データ(2つ目): 文字列 "timeout"
待機時間: 5秒
延長: ✓ 有効(入力ごとにタイマーリセット)
動作: 5秒間入力がない → "timeout"を出力
送信データ(1つ目): ペイロード(入力値をそのまま)
送信データ(2つ目): 文字列 "0"(または"timeout")
待機時間: 3秒
出力: 別の出力に送信(2ポート)
出力1 → 処理フローへ(即座)
出力2 → タイムアウト処理へ(3秒後)
MQTTでデバイスからハートビート受信
↓
Triggerノード(延長モード)
- 1つ目: 何も送らない
- 2つ目: "offline"
- 待機時間: 30秒
- 延長: 有効
↓
30秒間ハートビートなし
↓
"offline"出力 → アラート送信
※ デバイスの生存監視
ボタン押下 or センサーイベント
↓
Triggerノード
- 1つ目: 1
- 2つ目: 0
- 待機時間: 2秒
↓
GPIO出力ノード
↓
LEDが2秒間点灯して消灯
※ Raspberry PiのLED制御
ユーザーアクティビティ(API呼び出し等)
↓
Triggerノード(延長モード)
- 1つ目: 何も送らない
- 2つ目: "session_timeout"
- 待機時間: 15分
- 延長: 有効
↓
15分間アクティビティなし
↓
セッション無効化処理
※ Webアプリケーションのセッション管理
API呼び出し要求
↓
Triggerノード(2出力)
- 出力1: 即座にAPIへ
- 出力2: 5秒後にタイムアウト
↓
├─ 出力1 → HTTP Requestノード → 成功処理
└─ 出力2 → リトライカウンター → 再試行
※ API呼び出しのタイムアウト処理