# Triggering I/O from unix time stamps

**URL:** <https://discourse.nodered.org/t/triggering-i-o-from-unix-time-stamps/64595>\
**Category:** General\
**Created:** [1 July 2022 19:06 UTC](https://discourse.nodered.org/t/triggering-i-o-from-unix-time-stamps/64595 "2022-07-01T19:06:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Corey](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Corey](https://discourse.nodered.org/u/Corey)\
**Post date:** [1 July 2022 19:06 UTC](https://discourse.nodered.org/t/triggering-i-o-from-unix-time-stamps/64595/1 "2022-07-01T19:06:01Z")

</div>

Hi,

I'm relatively new to this, so apologies in advance.

I'm polling an API and storing a few time stamps and converting them to Unix to do basic calculations. What I would like to do is have an I/O triggered when the current time is 24 hours prior to the stored timestamp.

I'm able get the values and see them in the debug nodes but storing them to call or compare is proving to be difficult:

```auto
sysTime = Date.now()
startTimeTwentyFour = msg.TFhourStart
while (msg.eventid !== null)
    if (sysTime >= startTimeTwentyFour){
      trigger = 1;
    } else {
      trigger = 0;}
    
return msg;

```

I'm probably doing something obviously wrong, but can't seem to figure it out. How can I pass the trigger value??

```auto
[{"id":"b5d50dec.34ffc","type":"http request","z":"64b0889c.049f88","name":"Dispatch Events","method":"GET","ret":"txt","paytoqs":"query","url":"https://link-stg.cpowercorp.com/vLinkService.svc/{{{seshid}}}/DispatchEvents","tls":"","persist":true,"proxy":"","authType":"","senderr":false,"x":120,"y":240,"wires":[["de017d2b.63308","8ef32e9e.5606b"]]},{"id":"de017d2b.63308","type":"xml","z":"64b0889c.049f88","name":"","property":"payload","attr":"","chr":"","x":130,"y":320,"wires":[["3b6b89f24daf877e","e2b7f3c51ac56d1f"]]},{"id":"e00b1d51a858d12a","type":"function","z":"64b0889c.049f88","name":"24 hour logic","func":"sysTime = Date.now()\nstartTimeTwentyFour = msg.TFhourStart\nwhile (global.eventid !== null)\n if (sysTime >= startTimeTwentyFour){\n trigger = 1;\n } else {\n trigger = 0;}\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1110,"y":360,"wires":[["1e75c370236a42e8"]]},{"id":"3b6b89f24daf877e","type":"change","z":"64b0889c.049f88","name":"","rules":[{"t":"set","p":"StartTime","pt":"msg","to":"payload.DispatchEventResult.DispatchEventList[0].DispatchEvent[0].StartDate[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":320,"wires":[["74f49c601e5bd373"]]},{"id":"e2b7f3c51ac56d1f","type":"change","z":"64b0889c.049f88","name":"","rules":[{"t":"set","p":"EndTime","pt":"msg","to":"payload.DispatchEventResult.DispatchEventList[0].DispatchEvent[0].EndDate[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":360,"wires":[["93b144dedfa00494"]]},{"id":"1e75c370236a42e8","type":"debug","z":"64b0889c.049f88","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1340,"y":320,"wires":[]},{"id":"93b144dedfa00494","type":"function","z":"64b0889c.049f88","name":"End Time Epoch Conv","func":"msg.payload = new Date(msg.EndTime)\nmsg.payload = msg.payload.getTime()\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":360,"wires":[["fba9751eab0a4d17"]]},{"id":"fba9751eab0a4d17","type":"debug","z":"64b0889c.049f88","name":"End Time Epoch Conv","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":660,"y":400,"wires":[]},{"id":"74f49c601e5bd373","type":"function","z":"64b0889c.049f88","name":"Start Time Epoch Conv","func":"msg.payload = new Date(msg.StartTime)\nmsg.payload = msg.payload.getTime()\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":320,"wires":[["f4e69f49fe1e21f3"]]},{"id":"edcb7613e0cf2e84","type":"debug","z":"64b0889c.049f88","name":"Start Time Epoch Conv","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1370,"y":380,"wires":[]},{"id":"f4e69f49fe1e21f3","type":"function","z":"64b0889c.049f88","name":"Start Time Epoch Conv -24hours","func":"msg.payload = msg.payload - (24*60*60);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":950,"y":320,"wires":[["9f0acfc3bccac6c1"]]},{"id":"69bc7967decad8a4","type":"debug","z":"64b0889c.049f88","name":"Start Time Epoch Conv -24hours","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1390,"y":260,"wires":[]},{"id":"9f0acfc3bccac6c1","type":"change","z":"64b0889c.049f88","name":"","rules":[{"t":"set","p":"TFhourStart","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":360,"wires":[["69bc7967decad8a4","e00b1d51a858d12a"]]}]

```

---

<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:** [1 July 2022 21:07 UTC](https://discourse.nodered.org/t/triggering-i-o-from-unix-time-stamps/64595/2 "2022-07-01T21:07:35Z")

</div>

I can't import your flow at the moment so I can only look at the function code you posted above.

You are setting a variable called trigger (though I don't see a declaration for it, not sure if this is an error in itself).  
That variable only exists within this function node, and only while it is processing the current message, you can't use it elsewhere in the flow.

Possible solutions include:  
Make trigger part of the message object  
`msg.trigger = 1`  
Store the value in context variables - "global" or "flow" in scope  
`flow.set('trigger', 1)` (Be careful with this because another message arriving at this node might change the value before you have finished with it)

---

<div class="post-metadata">

**Author:** ![Corey](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Corey](https://discourse.nodered.org/u/Corey)\
**Post date:** [5 July 2022 17:08 UTC](https://discourse.nodered.org/t/triggering-i-o-from-unix-time-stamps/64595/3 "2022-07-05T17:08:57Z")

</div>

Thanks, will give it a shot and report back!

---

<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:** [3 September 2022 17:09 UTC](https://discourse.nodered.org/t/triggering-i-o-from-unix-time-stamps/64595/4 "2022-09-03T17:09:02Z")

</div>

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