Traffic ETA time calculating Topic is solved

Moderator: leecollings

Post Reply
dennis075
Posts: 11
Joined: Saturday 20 January 2018 12:05
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Traffic ETA time calculating

Post by dennis075 »

Goodevening,

I got a part of the google maps ETA script that i want to tweak, see below:

Code: Select all

("%02d:%02d"):format(time.hour, time.min+(traffic_Home2Work)
Traffic_Home2Work is a variable for the calculated travel time. I want to add it to the current time to know the ETA.
16:20 + 20 min works fine --> 16:40
16:50 + 20 min gives 16:70

On the forum I can't find the correct way of coding, hope someone can help me as this is probably not the hardest question here ;)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Traffic ETA time calculating

Post by waaren »

dennis075 wrote: Monday 11 May 2020 19:14
I got a part of the google maps ETA script that i want to tweak, see below:

Traffic_Home2Work is a variable for the calculated travel time. I want to add it to the current time to know the ETA.
16:20 + 20 min works fine --> 16:40
16:50 + 20 min gives 16:70
Time / date are not the easiest part of Lua.

See below a solution.

Code: Select all

local traffic_Home2Work = 20 -- travel time in minutes

local now = os.date('*t') -- now is a time object based on current time ; os.date('*t') is equivalent to os.date('*t', os.time())
local atWork = os.date('*t', os.time() + traffic_Home2Work * 60) -- os.time() = number of seconds of current time since 1970/01/01 

print('Current time: ' .. string.format('%02d:%02d', now.hour, now.min))
print('Arrival at work after ' .. traffic_Home2Work .. ' minutes travel: ' ..  string.format('%02d:%02d', atWork.hour, atWork.min))
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dennis075
Posts: 11
Joined: Saturday 20 January 2018 12:05
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Traffic ETA time calculating

Post by dennis075 »

Thanks for taking time to help me out. A little late reaction, but I just implemented it in my script and works perfect! Thanks a lot.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest