26.01.2021, 10:54
(This post was last modified: 27.01.2021, 07:36 by davidchispas.)
(25.01.2021, 17:04)admin Wrote: Try changing "delta - timeout" calculation in line 3 to "timeout - delta"
Code:
--Set temperature
Tc = '11/0/5' -- 09.001 Temperature (2Bytes)
--Reference Temperature
TRef = '11/0/20' -- 09.001 Temperature (2Bytes)
--Output object that enables resident script
addr = '11/0/32' --01. 1 bit (boolean)
--Countdown in days
RstDays = '11/0/31' --1 Bytes unsigned integer
--Countdown in hours
RstHours = '11/0/30' --1 Bytes unsigned integer
----------------------------------------------------------------------
obj = grp.find(addr)
if obj and obj.data then
delta = os.time() - obj.updatetime
timeout = (grp.getvalue(RstDays) * 24 + grp.getvalue(RstHours)) * 60 * 60
remaining = math.max(0, timeout - delta)
days = math.floor(remaining / 86400)
hours = math.floor((remaining % 86400) / 3600)
minutes = math.floor((remaining % 3600) / 60)
txtremaining = days .. 'd ' .. hours .. 'h ' .. minutes .. 'm '
grp.checkupdate('11/0/33', txtremaining)
-- switch off when timer expires
if remaining == 0 then
grp.write(addr, false)
grp.write(Tc, grp.getvalue(TRef))
end
end
Ok thanks, that's how it works. I want to get the counter reset to 0 when 'Tc' == 'TRef'. What can I add to the script?
This script runs every 1 second to be immediate, but the timer status sends it every second, I changed it to check.uptade to correct that. My question is if it is better like this or run it every 60 seconds ....?
To take advantage of this script to other functions, can I add seconds? I have tried but without positive result.