Wait and transform msg for shutter

Hey guys,

i recently installed my Shelly 2.5 for shutter control. All workflows should be build in Node Red. It's working out pretty good besides of one thing: i want to rotate my shutter lamella for 500 milliseconds to get another angle. Shelly API has a parameter for this but it's limited to at least 1 second which is too long.

I tried the following

node.send(msg);
setTimeout(function(){
    msg.payload = "stop";
    node.send(msg);
}, 3000);

It works with debug messages, but as soon as i connect the function to the next node, the second message disappears.

Flow

[
{
"id": "9880ae28.be1db",
"type": "tab",
"label": "EZ_Rollos",
"disabled": false,
"info": ""
},
{
"id": "7604809e.57e07",
"type": "mqtt in",
"z": "9880ae28.be1db",
"name": "Shellys",
"topic": "shellies/#",
"qos": "0",
"broker": "6376c96a.d92428",
"x": 94.89492797851562,
"y": 445.048828125,
"wires": [
[
"71437f.1f65cc8"
]
]
},
{
"id": "ee1fcc8f.efa97",
"type": "ui_slider",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Ost_Zustand",
"label": "Zu",
"tooltip": "Rolladen auf diesen Wert hoch/runter fahren",
"group": "8780170a.95d898",
"order": 1,
"width": "6",
"height": "1",
"passthru": true,
"outs": "end",
"topic": "slider",
"min": 0,
"max": "100",
"step": 1,
"x": 622,
"y": 168,
"wires": [
[
"44138b9.ede8374"
]
]
},
{
"id": "c411b688.b5abf8",
"type": "ui_slider",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Süd_Zustand",
"label": "Zu",
"tooltip": "Rolladen auf diesen Wert hoch/runter fahren",
"group": "74c77266.16ce0c",
"order": 1,
"width": "6",
"height": "1",
"passthru": true,
"outs": "end",
"topic": "slider",
"min": 0,
"max": "100",
"step": 1,
"x": 619,
"y": 520,
"wires": [
[
"6278ffa3.9d8f8"
]
]
},
{
"id": "7322fef3.1dfbc",
"type": "ui_slider",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_West_Zustand",
"label": "Zu",
"tooltip": "Rolladen auf diesen Wert hoch/runter fahren",
"group": "d3a6bef1.66637",
"order": 1,
"width": "6",
"height": "1",
"passthru": true,
"outs": "end",
"topic": "slider",
"min": 0,
"max": "100",
"step": 1,
"x": 611,
"y": 931,
"wires": [
[
"b08c7c18.11e1e"
]
]
},
{
"id": "71437f.1f65cc8",
"type": "switch",
"z": "9880ae28.be1db",
"name": "",
"property": "topic",
"propertyType": "msg",
"rules": [
{
"t": "cont",
"v": "shelly_ez_east_roller",
"vt": "global"
},
{
"t": "cont",
"v": "shelly_ez_south_roller",
"vt": "global"
},
{
"t": "cont",
"v": "shelly_ez_west_roller",
"vt": "global"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 218,
"y": 445,
"wires": [
[
"e87d6602.9f8a78"
],
[
"9770f412.efa9c8"
],
[
"cfee183d.ab8708"
]
]
},
{
"id": "c41a0549.a4b128",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Ost_Hoch",
"group": "8780170a.95d898",
"order": 4,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladen hoch fahren",
"color": "",
"bgcolor": "",
"icon": "mi-arrow_upward",
"payload": "open",
"payloadType": "str",
"topic": "shutter",
"x": 613,
"y": 258,
"wires": [
[
"44138b9.ede8374"
]
]
},
{
"id": "2d25173f.073a18",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Ost_Stop",
"group": "8780170a.95d898",
"order": 6,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladenbewegung stoppen",
"color": "",
"bgcolor": "",
"icon": "pause",
"payload": "stop",
"payloadType": "str",
"topic": "shutter",
"x": 613,
"y": 293,
"wires": [
[
"44138b9.ede8374"
]
]
},
{
"id": "9e79f6ee.eea618",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Ost_Zu",
"group": "8780170a.95d898",
"order": 8,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladen runter fahren",
"color": "",
"bgcolor": "",
"icon": "arrow_downward",
"payload": "close",
"payloadType": "str",
"topic": "shutter",
"x": 603,
"y": 332,
"wires": [
[
"44138b9.ede8374"
]
]
},
{
"id": "6f9c0bc1.60bee4",
"type": "mqtt out",
"z": "9880ae28.be1db",
"name": "Output_Shellies",
"topic": "",
"qos": "",
"retain": "",
"broker": "6376c96a.d92428",
"x": 1640,
"y": 394,
"wires":
},
{
"id": "a75bee22.9b36a",
"type": "ui_text",
"z": "9880ae28.be1db",
"group": "8780170a.95d898",
"order": 2,
"width": "1",
"height": "1",
"name": "",
"label": "Offen",
"format": "{{msg.payload}}",
"layout": "row-right",
"x": 561,
"y": 217,
"wires":
},
{
"id": "af6aeb07.1a5f08",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Süd_Hoch",
"group": "74c77266.16ce0c",
"order": 4,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladen hoch fahren",
"color": "",
"bgcolor": "",
"icon": "mi-arrow_upward",
"payload": "open",
"payloadType": "str",
"topic": "shutter",
"x": 604,
"y": 625,
"wires": [
[
"6278ffa3.9d8f8"
]
]
},
{
"id": "fedaed1c.26cdc",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Süd_Stop",
"group": "74c77266.16ce0c",
"order": 6,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladenbewegung stoppen",
"color": "",
"bgcolor": "",
"icon": "pause",
"payload": "stop",
"payloadType": "str",
"topic": "shutter",
"x": 606,
"y": 664,
"wires": [
[
"6278ffa3.9d8f8"
]
]
},
{
"id": "471fcac.7f32a34",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Süd_Zu",
"group": "74c77266.16ce0c",
"order": 8,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladen runter fahren",
"color": "",
"bgcolor": "",
"icon": "arrow_downward",
"payload": "close",
"payloadType": "str",
"topic": "shutter",
"x": 596,
"y": 703,
"wires": [
[
"6278ffa3.9d8f8"
]
]
},
{
"id": "2543edc0.abbec2",
"type": "ui_text",
"z": "9880ae28.be1db",
"group": "74c77266.16ce0c",
"order": 2,
"width": "1",
"height": "1",
"name": "",
"label": "Offen",
"format": "{{msg.payload}}",
"layout": "row-right",
"x": 555,
"y": 589,
"wires":
},
{
"id": "313991f.29d106e",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_West_Hoch",
"group": "d3a6bef1.66637",
"order": 4,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladen hoch fahren",
"color": "",
"bgcolor": "",
"icon": "mi-arrow_upward",
"payload": "open",
"payloadType": "str",
"topic": "shutter",
"x": 609,
"y": 1016,
"wires": [
[
"b08c7c18.11e1e"
]
]
},
{
"id": "f6f34ed3.2acf5",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_West_Stop",
"group": "d3a6bef1.66637",
"order": 6,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladenbewegung stoppen",
"color": "",
"bgcolor": "",
"icon": "pause",
"payload": "stop",
"payloadType": "str",
"topic": "shutter",
"x": 601,
"y": 1055,
"wires": [
[
"b08c7c18.11e1e"
]
]
},
{
"id": "57497e2.230128",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_West_Zu",
"group": "d3a6bef1.66637",
"order": 8,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "Rolladen runter fahren",
"color": "",
"bgcolor": "",
"icon": "arrow_downward",
"payload": "close",
"payloadType": "str",
"topic": "shutter",
"x": 601,
"y": 1094,
"wires": [
[
"b08c7c18.11e1e"
]
]
},
{
"id": "3f83d598.c966fa",
"type": "ui_text",
"z": "9880ae28.be1db",
"group": "d3a6bef1.66637",
"order": 2,
"width": "1",
"height": "1",
"name": "",
"label": "Offen",
"format": "{{msg.payload}}",
"layout": "row-right",
"x": 548,
"y": 980,
"wires":
},
{
"id": "78ca2a1b.c2f4d4",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Ost_Calibrate",
"group": "8780170a.95d898",
"order": 9,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "vertical_align_center",
"payload": "rc",
"payloadType": "str",
"topic": "shutter",
"x": 621,
"y": 368,
"wires": [
[
"44138b9.ede8374"
]
]
},
{
"id": "a8122432.c88a78",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Ost_Hoch_Kipp",
"group": "8780170a.95d898",
"order": 5,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "mi-expand_less",
"payload": "open",
"payloadType": "str",
"topic": "shutter",
"x": 626,
"y": 416,
"wires": [
[
"afab5276.4e9c8"
]
]
},
{
"id": "afab5276.4e9c8",
"type": "function",
"z": "9880ae28.be1db",
"name": "rotateShutterLamella",
"func": "node.send(msg);\nsetTimeout(function(){\n msg.payload = "stop";\n node.send(msg);\n}, 3000);\n\n\n\n\n\n\n\n// Creates two Messages for short up/down, followed\n// by a stop command\n// The length of the movement is defined in \n// the delay node\n\n/for (var i=0; i<2; i++){\n \n // Up/down command from button\n if (i === 0){\n node.send (msg);\n sleep(1000);\n }\n \nelse if (i ===1){\n \n // Stop command\n msg.payload = "stop";\n node.send (msg);\n \n }\n}\n/\n\nfunction sleep( millisecondsToWait )\n{\n var now = new Date().getTime();\n while ( new Date().getTime() < now + millisecondsToWait )\n {\n /* do nothing; this will exit once it reaches the time limit /\n / if you want you could do something and exit */\n }\n}",
"outputs": 1,
"noerr": 0,
"x": 882,
"y": 433,
"wires": [
[
"44138b9.ede8374"
]
]
},
{
"id": "242e6776.361038",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Ost_Zu_Kipp",
"group": "8780170a.95d898",
"order": 7,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "mi-expand_more",
"payload": "close",
"payloadType": "str",
"topic": "shutter",
"x": 634,
"y": 454,
"wires": [
[
"afab5276.4e9c8"
]
]
},
{
"id": "8961145b.cf3c78",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Süd_Hoch_Kipp",
"group": "74c77266.16ce0c",
"order": 5,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "mi-expand_less",
"payload": "open",
"payloadType": "str",
"topic": "shutter",
"x": 622,
"y": 783,
"wires": [
[
"a02c0d24.0908a"
]
]
},
{
"id": "7fd3ccb1.88cf24",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Süd_Zu_Kipp",
"group": "74c77266.16ce0c",
"order": 7,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "mi-expand_more",
"payload": "close",
"payloadType": "str",
"topic": "shutter",
"x": 614,
"y": 823,
"wires": [
[
"a02c0d24.0908a"
]
]
},
{
"id": "af6e2eb4.09ac",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_West_Hoch_Kipp",
"group": "d3a6bef1.66637",
"order": 5,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "mi-expand_less",
"payload": "open",
"payloadType": "str",
"topic": "shutter",
"x": 618,
"y": 1141,
"wires": [
[
"ddcf4c22.57d03"
]
]
},
{
"id": "c4a7ce28.6fe0e",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_West_Zu_Kipp",
"group": "d3a6bef1.66637",
"order": 7,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "mi-expand_more",
"payload": "close",
"payloadType": "str",
"topic": "shutter",
"x": 610,
"y": 1181,
"wires": [
[
"ddcf4c22.57d03"
]
]
},
{
"id": "f4de915e.f14f5",
"type": "debug",
"z": "9880ae28.be1db",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 1361,
"y": 413,
"wires":
},
{
"id": "44138b9.ede8374",
"type": "function",
"z": "9880ae28.be1db",
"name": "createMQTTMessage",
"func": "// !! IMPORTANT !!\n// Change global in extracShelly with the right Shelly\n// when copied! \n// !!!!!!!!!!!!!!!\n\n// Define Shelly you want to process\nvar extractShelly = global.get("shelly_ez_east_roller");\n\n// Check for slider Shelly command set\nif (msg.topic === "slider"){\n \n // Prepare concatTopic variable \n var concatTopic = "slider_XXX_out";\n concatTopic = concatTopic.replace("XXX",extractShelly);\n \n // Create topic for slider MQTT output\n msg.topic = global.get(concatTopic);\n \n return msg;\n}\n\n// Check for shutter Shelly commmand set\nelse if (msg.topic === "shutter"){\n \n // Prepare concatTopic variable \n var concatTopic = "shutter_XXX";\n concatTopic = concatTopic.replace("XXX",extractShelly);\n \n // Create topic for slider MQTT output\n msg.topic = global.get(concatTopic);\n \n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 1342,
"y": 286,
"wires": [
[
"6f9c0bc1.60bee4",
"f4de915e.f14f5"
]
]
},
{
"id": "e87d6602.9f8a78",
"type": "function",
"z": "9880ae28.be1db",
"name": "shutterPosition",
"func": "//Filter msg topics for current slider position\nif (msg.topic.includes("/roller/0/pos")){\n\nreturn msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 389,
"y": 169,
"wires": [
[
"ee1fcc8f.efa97"
]
]
},
{
"id": "9770f412.efa9c8",
"type": "function",
"z": "9880ae28.be1db",
"name": "shutterPosition",
"func": "//Filter msg topics for current slider position\nif (msg.topic.includes("/roller/0/pos")){\n\nreturn msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 412,
"y": 520,
"wires": [
[
"c411b688.b5abf8"
]
]
},
{
"id": "6278ffa3.9d8f8",
"type": "function",
"z": "9880ae28.be1db",
"name": "createMQTTMessage",
"func": "// !! IMPORTANT !!\n// Change global in extracShelly with the right Shelly\n// when copied! \n// !!!!!!!!!!!!!!!\n\n// Define Shelly you want to process\nvar extractShelly = global.get("shelly_ez_south_roller");\n\n// Check for slider Shelly command set\nif (msg.topic === "slider"){\n \n // Prepare concatTopic variable \n var concatTopic = "slider_XXX_out";\n concatTopic = concatTopic.replace("XXX",extractShelly);\n \n // Create topic for slider MQTT output\n msg.topic = global.get(concatTopic);\n \n return msg;\n}\n\n// Check for shutter Shelly commmand set\nelse if (msg.topic === "shutter"){\n \n // Prepare concatTopic variable \n var concatTopic = "shutter_XXX";\n concatTopic = concatTopic.replace("XXX",extractShelly);\n \n // Create topic for slider MQTT output\n msg.topic = global.get(concatTopic);\n \n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 1332,
"y": 628,
"wires": [
[
"6f9c0bc1.60bee4"
]
]
},
{
"id": "b08c7c18.11e1e",
"type": "function",
"z": "9880ae28.be1db",
"name": "createMQTTMessage",
"func": "// !! IMPORTANT !!\n// Change global in extracShelly with the right Shelly\n// when copied! \n// !!!!!!!!!!!!!!!\n\n// Define Shelly you want to process\nvar extractShelly = global.get("shelly_ez_west_roller");\n\n// Check for slider Shelly command set\nif (msg.topic === "slider"){\n \n // Prepare concatTopic variable \n var concatTopic = "slider_XXX_out";\n concatTopic = concatTopic.replace("XXX",extractShelly);\n \n // Create topic for slider MQTT output\n msg.topic = global.get(concatTopic);\n \n return msg;\n}\n\n// Check for shutter Shelly commmand set\nelse if (msg.topic === "shutter"){\n \n // Prepare concatTopic variable \n var concatTopic = "shutter_XXX";\n concatTopic = concatTopic.replace("XXX",extractShelly);\n \n // Create topic for slider MQTT output\n msg.topic = global.get(concatTopic);\n \n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"x": 1342,
"y": 995,
"wires": [

]
},
{
"id": "cfee183d.ab8708",
"type": "function",
"z": "9880ae28.be1db",
"name": "shutterPosition",
"func": "//Filter msg topics for current slider position\nif (msg.topic.includes("/roller/0/pos")){\n\nreturn msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 389,
"y": 931,
"wires": [
[
"7322fef3.1dfbc"
]
]
},
{
"id": "9e711817.0d0e38",
"type": "ui_button",
"z": "9880ae28.be1db",
"name": "Shelly_EZ_Süd_Calibrate",
"group": "74c77266.16ce0c",
"order": 9,
"width": "1",
"height": "1",
"passthru": false,
"label": "",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "vertical_align_center",
"payload": "rc",
"payloadType": "str",
"topic": "shutter",
"x": 615,
"y": 744,
"wires": [
[
"6278ffa3.9d8f8"
]
]
},
{
"id": "615ae255.a8b94c",
"type": "delay",
"z": "9880ae28.be1db",
"name": "limitMovement",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "2",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 1105,
"y": 796,
"wires": [
[
"6278ffa3.9d8f8"
]
]
},
{
"id": "a02c0d24.0908a",
"type": "function",
"z": "9880ae28.be1db",
"name": "rotateShutterLamella",
"func": "// Creates two Messages for short up/down, followed\n// by a stop command\n// The length of the movement is defined in \n// the delay node\n\nfor (var i=0; i<2; i++){\n \n // Up/down command from button\n if (i === 0){\n node.send (msg);\n }\n \nelse if (i ===1){\n \n // Stop command\n msg.payload = "stop";\n node.send (msg);\n \n }\n}\n\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 886,
"y": 798,
"wires": [
[
"615ae255.a8b94c"
]
]
},
{
"id": "651c5608.12bc58",
"type": "delay",
"z": "9880ae28.be1db",
"name": "limitMovement",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "2",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 1105,
"y": 1166,
"wires": [
[
"b08c7c18.11e1e"
]
]
},
{
"id": "ddcf4c22.57d03",
"type": "function",
"z": "9880ae28.be1db",
"name": "rotateShutterLamella",
"func": "// Creates two Messages for short up/down, followed\n// by a stop command\n// The length of the movement is defined in \n// the delay node\n\nfor (var i=0; i<2; i++){\n \n // Up/down command from button\n if (i === 0){\n node.send (msg);\n }\n \nelse if (i ===1){\n \n // Stop command\n msg.payload = "stop";\n node.send (msg);\n \n }\n}\n\nreturn null;",
"outputs": 1,
"noerr": 0,
"x": 894,
"y": 1165,
"wires": [
[
"651c5608.12bc58"
]
]
},
{
"id": "6376c96a.d92428",
"type": "mqtt-broker",
"z": "",
"name": "Mosquitto",
"broker": "XZY",
"port": "1883",
"clientid": "Mosquitto",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "/Service/nodered/status",
"birthQos": "0",
"birthPayload": "started",
"closeTopic": "",
"closePayload": "",
"willTopic": "/Service/nodered/status",
"willQos": "0",
"willPayload": "crashed"
},
{
"id": "8780170a.95d898",
"type": "ui_group",
"z": "",
"name": "Ostrollo",
"tab": "9b56bf48.b9a57",
"order": 1,
"disp": true,
"width": "7",
"collapse": true
},
{
"id": "74c77266.16ce0c",
"type": "ui_group",
"z": "",
"name": "Südrollo",
"tab": "9b56bf48.b9a57",
"order": 2,
"disp": true,
"width": "7",
"collapse": true
},
{
"id": "d3a6bef1.66637",
"type": "ui_group",
"z": "",
"name": "Westrollo",
"tab": "9b56bf48.b9a57",
"order": 3,
"disp": true,
"width": "7",
"collapse": true
},
{
"id": "9b56bf48.b9a57",
"type": "ui_tab",
"z": "",
"name": "Esszimmer Rollos",
"icon": "dashboard",
"order": 2,
"disabled": false,
"hidden": false
}
]

If the shelly API only supports 1 second, how can you override it ?

Why not use a trigger or delay node ? Both can be set in milliseconds.

Thank you, i oversaw the "trigger" node - delay only supports 1 second at least as well. Trigger works fine!

Delay node also supports milliseconds if you use it as delay.