Logic Machine Forum
Alarm "clock" - Printable Version

+- Logic Machine 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: Alarm "clock" (/showthread.php?tid=969)



Alarm "clock" - FatMax - 29.08.2017

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?


RE: Alarm "clock" - admin - 29.08.2017

See this thread: https://forum.logicmachine.net/showthread.php?tid=718


RE: Alarm "clock" - FatMax - 29.08.2017

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.


RE: Alarm "clock" - admin - 29.08.2017

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



RE: Alarm "clock" - FatMax - 29.08.2017

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?


RE: Alarm "clock" - admin - 29.08.2017

Yes, 3 bytes with type time/day