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.

Alarm "clock"
#1
I´ve tried finding a solution for setting an alarm time to i.e. progressively increase the value of a light in a period of time.

Having difficulties wrapping my head around the os.time/os.date function.

Has anyone done something similar with a working solution?
Reply
#2
See this thread: https://forum.logicmachine.net/showthread.php?tid=718
Reply
#3
Thank you for the reply.

The reason I mentioned os.time/os.date is because i dont have a set schedule. This means I´m not interested in waking up at the same time every day of the week (some things can not be automated easily). I want to set a time in visu that then will trigger the wake up light 30 mins before that time.
Reply
#4
1/1/1 = time object
1/1/2 = output object

delta / 10 controls how smooth the transition is, 10 means 10 * 100 seconds to get from 0% to 100%.

Note that this will not work correctly if alarm is set very close to after midnight.

This can either be a resident or a scheduled script, depending how long the final transition is.

Code:
function getoffset(t)
  return t.hour * 3600 + t.min * 60 + t.sec
end

now = os.date('*t')
now = getoffset(now)

set = grp.getvalue('1/1/1')
set = getoffset(set)

if now <= set then
  delta = set - now
  val = math.floor(100 - delta / 10)
  if val > 0 then
    grp.write('1/1/2', val)
  end
end
Reply
#5
This is fantastic.

A question on the side; the time object, is it a 3-Byte object? How do you write the correct values to this in a script?
Reply
#6
Yes, 3 bytes with type time/day
Reply


Forum Jump: