LUA TimeDiff not working?!

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

LUA TimeDiff not working?!

Post by emme »

got a wired thing....

Code: Select all

function timeDiff(dName,dType)
    if dType == 'v' then 
        updTime = uservariables_lastupdate[dName]
    elseif dType == 'd' then
        updTime = otherdevices_lastupdate[dName]
    end 
    t1 = os.time()
    year = string.sub(updTime, 1, 4)
    month = string.sub(updTime, 6, 7)
    days = string.sub(updTime, 9, 10)
    hour = string.sub(updTime, 12, 13)
    minutes = string.sub(updTime, 15, 16)
    seconds = string.sub(updTime, 18, 19)

    t2 = os.time{year=year, month=month, day=days, hour=hour, min=minutes, sec=seconds}
    tDiff = os.difftime(t1,t2)
    return tDiff
end
the

Code: Select all

t2 = os.time{year=year, month=month, day=days, hour=hour, min=minutes, sec=seconds}
rturns this error:
field 'day' missing in date table
The most dangerous phrase in any language is:
"We always done this way"
SweetPants

Re: LUA TimeDiff not working?!

Post by SweetPants »

zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: LUA TimeDiff not working?!

Post by zicht »

I use this :

Code: Select all

function timedifference (s)   --- tijdverschil bepalen sinds laatste schakeling in sec
   if s == nil then print("Error  ") end
   year = string.sub(s, 1, 4)
   month = string.sub(s, 6, 7)
   day = string.sub(s, 9, 10)
   hour = string.sub(s, 12, 13)
   minutes = string.sub(s, 15, 16)
   seconds = string.sub(s, 18, 19)
   t1 = os.time()
   t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
   difference = os.difftime (t1, t2)
   return difference
end
Call it like

Code: Select all

difference2 = timedifference(otherdevices_lastupdate['Beweging Woonkamer'])
never have any problem.
I only see dayfield missing when i use

Code: Select all

difference2 = timedifference(Devicechanged_lastupdate['Beweging Woonkamer'])
But there is no reason to use devicechanged as otherdevices will return the exact wanted result
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest