30.11.2021, 15:47
I'm not sure where you heading here but each object has its update time saved and you can use this instead os.time.
input = grp.find('1/1/1')
start = input.updatetime
This will give you time in numeric format. You can save on and off value in a storage and compare. Here is example of counter from FB Editor, It might help.
input = grp.find('1/1/1')
start = input.updatetime
This will give you time in numeric format. You can save on and off value in a storage and compare. Here is example of counter from FB Editor, It might help.
Code:
function operating_hours(input, reset, blockID)
local inputValue = input.value and input.value ~= 0
if reset and reset ~= 0 then
if inputValue then
storage.set(blockID .. "_start", os.time())
end
return inputValue and 0 or nil
elseif inputValue then
local start = storage.get(blockID .. "_start")
if start == nil then
start = input.updatetime
storage.set(blockID .. "_start", start)
end
return (os.time() - start) / 3600
else
storage.delete(blockID .. "_start")
return nil
end
end
input = grp.find('1/1/1')
reset = grp.getvalue('1/1/4')
blockID= _SCRIPTNAME
hours = operating_hours(input, reset, blockID)
log(hours)
if hours ~= nil then
grp.write('1/1/2', hours)
end
------------------------------
Ctrl+F5
Ctrl+F5