Problems with hour

Hi guys I have this flow but I'm trying to get my current hour but is not even close I don't know what is happening
Sin título

[{"id":"5f2dfd9c.f03124","type":"function","z":"8b253657.5d90d8","name":"","func":"global.set('valueone',msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":232,"wires":[["43dda46c.a02cac"]]},{"id":"43dda46c.a02cac","type":"debug","z":"8b253657.5d90d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":534,"y":232,"wires":[]},{"id":"bc2e421c.1ea6d","type":"inject","z":"8b253657.5d90d8","name":"messagenumerone","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()\t","payloadType":"jsonata","x":180,"y":232,"wires":[["5f2dfd9c.f03124"]]},{"id":"29a17fb.d08298","type":"inject","z":"8b253657.5d90d8","name":"messagenumertwo","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()","payloadType":"jsonata","x":180,"y":280,"wires":[["76094289.9729cc"]]},{"id":"83e2c27b.29aec","type":"debug","z":"8b253657.5d90d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":534,"y":280,"wires":[]},{"id":"76094289.9729cc","type":"function","z":"8b253657.5d90d8","name":"","func":"var getvalueone = global.get(\"valueone\");\nvar getvaluetwo = msg.payload;\nvar nd = new Date().toISOString().split(\"T\");\nvar d = nd[0]\nvar t = nd[1].substring(0,8)\nvar dt = d+\" \"+t\nreturn {payload:{\"time\":dt,\"value2\":getvaluetwo,\"value1\":getvalueone} };","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":280,"wires":[["83e2c27b.29aec"]]}]

Ok this in context of your previous flow correct ?

What timezone are you in ?

yeah this of my previous flow my timezone is in mexico it will be UTC -5

Try this flow instead. Date/time are not always friendly to deal with, here I used jsonata in a change node instead as it has built-in timezones makes it a lot easier. Not need for function nodes either

[{"id":"9f9dbced.7ee338","type":"debug","z":"ea67f3fb.0745f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":240,"wires":[]},{"id":"c24f1260.e9847","type":"inject","z":"ea67f3fb.0745f","name":"messagenumerone","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()\t","payloadType":"jsonata","x":268,"y":240,"wires":[["beaddbe2.c36c3"]]},{"id":"7473052f.0b625c","type":"inject","z":"ea67f3fb.0745f","name":"messagenumertwo","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()","payloadType":"jsonata","x":268,"y":288,"wires":[["47b6ad5c.3c2bdc"]]},{"id":"c8a4a756.b2b268","type":"debug","z":"ea67f3fb.0745f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":288,"wires":[]},{"id":"47b6ad5c.3c2bdc","type":"change","z":"ea67f3fb.0745f","name":"","rules":[{"t":"set","p":"value2","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.time","pt":"msg","to":"$moment().tz('America/Mexico_City').format(\"YYYY-MM-DD hh:mm:ss\")\t","tot":"jsonata"},{"t":"set","p":"payload.value1","pt":"msg","to":"value1","tot":"global"},{"t":"move","p":"value2","pt":"msg","to":"payload.value2","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":488,"y":288,"wires":[["c8a4a756.b2b268"]]},{"id":"beaddbe2.c36c3","type":"change","z":"ea67f3fb.0745f","name":"","rules":[{"t":"set","p":"value1","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"value1","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":488,"y":240,"wires":[["9f9dbced.7ee338"]]}]

Alright actually I haven't seen a flow like that to work with Date/time and yeah is not really friendly to work with that. Thanks

Alternatively you could use node-red-contrib-simpletime.

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