Page 1 of 1

multiple last updates

Posted: Friday 17 November 2023 22:36
by tiga
how can i implement multiple last updates into one script?

i have tried multiple versions but nu succes.

Code: Select all

--laatst gezien:

laatst_gezien_woonkamer = os.time()
s = otherdevices_lastupdate['temperatuur woonkamer']

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)

laatst_gezien_cp = os.time()
s = otherdevices_lastupdate['slaap c/p']

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)


commandArray = {}


t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference1 = (os.difftime (laatst_gezien_woonkamer, t2))
difference2 = (os.difftime (laatst_gezien_cp, t2))
i want to calculate 5 difftimes in one script if possible

Re: multiple last updates

Posted: Saturday 18 November 2023 15:25
by tiga
Anyone?

Re: multiple last updates

Posted: Saturday 18 November 2023 15:45
by Kedi
Use dzVents with time object: https://www.domoticz.com/wiki/DzVents:_ ... ime_object
It is much easier to handle and calculate with time.
And use the data section to store previous lastupdates

Re: multiple last updates

Posted: Saturday 18 November 2023 19:35
by tiga
thanks for the answer but i actualy want to do it in lua

Re: multiple last updates

Posted: Saturday 18 November 2023 20:21
by Kedi
dzVents is lua.

Re: multiple last updates

Posted: Saturday 18 November 2023 20:35
by jvdz
something like this?:

Code: Select all

--
-- Calculate the time difference in seconds between Now and supplied time. in HH:MM:SS
function datetimedifferencenow(s)
	local difference = 0
	if (s ~= nil) then
		s = s .. ':00' -- add seconds in case only hh:mm is supplied
		local syear = string.sub(s, 1, 4)
		local smonth = string.sub(s, 6, 7)
		local sday = (string.sub(s, 9, 10) or '01')
		local shour = string.sub(s, 12, 13)
		local sminutes = string.sub(s, 15, 16)
		local sseconds = string.sub(s, 18, 19)
		local t1 = os.time()
		local t2 = os.time { year = syear, month = smonth, day = sday, hour = shour, min = sminutes, sec = sseconds }
		difference = os.difftime(t1, t2)
	end
	return difference
end

-- calcutale number of seconds passed since lastupdate
function getlastupdatediff(device)
	if otherdevices_lastupdate[device] then
		return datetimedifferencenow(otherdevices_lastupdate[device])
	else
		return 0
	end
end

difference1 = getlastupdatediff('temperatuur woonkamer')
difference2 = getlastupdatediff('slaap c/p')


Re: multiple last updates

Posted: Saturday 18 November 2023 20:42
by tiga
thanks Jos i will give it a try!