r/nodered • u/longunmin • Aug 24 '20
How to trigger this flow without inject node?
Does anyone know who I can trigger this flow without the inject node? I can't get the dsm node to trigger without the inject node? [ { "id": "ed4578a7.582328", "type": "inject", "z": "c34989d3.2e4e18", "name": "", "topic": "", "payload": "on", "payloadType": "str", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 810, "y": 560, "wires": [ [ "9d8bcca5.c96f9" ] ] }, { "id": "e30395e5.570848", "type": "function", "z": "c34989d3.2e4e18", "name": "Payload Adjustment", "func": "var step = msg.payload;\n\nvar step_pcg = step.toFixed(0);\n\nmsg.payload = step_pcg;\n\nreturn msg;", "outputs": 1, "noerr": 0, "x": 1760, "y": 580, "wires": [ [ "5303a77e.936ae8" ] ] }, { "id": "e6b6c2ad.86995", "type": "change", "z": "c34989d3.2e4e18", "name": "Set JSON Message", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "{\"initialdelay\":2,\"start\":255,\"end\":0,\"duration\":60,\"step\":5,\"unit\":\"Seconds\"}", "tot": "json" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1270, "y": 500, "wires": [ [ "9f97e877.32dc18" ] ] }, { "id": "6dd98ad1.6be564", "type": "change", "z": "c34989d3.2e4e18", "name": "Set JSON Message - Stop", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "stop", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1280, "y": 660, "wires": [ [ "9f97e877.32dc18" ] ] }, { "id": "9d8bcca5.c96f9", "type": "switch", "z": "c34989d3.2e4e18", "name": "", "property": "payload", "propertyType": "msg", "rules": [ { "t": "eq", "v": "on", "vt": "str" }, { "t": "eq", "v": "stop", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 950, "y": 560, "wires": [ [ "e6b6c2ad.86995" ], [ "6dd98ad1.6be564" ] ] }, { "id": "9f97e877.32dc18", "type": "dsm", "z": "c34989d3.2e4e18", "name": "fade in/out", "sm_config": "{\n \"inputTrigger\": \"topic\",\n \"stateOutput\": \"current\",\n \"currentState\": \"stopped\",\n \n \"states\": {\n \"stopped\": {\n \"start\": \"started\",\n \"stop\": \"stopped\"\n },\n \"started\": {\n \"fade_in\": \"fade_in\",\n \"fade_out\": \"fade_out\",\n \"stop\": \"stopped\"\n },\n \"fade_in\": {\n \"fade_in\": \"fade_in\",\n \"stop\": \"stopped\"\n },\n \"fade_out\": {\n \"fade_out\": \"fade_out\",\n \"stop\": \"stopped\"\n }\n },\n \"data\": {\n \"initialdelay\": 0,\n \"start\": 0,\n \"end\": 1,\n \"duration\": 3000,\n \"step\": 100,\n \"unit\": \"Milliseconds\",\n \"factor\": 1\n },\n \"methods\": {\n \"init\": [\n \"sm.tick = function(tran, msg) {\",\n \" timeout.id = setTimeout(function() {\",\n \" sm.text = 'fading ' + sm.data.duration + ' ' + sm.data.unit + ' - ' + sm.data.actual;\",\n \" msg.payload = sm.data.actual;\",\n \" node.send(msg);\",\n \" resume(tran, msg);\",\n \" }, sm.data.step * sm.data.factor);\",\n \"};\",\n \"sm.factors = {'milliseconds': 1, 'seconds': 1000, 'minutes': 60000};\",\n \"sta.fill = 'grey';\"\n ],\n \"start\": [\n \"if (typeof msg.payload.initialdelay !== 'undefined') sm.data.initialdelay = msg.payload.initialdelay;\",\n \"if (typeof msg.payload.start !== 'undefined') sm.data.start = msg.payload.start;\",\n \"if (typeof msg.payload.end !== 'undefined') sm.data.end = msg.payload.end;\",\n \"if (typeof msg.payload.duration !== 'undefined') sm.data.duration = msg.payload.duration;\",\n \"if (typeof msg.payload.step !== 'undefined') sm.data.step = msg.payload.step;\",\n \"if (typeof msg.payload.unit !== 'undefined') {\",\n \" if (sm.factors.hasOwnProperty(msg.payload.unit.toLowerCase())) {\",\n \" sm.data.factor = sm.factors[msg.payload.unit.toLowerCase()];\",\n \" sm.data.unit = msg.payload.unit;\",\n \" } else {\",\n \" node.warn('>' + msg.payload.unit + '< unknown, available: Milliseconds, Seconds, Minutes');\",\n \" };\",\n \"} else {\",\n \" sm.data.factor = 1;\",\n \" sm.data.unit = 'Milliseconds';\",\n \"};\",\n \n \"clearTimeout(timeout.id);\",\n \"timeout.id = setTimeout(function() {\",\n \" sm.data.delta = (sm.data.step / sm.data.duration) * Math.abs(sm.data.start - sm.data.end);\",\n \" sm.data.actual = sm.data.start;\",\n \n \" if (sm.data.end > sm.data.start) {\",\n \" sm.text = 'fade_in';\",\n \" resume('fade_in', msg);\",\n \" } else {\",\n \" sm.text = 'fade_out';\",\n \" resume('fade_out', msg);\",\n \" };\",\n \"}, sm.data.initialdelay * sm.data.factor);\",\n \"sm.text = 'initial delay ' + sm.data.initialdelay + ' ' + sm.data.unit;\",\n \"msg.payload = sm.data.start;\",\n \"node.send(msg);\"\n ],\n \"fade_in\": [\n \"if (sm.data.actual < sm.data.end) {\",\n \" sm.data.actual = Math.round((sm.data.actual + sm.data.delta) * 100) / 100;\",\n \" if (sm.data.actual > sm.data.end) {sm.data.actual = sm.data.end;};\",\n \" sm.tick('fade_in', msg);\",\n \"} else {\",\n \" resume('stop', msg);\",\n \"};\"\n ],\n \"fade_out\": [\n \"if (sm.data.actual > sm.data.end) {\",\n \" sm.data.actual = Math.round((sm.data.actual - sm.data.delta) * 100) / 100;\",\n \" if (sm.data.actual < sm.data.end) {sm.data.actual = sm.data.end;};\",\n \" sm.tick('fade_out', msg);\",\n \"} else {\",\n \" resume('stop', msg);\",\n \"};\"\n ],\n \"stop\": [\n \"sm.text = sm.currentState;\",\n \"clearTimeout(timeout.id);\"\n ],\n \"onAfterTransition\": \"output = false;\",\n \"status\": {\n \"fill\": {\n \"get\": \"sm.currentState === 'stopped' ? 'grey': 'green';\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text || sm.currentState;\"\n }\n }\n }\n}", "x": 1530, "y": 580, "wires": [ [ "e30395e5.570848" ] ] } ]
3
u/mgithens1 Aug 24 '20
Instead of asking us to load your flow, shouldn't you just ask your desire? You want to kick off something based on something.... just tell us!!