# Dsm faults to NaN when attempting to move message to msg.payload

**URL:** <https://discourse.nodered.org/t/dsm-faults-to-nan-when-attempting-to-move-message-to-msg-payload/86358>\
**Category:** General\
**Created:** [12 March 2024 00:21 UTC](https://discourse.nodered.org/t/dsm-faults-to-nan-when-attempting-to-move-message-to-msg-payload/86358 "2024-03-12T00:21:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EW57](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@EW57](https://discourse.nodered.org/u/EW57)\
**Post date:** [12 March 2024 00:21 UTC](https://discourse.nodered.org/t/dsm-faults-to-nan-when-attempting-to-move-message-to-msg-payload/86358/1 "2024-03-12T00:21:15Z")

</div>

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,

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [12 March 2024 00:35 UTC](https://discourse.nodered.org/t/dsm-faults-to-nan-when-attempting-to-move-message-to-msg-payload/86358/2 "2024-03-12T00:35:36Z")

</div>

What is DSM? Can you share the URL of the DSM examples?

---

<div class="post-metadata">

**Author:** ![EW57](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@EW57](https://discourse.nodered.org/u/EW57)\
**Post date:** [12 March 2024 01:36 UTC](https://discourse.nodered.org/t/dsm-faults-to-nan-when-attempting-to-move-message-to-msg-payload/86358/3 "2024-03-12T01:36:38Z")

</div>

Thanks for the quick reply, this is the node & corresponding wiki I was referencing:

> **[node-red-contrib-dsm](https://flows.nodered.org/node/node-red-contrib-dsm)**
>
> A dynamic state machine node based on the finite state machine model.

> **[Home](https://github.com/cflurin/node-red-contrib-dsm/wiki)**
>
> A dynamic state machine node based on the Finite state machine. - cflurin/node-red-contrib-dsm

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 June 2024 01:36 UTC](https://discourse.nodered.org/t/dsm-faults-to-nan-when-attempting-to-move-message-to-msg-payload/86358/4 "2024-06-10T01:36:58Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
