fellinga / node-red-contrib-ui-time-scheduler

Easily power on/off any kind of device based on a schedule that you can easily create at the node-red-dashboard frontend.
MIT License
37 stars 15 forks source link

Fixed payload to ui-scheduler but incorrect result #68

Closed eddyyanto closed 2 years ago

eddyyanto commented 2 years ago

I have a ui-scheduler and 2 ui-dropdown for on and off time event (this will integrated with a UI from external non js system as well). The idea is for user to select the on or off time and update the ui-scheduler accordingly.

For the date, it's currently restricted to Monday only and for the on time between 07:00 to 09:30 and off time between 17:00 to 19:30. I've pre-populated the ui-dropdown with the correct timestamp eg: 07:00 : 1637535600000 09:00 : 1637542800000 and so on.

But it seemed that there's a bug somewhere that when the payload is sent to ui-scheduler, it doesn't update correctly. Eg: If 07:00 and 07:30 is selected on the on time, the date changed to Tue even though the date payload if fixed.

Any idea?

Here's the sample flow:

[{"id":"2a3162a527b8714d","type":"tab","label":"Time Scheduler Test","disabled":false,"info":""},{"id":"c3a45617633072f0","type":"ui_time_scheduler","z":"2a3162a527b8714d","group":"687305bd06d91bc7","name":"","startDay":"0","refresh":60,"devices":["SCHEDULE"],"singleOff":false,"onlySendChange":false,"customPayload":false,"eventMode":true,"eventOptions":[{"label":"AV On","event":"true"},{"label":"AV Off","event":"false"}],"sendTopic":false,"lat":"","lon":"","customContextStore":"stroreInFile","outputs":2,"order":4,"width":"16","height":"5","x":950,"y":580,"wires":[[],[]]},{"id":"4886396b132eb5f5","type":"ui_dropdown","z":"2a3162a527b8714d","name":"","label":"On Time","tooltip":"","place":"Select On Time","group":"687305bd06d91bc7","order":2,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"07:00","value":"1637535600000","type":"str"},{"label":"07:30","value":"1637537400000","type":"str"},{"label":"08:00","value":"1637539200000","type":"str"},{"label":"08:30","value":"1637541000000","type":"str"},{"label":"09:00","value":"1637542800000","type":"str"},{"label":"09:30","value":"1637544600000","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":220,"y":560,"wires":[["60d833492e5c597d"]]},{"id":"60d833492e5c597d","type":"change","z":"2a3162a527b8714d","name":"set onTime = payload","rules":[{"t":"set","p":"onTime","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":560,"wires":[["17bc7f4d1695fd47"]]},{"id":"5fe8ecaf9f1f6002","type":"change","z":"2a3162a527b8714d","name":"set offTime = payload","rules":[{"t":"set","p":"offTime","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":600,"wires":[["17bc7f4d1695fd47"]]},{"id":"42a7446188f1447b","type":"ui_dropdown","z":"2a3162a527b8714d","name":"","label":"Off Time","tooltip":"","place":"Select Off Time","group":"687305bd06d91bc7","order":3,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"17:00","value":"1637571600000","type":"str"},{"label":"17:30","value":"1637573400000","type":"str"},{"label":"18:00","value":"1637575200000","type":"str"},{"label":"18:30","value":"1637577000000","type":"str"},{"label":"19:00","value":"1637578800000","type":"str"},{"label":"19:30","value":"1637580600000","type":"str"}],"payload":"","topic":"topic","topicType":"msg","className":"","x":220,"y":600,"wires":[["5fe8ecaf9f1f6002"]]},{"id":"17bc7f4d1695fd47","type":"function","z":"2a3162a527b8714d","name":"","func":"onTime = flow.get(\"onTime\");\noffTime = flow.get(\"offTime\");\n\nmsg.payload = '{\"timers\":[{\"starttime\":' + onTime + ',\"days\":[0,1,0,0,0,0,0],\"output\":\"0\",\"event\":true},{\"starttime\":' + offTime + ',\"days\":[0,1,0,0,0,0,0],\"output\":\"0\",\"event\":false}],\"settings\":{}}';\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":580,"wires":[["c3a45617633072f0"]]},{"id":"687305bd06d91bc7","type":"ui_group","name":"Omnigram","tab":"2936b813.6cde68","order":1,"disp":false,"width":"16","collapse":false,"disabled":false,"hidden":false,"className":""},{"id":"2936b813.6cde68","type":"ui_tab","name":"Scheduler Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

fellinga commented 2 years ago

Hi @eddyyanto,

that is a time zone issue. Your value for 07:00 is 1637535600000 which would be a Sunday in UTC Time (Sun Nov 21 2021 23:00:00). The days array is stored in UTC time too! [0,1,0,0,0,0,0] therefore does not match with the timestamp that you have provided.

That is also why it works after 08:00 because 08:00 in Singapore would be Midnight in UTC Time and therefore Monday already.

Please let me know if this helps!