This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Operating hours, relay closing time..., comparison 3byte
#1
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
Reply


Messages In This Thread
Operating hours, relay closing time..., comparison 3byte - by sivlecrash - 30.11.2021, 12:56

Forum Jump: