LogicMachine Forum
Operating hours counter - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Operating hours counter (/showthread.php?tid=2336)



Operating hours counter - hummelsystemhaus - 11.11.2019

Hey guys,

we want to create an operating hour counter for a Boolean address, does anyone have a finished script?

Thank you


RE: Operating hours counter - Daniel - 11.11.2019

Function from FB Editor
Code:
function fbe_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