multiple last updates

Moderator: leecollings

Post Reply
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

multiple last updates

Post 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
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: multiple last updates

Post by tiga »

Anyone?
Kedi
Posts: 561
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: multiple last updates

Post 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
Logic will get you from A to B. Imagination will take you everywhere.
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: multiple last updates

Post by tiga »

thanks for the answer but i actualy want to do it in lua
Kedi
Posts: 561
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: multiple last updates

Post by Kedi »

dzVents is lua.
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
jvdz
Posts: 2206
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: multiple last updates

Post 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')

New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: multiple last updates

Post by tiga »

thanks Jos i will give it a try!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests