When to start if need to be on time - Time Calc

Hi there, i hope you are all fine and healthy.

I am struggling with time calculation.
I am sure it is possible to do, but as im new to nodered I am really not sure how to start.

Let me explain, I need to be at work at 8 AM. I would like to set up a light, which is indicating when I should leave for work to be on time.
I have a Waze Travel Time sensor for the duration I will need.

So, I need to calculate the current time plus the travel time, if it is before 8am, light is green, if it will be between 8 and 8.10 it will be orange etc.

I am not sure how to realize this, can someone help here ?

(of course there will be more, light on only during work days and only in the morning etc. )

Thanks for the help here.

Hi Crey, welcome to the forum!

So the first thing you should is spend an hour and watch the Node-RED Essentials videos. This will be time well spent.

Next start small and build up. Figure out how to get the data from the Waze Travel Time sensor (if you need help, you should provide a link to it's documentation ot the full name of the node you have found that will send the data. I, for one, have never heard about that before)

Next attach a debug node (set to display the 'Complete msg object') to it so you can see the data coming.

Next you need to know how to test the time. A great resourse there is doing a google search using 'javascript time calculations'. Again use debug nodes to see what you come up with.

Once you have the logic working, you can work on the part of lighting the lights - however you haven't given any information on what hardware you will use and that brings me to another peice of advice.

When you open a thread remember that the person reading it is not in the room so they don't know what you know. Providing them with the hardware you are using (Rpi 4, Pi Zero W, Mac, PC, WeMos etc), OS versions, version of NR and node.js (can be found on the NR start up log) the dashboard version (if using it), names of contrib nodes you are using (node-red-contrib-?????). All this information will make it easier for someone to help you and saving the tme of the person helping you having to ask for the information.

Hopefully you're going to find this addictive and fun! I'll be waiting to hear from you.

Not sure what this is? Can you elaborate? I can't find a useful API for Waze.

Hi @zenofmud

thanks for you informations.
I did read the manuals and tried to solve it by msyself.

But of course I missed the easiest things.
I am using / working with Home assistant and the installed NodeRed Component.
Works like a charme, having already a lot of flows.

@TotallyInformation im using the component from HA -> https://www.home-assistant.io/integrations/waze_travel_time/
More or less the same as GoogleMaps api request

It works good and gives me a number something like XX.XX in Minutes, so 41.46 minutes.
I am ok with just the integer, do not need the number after the dot

It is just the normale node red (V. 7.2.11)
Also i am sure I do not need any contrib for this.

What I would use is the function node of course.
I have the value of the current time (from the inject node) also converted it to a time one can read and work with

[{"id":"b5fd4031.138768","type":"inject","z":"c43d799.c48b188","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":2560,"wires":[["8140daf7.9698"]]},{"id":"8140daf7.9698","type":"function","z":"c43d799.c48b188","name":"time_convert","func":"topic = msg.topic;\nd = new Date();\ndformat = [d.getHours(),d.getMinutes()].join(':');\nmsg.payload=dformat\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":2560,"wires":[[]]}]

And of course I have the time from the Waze sensor.

Now I need the join node, I think, to combine them, so I can then calculate with the Times within a function node.
And here it stops I am not sure how to join them into one function node.
I think I could give them different msg. name but not quite sure about.
Maybe if I get a tipp here I can then check how to add / subtract the time.

feed the waze time into function and compare current time there as below

[{"id":"b5fd4031.138768","type":"inject","z":"c43d799.c48b188","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":2560,"wires":[["8140daf7.9698"]]},{"id":"8140daf7.9698","type":"function","z":"c43d799.c48b188","name":"time_convert","func":"topic = msg.topic;\nd = new Date();\ndformat = [d.getHours(),d.getMinutes()].join(':');\nmsg.payload=dformat\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":2560,"wires":[[]]}]

Ahhh, knowng that you are using Home Assistant was an important peice of information. In your first post you said you were new to node-red but now you are saying you have made many flows...

Any way, put a debug node on the output of the waze node and show us what the data actually looks like. The 41.46 might mean the travel time is 41 minutes, 46 seconds but you should check if that is correct in the Waze documentation.

Then do the calculation on paper. Doing that should make coding simple. You can pass the travel time into a function node and in the code get the current time (google javascript Date Get Methods)

BTW Node-RED is at version v1.2.6 so the version you are reporting must be the Home Assistant version.

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