Delayノードは、メッセージの送信を遅らせたり、流量を制限したりするノードです。
日常生活で例えると、交通信号機のようなものです。
Delayノードは、入力メッセージを受け取り、指定した条件に基づいて
遅延させてから出力します。
API呼び出しの間隔調整やセンサーデータの流量制御に活用できます。
Delay ノードの設定は、まず「動作」で2つのモードのどちらかを選ぶ。選んだモードによって表示される項目が変わる。右欄は、その項目がどちらの動作のときに現れるかを示す。
サンプルフローは、Node-RED本体に同梱されている公式サンプル5つ(「Delay message」から「Limit message rate for each topic」まで)を1つのタブにまとめ、名前の無かった inject ノードと debug ノードに日本語の名前を付けたものです。エディタの メニュー → 読み込み → サンプル → node-red → function → delay からも、元の5つを開けます。
📋 サンプルフロー(クリックで展開)
参照元:NodeREDエディター内サンプルフロー
[
{
"id": "7feaabd51ac8013f",
"type": "tab",
"label": "delay",
"disabled": false,
"info": "",
"env": []
},
{
"id": "87bd706a.aec93",
"type": "comment",
"z": "7feaabd51ac8013f",
"name": "Delay message",
"info": "Delay node can delay sending input message to output port by a specified amount of time.",
"x": 160,
"y": 60,
"wires": []
},
{
"id": "1d17715c.34170f",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "例1: 実行",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "Hello, World!",
"payloadType": "str",
"x": 210,
"y": 120,
"wires": [
[
"26b43de5.4df8f2",
"9930fecd.ee0c8"
]
]
},
{
"id": "9930fecd.ee0c8",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "例1: すぐの出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 410,
"y": 120,
"wires": []
},
{
"id": "26b43de5.4df8f2",
"type": "delay",
"z": "7feaabd51ac8013f",
"name": "",
"pauseType": "delay",
"timeout": "3",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 400,
"y": 180,
"wires": [
[
"c8c2796c.dcb9f8"
]
]
},
{
"id": "c8c2796c.dcb9f8",
"type": "change",
"z": "7feaabd51ac8013f",
"name": "Goodbye, World!",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "Goodbye, World!",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 590,
"y": 180,
"wires": [
[
"c58a290e.2fa438"
]
]
},
{
"id": "c58a290e.2fa438",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "例1: 遅れた出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 790,
"y": 180,
"wires": []
},
{
"id": "c15b8c3e.955ed",
"type": "comment",
"z": "7feaabd51ac8013f",
"name": "Delay message by message property",
"info": "Delay node can delay sending input message to output port by a specified amount of time by `msg.delay` property.",
"x": 210,
"y": 320,
"wires": []
},
{
"id": "a5ed5817.9df448",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "例2: 1秒遅らせる",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
},
{
"p": "delay",
"v": "1000",
"vt": "num"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "delay 1s",
"payloadType": "str",
"x": 180,
"y": 380,
"wires": [
[
"5cf53f4.25b7ec",
"59b7b67a.a8e888"
]
]
},
{
"id": "59b7b67a.a8e888",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "例2: すぐの出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 390,
"y": 380,
"wires": []
},
{
"id": "5cf53f4.25b7ec",
"type": "delay",
"z": "7feaabd51ac8013f",
"name": "",
"pauseType": "delayv",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 380,
"y": 440,
"wires": [
[
"fc989f41.c4114"
]
]
},
{
"id": "fc989f41.c4114",
"type": "change",
"z": "7feaabd51ac8013f",
"name": "Goodbye, World!",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "Goodbye, World!",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 570,
"y": 440,
"wires": [
[
"74ba3d1c.666034"
]
]
},
{
"id": "74ba3d1c.666034",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "例2: 遅れた出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 770,
"y": 440,
"wires": []
},
{
"id": "6cdf7297.bf5a8c",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "例2: 10秒遅らせる",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
},
{
"p": "delay",
"v": "10000",
"vt": "num"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "delay 10s",
"payloadType": "str",
"x": 180,
"y": 440,
"wires": [
[
"59b7b67a.a8e888",
"5cf53f4.25b7ec"
]
]
},
{
"id": "b0200f61.5efa5",
"type": "comment",
"z": "7feaabd51ac8013f",
"name": "Reset or flush pending message",
"info": "Delay node can reset or flush delayed message by sending it a message with `reset` or `flush` property.",
"x": 170,
"y": 580,
"wires": []
},
{
"id": "d5cd8991.e6d2e8",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "例3: 実行",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "Hello, World!",
"payloadType": "str",
"x": 170,
"y": 640,
"wires": [
[
"607f556b.3ec5fc",
"fd14cb.2044db38"
]
]
},
{
"id": "fd14cb.2044db38",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "例3: すぐの出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 370,
"y": 640,
"wires": []
},
{
"id": "607f556b.3ec5fc",
"type": "delay",
"z": "7feaabd51ac8013f",
"name": "",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "minutes",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 360,
"y": 700,
"wires": [
[
"d1fc6763.2a30c8"
]
]
},
{
"id": "d1fc6763.2a30c8",
"type": "change",
"z": "7feaabd51ac8013f",
"name": "Goodbye, World!",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "Goodbye, World!",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 700,
"wires": [
[
"15486d4a.80c6f3"
]
]
},
{
"id": "15486d4a.80c6f3",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "例3: 遅れた出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 700,
"wires": []
},
{
"id": "2b8b28c7.4c8978",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "reset",
"props": [
{
"p": "topic",
"vt": "str"
},
{
"p": "reset",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 150,
"y": 700,
"wires": [
[
"607f556b.3ec5fc"
]
]
},
{
"id": "3a7e1bec.8bc3d4",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "flush",
"props": [
{
"p": "topic",
"vt": "str"
},
{
"p": "flush",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 150,
"y": 760,
"wires": [
[
"607f556b.3ec5fc"
]
]
},
{
"id": "2d14f1a7.e776ce",
"type": "comment",
"z": "7feaabd51ac8013f",
"name": "Slow down messages passing through a flow",
"info": "Delay node can be used to slow down messages passing through a flow.\n\nSee Node-RED cookbook [item](https://cookbook.nodered.org/basic/rate-limit-messages).",
"x": 230,
"y": 860,
"wires": []
},
{
"id": "af78b43e.9817d8",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "Inject Array",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[0,1,2,3,4,5,6,7,8,9]",
"payloadType": "json",
"x": 190,
"y": 920,
"wires": [
[
"a35943e3.eaf0a"
]
]
},
{
"id": "a35943e3.eaf0a",
"type": "split",
"z": "7feaabd51ac8013f",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 330,
"y": 920,
"wires": [
[
"23eacc60.7290a4"
]
]
},
{
"id": "23eacc60.7290a4",
"type": "delay",
"z": "7feaabd51ac8013f",
"name": "",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 470,
"y": 920,
"wires": [
[
"b5b7746a.53bf88"
]
]
},
{
"id": "b5b7746a.53bf88",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "Debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 610,
"y": 920,
"wires": []
},
{
"id": "3dc5015b.96c97e",
"type": "comment",
"z": "7feaabd51ac8013f",
"name": "Limit rate of message transfer for each topic",
"info": "Delay node can limit of message transmission from input to output port by a specified number of message per a specified time.\nIf `For each topic` is selected, messages are grouped by `msg.topic` value. When grouping messages by topic, intermediate messages are dropped and the last messages received sent.",
"x": 210,
"y": 1100,
"wires": []
},
{
"id": "bdafe4c6.4d5658",
"type": "inject",
"z": "7feaabd51ac8013f",
"name": "例5: 実行",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[{\"topic\":\"apple\",\"payload\":1},{\"topic\":\"apple\",\"payload\":2},{\"topic\":\"apple\",\"payload\":3},{\"topic\":\"orange\",\"payload\":1},{\"topic\":\"orange\",\"payload\":2},{\"topic\":\"orange\",\"payload\":3},{\"topic\":\"banana\",\"payload\":1},{\"topic\":\"banana\",\"payload\":2},{\"topic\":\"banana\",\"payload\":3}]",
"payloadType": "json",
"x": 150,
"y": 1160,
"wires": [
[
"f86dc462.195818"
]
]
},
{
"id": "e0bdfcc1.cdf48",
"type": "delay",
"z": "7feaabd51ac8013f",
"name": "",
"pauseType": "timed",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "2",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"x": 690,
"y": 1160,
"wires": [
[
"29d8beea.6b37f2"
]
]
},
{
"id": "29d8beea.6b37f2",
"type": "debug",
"z": "7feaabd51ac8013f",
"name": "例5: 結果",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 890,
"y": 1160,
"wires": []
},
{
"id": "f86dc462.195818",
"type": "split",
"z": "7feaabd51ac8013f",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 290,
"y": 1160,
"wires": [
[
"9feb3aac.616c38"
]
]
},
{
"id": "9feb3aac.616c38",
"type": "change",
"z": "7feaabd51ac8013f",
"name": "set topic&payload",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "payload.topic",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 470,
"y": 1160,
"wires": [
[
"e0bdfcc1.cdf48"
]
]
},
{
"id": "949199e8.89bc88",
"type": "comment",
"z": "7feaabd51ac8013f",
"name": "↑ pass last message of each topic",
"info": "",
"x": 740,
"y": 1200,
"wires": []
}
]
フローには、公式サンプルの5つの例が、上から順に並んでいます。それぞれの先頭に、英語の comment ノードがあります。例の番号が、下のパターンの番号に当たります。delay ノードには名前が付いていないので、ここでは種類の名前で呼びます。
例1〜3 は、同じ作りです。inject の出力が2つに分かれ、一方はそのまま「すぐの出力」(debug)へ、もう一方は delay →「Goodbye, World!」(change)→「遅れた出力」(debug)へ進みます。change は、msg.payload を Goodbye, World! に書き換えます。遅れて届いたほうを、debug に出る文字で見分けるための作りです。
動作: メッセージの遅延(指定した時間遅延)
遅延時間: 3秒
入力: 10:00:00 に "Hello, World!"
出力: 10:00:03 に、3秒遅れて届く
(サンプルフローでは、遅れたほうを見分けられるよう、
途中の change が "Goodbye, World!" に書き換えている)
動作: メッセージの遅延(msg.delay に遅延を設定)
(設定画面で「msg.delay に遅延を設定」を選択)
メッセージ1: msg.delay = 1000 → 1秒後に出力
メッセージ2: msg.delay = 10000 → 10秒後に出力
Resetの場合:
1. メッセージを送信(1分の遅延開始)
2. 1分たつ前にresetを送信
3. 待機中のメッセージは破棄される(出力なし)
Flushの場合:
1. メッセージを送信(1分の遅延開始)
2. 1分たつ前にflushを送信
3. 待機中のメッセージが即座に出力される
動作: メッセージの流量制限(msg.topic毎)
流量: 1メッセージ / 2秒
中間メッセージの扱い: 中間メッセージを削除
入力:
apple:1 → apple:2 → apple:3
orange:1 → orange:2 → orange:3
banana:1 → banana:2 → banana:3
出力(2秒ごとの区切りで。押してから2秒以内):
apple:3(最新のみ)
orange:3(最新のみ)
banana:3(最新のみ)
外部API(1秒に10回まで)への連続リクエスト
↓
Delayノード(レート: 10msg/秒)
↓
HTTP Request → API呼び出し
↓
レート制限エラーを回避しながら大量処理
温度センサー(100ms間隔で送信)
↓
Delayノード(トピック別、1msg/5秒、ドロップ)
↓
最新値のみ5秒ごとにダッシュボードに表示
↓
通信量とCPU負荷を大幅削減
Raspberry Pi起動
↓
Delay 10秒(ネットワーク接続待ち)
↓
Delay 5秒(センサー初期化待ち)
↓
メイン処理開始
※ 起動直後の不安定な状態を回避