25.06.2017, 07:48
(This post was last modified: 25.06.2017, 07:55 by XSPA2474KW.)
(08.06.2017, 10:28)mlaudren Wrote: Hi,
You could use couple of counter and timer to define time since last push like:
Code:local pushcount = storage.get('pushcount', 0)
local timepush = os.time()
local timepushinit = storage.get('lastpush', 0)
delta = timepush - timepushinit
if delta > 60 then
pushcount = 0
storage.set('lastpush', timepush)
end
if pushcount == 0 then
-- do something
elseif pushcount == 1 and delta > 20 then
--do something
elseif pushcount == 2 and delta > 30 then
-- ...
else
-- do something
end
pushcount = pushcount+1
storage.set('pushcount', pushcount)
Hi mlaudren
thanks for your reply. I have written the code below but it is not working right. The code is working right at first time once, but when I change the temperature '5/3/0' manually, the Temp is not updated. Can you help?
local pushcount = storage.get('pushcount', 0)
local timepush = os.time()
local timepushinit = storage.get('lastpush', 0)
--Temp=grp.getvalue('5/3/0')
--storage.set('Temp',Temp)
local Temp = storage.get('Temp',0)
delta = timepush - timepushinit
grp.write('11/4/1',delta)
--grp.write('11/4/4',ActualTemp)
if delta > 15 then
pushcount = 0
storage.set('lastpush', timepush)
end
if pushcount == 0 then
ActualTemp=grp.getvalue('5/3/0')
storage.set('Temp', ActualTemp)
Temp=Temp+0.5
storage.set('Temp', Temp)
grp.write('11/4/3',Temp)
else
ActualTemp=grp.getvalue('5/3/0')
storage.set('Temp', ActualTemp)
Temp=Temp
storage.set('Temp', Temp)
grp.write('11/4/3',Temp)
end
pushcount = pushcount+1
storage.set('pushcount', pushcount)
--storage.set('Temp', Temp)
grp.write('11/4/2',pushcount)
--grp.write('11/4/3',Temp)