Greetings, I'm new to Node-RED & learning more everyday, however, I've got a dilemma that I havent been able to fix by searching.
I'm attempting to use the DSM examples to track cumulative "on" time of a process, which seems to be working, however, my understanding is that the "GSheet" node that I'm wanting to pass data to requires the data to be be input as "msg.payload".
Therefore, I'm attempting to move the "msg.data.time" value to "msg.payload", and this appears to work initially. I can inject "on" then "off" and the value transfers as expected, however, upon attempting to inject "on" again, the value changes to "NaN" & must be reset.
DSM is currently beyond my grasp, & by looking at the code itself, I'm at a loss on how to manipulate the data. Currently, all I'm needing is the msg.data.time value, but I dont see how to output that directly as the payload.
Any assistance would be greatly appreciated,
[{"id":"b55c15bd9654f34f","type":"inject","z":"a93a3cda7eefd398","name":"on","props":[{"p":"test","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"on","x":730,"y":2820,"wires":[["c80f6266c96ef49e"]]},{"id":"3e5eb9c13e1b28b7","type":"inject","z":"a93a3cda7eefd398","name":"off","props":[{"p":"test","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"off","x":730,"y":2860,"wires":[["c80f6266c96ef49e"]]},{"id":"fec05ab30e7b3d4a","type":"inject","z":"a93a3cda7eefd398","name":"reset","props":[{"p":"test","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","x":730,"y":2900,"wires":[["c80f6266c96ef49e"]]},{"id":"f4d9399d44311fd2","type":"debug","z":"a93a3cda7eefd398","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1170,"y":2860,"wires":[]},{"id":"c80f6266c96ef49e","type":"dsm","z":"a93a3cda7eefd398","name":"operating time","sm_config":"{\n \"stateOutput\": \"output\",\n \"currentState\": \"stopped\",\n \"states\": {\n \"stopped\": {\n \"on\": \"started\"\n },\n \"started\": {\n \"inc\": \"counting\",\n \"off\": \"stopped\"\n },\n \"counting\": {\n \"inc\": \"counting\",\n \"off\": \"stopped\"\n }\n },\n \"data\": {\n \"time\": 0,\n \"step\": 1,\n \"prev_time\": null\n },\n \"methods\": {\n \"on\": [\n \"if (sm.currentState === 'started') {\",\n \" sm.data.prev_time = Date.now();\",\n \" node.send(msg);\",\n \" resume('inc', msg);\",\n \"}\"\n ],\n \"inc\": [\n \"timeout.interval = setTimeout(function() {\",\n \" var now = Date.now();\",\n \" sm.data.time += now - sm.data.prev_time;\",\n \" sm.data.prev_time = now;\",\n \" resume('inc', msg);\",\n \"}, sm.data.step*1000);\",\n \"output = false;\"\n ],\n \"off\": [\n \"clearTimeout(timeout.interval);\"\n ],\n \"reset\": [\n \"sm.data.time = 0;\"\n ],\n \"onTransition\": [\n \"sm.text = 'time '+ Math.round(sm.data.time / 1000);\"\n ],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.currentState === 'counting' ? 'green' : 'grey';\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text;\"\n }\n }\n }\n}","x":950,"y":2860,"wires":[["da75ede56e87391f","f4d9399d44311fd2"]]},{"id":"da75ede56e87391f","type":"switch","z":"a93a3cda7eefd398","name":"","property":"data.time","propertyType":"msg","rules":[{"t":"istype","v":"undefined","vt":"undefined"},{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1210,"y":2900,"wires":[[],["73208baae0e266e9"]]},{"id":"73208baae0e266e9","type":"change","z":"a93a3cda7eefd398","name":"","rules":[{"t":"move","p":"data.time","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1380,"y":2900,"wires":[["f697df2841a8934e"]]},{"id":"f697df2841a8934e","type":"debug","z":"a93a3cda7eefd398","name":"debug 18","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1560,"y":2900,"wires":[]}]