LogicMachine Forum
Operating hours, relay closing time..., comparison 3byte - 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, relay closing time..., comparison 3byte (/showthread.php?tid=3715)



Operating hours, relay closing time..., comparison 3byte - sivlecrash - 30.11.2021

Hello,
I have saved the on and off (time and date). Can you please advise me how to calculate the difference between "time_on, date_on" and "time_off, date_off" ?
Thank you


Code:
adr_relay_status     = '32/7/0'  --relay_status        --01 1bit adr_time_on         = '32/7/1'  --on time            --10 3byte time/day adr_date_on         = '32/7/2'  --on date            --11 3byte date adr_time_off         = '32/7/3'  --off time            --10 3byte time/day adr_date_off         = '32/7/4'  --off date            --11 3byte date adr_sum_days         = '32/7/5'  --sum days            --07 2byte unsigned integer adr_sum_hours         = '32/7/6'  --sum hours            --07 2byte unsigned integer adr_sum_minutes     = '32/7/7'  --sum minutes        --07 2byte unsigned integer adr_sum_seconds     = '32/7/8'  --sum seconds        --07 2byte unsigned integer relay_status     = grp.getvalue(adr_relay_status) if (relay_status == true) then   -- get current data as table   now = os.date('*t')   -- system week day starts from sunday, convert it to knx format   wday = now.wday == 1 and 7 or now.wday - 1   -- time table   time = {   day = wday,   hour = now.hour,   minute = now.min,   second = now.sec,   }   -- date table   date = {   day = now.day,   month = now.month,   year = now.year,   }   -- write to   grp.write(adr_time_on, time, dt.time)   grp.write(adr_date_on, date, dt.date) end if (relay_status == false) then   -- get current data as table   now = os.date('*t')   -- system week day starts from sunday, convert it to knx format   wday = now.wday == 1 and 7 or now.wday - 1   -- time table   time = {   day = wday,   hour = now.hour,   minute = now.min,   second = now.sec,   }   -- date table   date = {   day = now.day,   month = now.month,   year = now.year,   }   -- write to   grp.write(adr_time_off, time, dt.time)   grp.write(adr_date_off, date, dt.date)     time_on     = grp.getvalue(adr_time_on)   date_on     = grp.getvalue(adr_date_on)   time_off     = grp.getvalue(adr_time_off)   date_off     = grp.getvalue(adr_date_off)   sum_days     = grp.getvalue(adr_sum_days)   sum_hours     = grp.getvalue(adr_sum_hours)   sum_minutes     = grp.getvalue(adr_sum_minutes)   sum_seconds     = grp.getvalue(adr_sum_seconds)     --[[   script   calculation of the difference between the on and off time of the relay   addition to "sum_days" and  "sum_hours" and "sum_minutes" and "sum_seconds"   ]]--   days = 0 --?   hours = 0 --?   minutes = 0 --?   seconds = 0 --?     grp.write(adr_sum_days, days)   grp.write(adr_sum_hours, hours)   grp.write(adr_sum_minutes, minutes)   grp.write(adr_sum_seconds, seconds) end



RE: Operating hours, relay closing time..., comparison 3byte - Daniel - 30.11.2021

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.
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



RE: Operating hours, relay closing time..., comparison 3byte - sivlecrash - 01.12.2021

Thank you. I will try.