About the example. The Timer() interval can be set from the UI or by sending a new value in a msg.payload. The Timer() can be triggered or canceled via msg.topic.
- User input range problem.
If the widget displays a value greater than max and the browser user clicks increase it stays the same instead of changing to the max value,
if the widget displays a value less than min and the browser user clicks decrease it stays the same instead of changing to the min value.
Perhapse an out of range incomming msg.payload value should be limited in the same way as when the numeric field is editable (i.e. the value is limited by max and min.
- Server restart/redeploy inconsistency of msg passthrough.
When the server has just been restarted the ui shows the min value.
if a msg arrives at the Numeric input it is always passed on to the output whether it matches min or not.
Following on from redeploy the incomming message will not pass through if the payload matches the displayed value.
This has been discussed before https://discourse.nodered.org/t/slider-and-numeric-widgets-only-pass-through-message-if-different-from-current-value/43275 and was rejected as a bug and that it behaves as it was designed.
It does however generate very confusing behaviour.
I would like to suggest a couple of solutions;
- Add an 'Always pass through the incoming msg' option or
- When msg pass through is checked then always pass through the first message following a redeploy.
[
{
"id": "c663234a94c888ee",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "5e1dfd7d0cd7dcad",
"type": "function",
"z": "c663234a94c888ee",
"name": "Timer",
"func": "var msg1 = RED.util.cloneMessage(msg);\nvar msg2 = RED.util.cloneMessage(msg);\nvar isDay = flow.get(\"Timers_dayIsDay\") || false;\nvar t = isDay ? context.get(\"tDay\") || 0 : context.get(\"tNight\") || 0;\nvar payloadI = parseInt(msg.payload, 10);\n\nswitch(msg.topic){\n case \"tDay\":\n case \"tNight\":\n context.set(\"In\", payloadI);\n context.set(msg.topic, payloadI);\n break;\n case \"StartMsg\":\n case \"TimeoutMsg\":\n context.set(msg.topic, msg.payload);\n break;\n case \"t\":\n context.set(\"tDay\", payloadI);\n context.set(\"tNight\", payloadI);\n break;\n case \"can\":\n if (t>0) {\n context.set(\"In\", 0);\n msg.payload = 0;\n msg2.payload = context.get(\"TimeoutMsg\");\n return [msg,msg1,msg2];\n }\n break;\n case \"trig\":\n if (t>0) {\n context.set(\"In\", t);\n msg.payload = t;\n msg2.payload = context.get(\"StartMsg\");\n return [msg,null,msg2];\n }\n break;\n case \"date_time\":\n var timeout = context.get(\"In\")-1;\n if (timeout>=0) {\n msg.payload = timeout;\n context.set(\"In\", timeout);\n if(timeout===0){\n msg2.payload = context.get(\"TimeoutMsg\");\n msg1.topic = \"trig\";\n return [msg,msg1,msg2]; \n }\n return [msg, null, null];\n }\n break;\n default:\n}\nreturn [null,null,null];",
"outputs": 3,
"noerr": 0,
"initialize": "// Code added here will be run once\n// whenever the node is started.\nif (context.get(\"In\") === undefined) context.set(\"In\", 0);\nif (context.get(\"tDay\") === undefined) context.set(\"tDay\", 0);\nif (context.get(\"tNight\") === undefined) context.set(\"tNight\", 0);\nif (context.get(\"StartMsg\") === undefined) context.set(\"StartMsg\", node.name + \" on\");\nif (context.get(\"TimeoutMsg\") === undefined) context.set(\"TimeoutMsg\", node.name + \" off\");",
"finalize": "",
"libs": [],
"x": 630,
"y": 280,
"wires": [
[
"f95607478f97d26e",
"2119c51023900f67"
],
[
"85b52b660829e08f"
],
[
"be9b50cb02667584",
"a756d66daffe08ea",
"2b1ef55ae7f84c06"
]
],
"outputLabels": [
"t",
"trig/can",
"Output Msg"
]
},
{
"id": "173f71bf.12772e",
"type": "ui_numeric",
"z": "c663234a94c888ee",
"name": "Time (2 to 5)",
"label": "Time<br>(2 to 5)",
"tooltip": "",
"group": "879c5e97.07fff",
"order": 6,
"width": 4,
"height": 1,
"wrap": true,
"passthru": true,
"topic": "t",
"topicType": "str",
"format": "{{msg.payload}} s",
"min": "2",
"max": "5",
"step": "1",
"x": 470,
"y": 200,
"wires": [
[
"5e1dfd7d0cd7dcad",
"22aa45a8fd5fbb35"
]
]
},
{
"id": "be9b50cb02667584",
"type": "debug",
"z": "c663234a94c888ee",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 300,
"wires": []
},
{
"id": "7a210301e50e26dd",
"type": "ui_button",
"z": "c663234a94c888ee",
"name": "",
"group": "879c5e97.07fff",
"order": 2,
"width": 0,
"height": 0,
"passthru": true,
"label": "trig 2",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "2",
"payloadType": "num",
"topic": "trig",
"topicType": "str",
"x": 250,
"y": 140,
"wires": [
[
"231cdf551d50e1f5",
"173f71bf.12772e",
"9b805eab241a91c3"
]
]
},
{
"id": "f95607478f97d26e",
"type": "debug",
"z": "c663234a94c888ee",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 220,
"wires": []
},
{
"id": "85b52b660829e08f",
"type": "debug",
"z": "c663234a94c888ee",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 260,
"wires": []
},
{
"id": "22aa45a8fd5fbb35",
"type": "debug",
"z": "c663234a94c888ee",
"name": "msg 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 140,
"wires": []
},
{
"id": "231cdf551d50e1f5",
"type": "debug",
"z": "c663234a94c888ee",
"name": "msg 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 100,
"wires": []
},
{
"id": "9b805eab241a91c3",
"type": "delay",
"z": "c663234a94c888ee",
"name": "",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"x": 450,
"y": 260,
"wires": [
[
"5e1dfd7d0cd7dcad"
]
]
},
{
"id": "6857a6622619fcb4",
"type": "inject",
"z": "c663234a94c888ee",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "date_time",
"payloadType": "date",
"x": 130,
"y": 140,
"wires": [
[
"7a210301e50e26dd"
]
]
},
{
"id": "f969cf77d0332d48",
"type": "ui_button",
"z": "c663234a94c888ee",
"name": "",
"group": "879c5e97.07fff",
"order": 3,
"width": 0,
"height": 0,
"passthru": true,
"label": "trig 4",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "4",
"payloadType": "num",
"topic": "trig",
"topicType": "str",
"x": 250,
"y": 200,
"wires": [
[
"173f71bf.12772e",
"9b805eab241a91c3"
]
]
},
{
"id": "a34b1385d55de867",
"type": "inject",
"z": "c663234a94c888ee",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "date_time",
"payloadType": "date",
"x": 130,
"y": 200,
"wires": [
[
"f969cf77d0332d48"
]
]
},
{
"id": "8cec9de3c37eed73",
"type": "ui_button",
"z": "c663234a94c888ee",
"name": "",
"group": "879c5e97.07fff",
"order": 5,
"width": 0,
"height": 0,
"passthru": true,
"label": "cancel",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "0",
"payloadType": "num",
"topic": "can",
"topicType": "str",
"x": 250,
"y": 380,
"wires": [
[
"5e1dfd7d0cd7dcad"
]
]
},
{
"id": "804834061f15d443",
"type": "inject",
"z": "c663234a94c888ee",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "date_time",
"payloadType": "date",
"x": 130,
"y": 380,
"wires": [
[
"8cec9de3c37eed73"
]
]
},
{
"id": "3975b2855c12bbf5",
"type": "ui_button",
"z": "c663234a94c888ee",
"name": "",
"group": "879c5e97.07fff",
"order": 4,
"width": 0,
"height": 0,
"passthru": true,
"label": "trig 9",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "9",
"payloadType": "num",
"topic": "trig",
"topicType": "str",
"x": 250,
"y": 260,
"wires": [
[
"9b805eab241a91c3",
"173f71bf.12772e"
]
]
},
{
"id": "e06e07010c09f601",
"type": "inject",
"z": "c663234a94c888ee",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "date_time",
"payloadType": "date",
"x": 130,
"y": 260,
"wires": [
[
"3975b2855c12bbf5"
]
]
},
{
"id": "2119c51023900f67",
"type": "ui_text",
"z": "c663234a94c888ee",
"group": "879c5e97.07fff",
"order": 7,
"width": 2,
"height": 1,
"name": "",
"label": "Timer",
"format": "{{msg.payload}}",
"layout": "col-center",
"x": 810,
"y": 180,
"wires": []
},
{
"id": "a756d66daffe08ea",
"type": "ui_text",
"z": "c663234a94c888ee",
"group": "879c5e97.07fff",
"order": 8,
"width": 2,
"height": 1,
"name": "",
"label": "Status",
"format": "{{msg.payload}}",
"layout": "col-center",
"x": 810,
"y": 340,
"wires": []
},
{
"id": "5bd66c1b0b767811",
"type": "trigger",
"z": "c663234a94c888ee",
"name": "",
"op1": "1",
"op2": "0",
"op1type": "str",
"op2type": "str",
"duration": "500",
"extend": false,
"overrideDelay": false,
"units": "ms",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 2,
"x": 380,
"y": 500,
"wires": [
[],
[
"0f2362092d75950b"
]
]
},
{
"id": "0f2362092d75950b",
"type": "trigger",
"z": "c663234a94c888ee",
"name": "",
"op1": "1",
"op2": "0",
"op1type": "str",
"op2type": "str",
"duration": "500",
"extend": false,
"overrideDelay": false,
"units": "ms",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 2,
"x": 380,
"y": 560,
"wires": [
[],
[
"5bd66c1b0b767811",
"44039a9de768a5be"
]
]
},
{
"id": "8bda45209894c851",
"type": "change",
"z": "c663234a94c888ee",
"name": "",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 140,
"y": 520,
"wires": [
[
"5bd66c1b0b767811",
"0f2362092d75950b"
]
]
},
{
"id": "2b1ef55ae7f84c06",
"type": "switch",
"z": "c663234a94c888ee",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "cont",
"v": "off",
"vt": "str"
},
{
"t": "cont",
"v": "on",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 630,
"y": 340,
"wires": [
[
"8bda45209894c851"
],
[
"5bd66c1b0b767811"
]
],
"outputLabels": [
"off",
"on"
]
},
{
"id": "767156f216cdc9c8",
"type": "debug",
"z": "c663234a94c888ee",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 520,
"wires": []
},
{
"id": "44039a9de768a5be",
"type": "change",
"z": "c663234a94c888ee",
"name": "",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "date_time",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 410,
"y": 620,
"wires": [
[
"5e1dfd7d0cd7dcad",
"767156f216cdc9c8"
]
]
},
{
"id": "562f1ec679d1830f",
"type": "ui_button",
"z": "c663234a94c888ee",
"name": "",
"group": "879c5e97.07fff",
"order": 1,
"width": 0,
"height": 0,
"passthru": true,
"label": "trig x",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "",
"payloadType": "num",
"topic": "trig",
"topicType": "str",
"x": 250,
"y": 80,
"wires": [
[
"9b805eab241a91c3"
]
]
},
{
"id": "be80cf1d18eb6987",
"type": "inject",
"z": "c663234a94c888ee",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "date_time",
"payloadType": "date",
"x": 130,
"y": 80,
"wires": [
[
"562f1ec679d1830f"
]
]
},
{
"id": "8f2cd3463ce95fd5",
"type": "comment",
"z": "c663234a94c888ee",
"name": "Synchronised 1Hz msg source cooked up for the demo",
"info": "",
"x": 400,
"y": 440,
"wires": []
},
{
"id": "6f9c872d84f7785c",
"type": "comment",
"z": "c663234a94c888ee",
"name": "Numeric Widget Problem",
"info": "",
"x": 510,
"y": 20,
"wires": []
},
{
"id": "f66021efcebf6b29",
"type": "comment",
"z": "c663234a94c888ee",
"name": "How to get the value of the Numeric Widget on startup, server restart or redepoly ?",
"info": "",
"x": 610,
"y": 60,
"wires": []
},
{
"id": "b2cd937bd998427a",
"type": "ui_button",
"z": "c663234a94c888ee",
"name": "",
"group": "879c5e97.07fff",
"order": 4,
"width": 0,
"height": 0,
"passthru": true,
"label": "trig 1",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "1",
"payloadType": "num",
"topic": "trig",
"topicType": "str",
"x": 250,
"y": 320,
"wires": [
[
"173f71bf.12772e",
"9b805eab241a91c3"
]
]
},
{
"id": "758712000386c429",
"type": "inject",
"z": "c663234a94c888ee",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "date_time",
"payloadType": "date",
"x": 130,
"y": 320,
"wires": [
[
"b2cd937bd998427a"
]
]
},
{
"id": "879c5e97.07fff",
"type": "ui_group",
"name": "node:14.7.5, red:2.0.5, red-dashboard:2.30.0",
"tab": "105c5e70.b644f2",
"order": 4,
"disp": true,
"width": "8",
"collapse": true
},
{
"id": "105c5e70.b644f2",
"type": "ui_tab",
"name": "Hydroponics",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
If I am going about this the wrong way then please feel free to suggest a simpler way.