30.11.2021, 12:56
(This post was last modified: 30.11.2021, 13:17 by sivlecrash.)
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
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