Logic Machine Forum
Scheduler read - 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: Scheduler read (/showthread.php?tid=4367)



Scheduler read - toujour - 09.11.2022

Hi,

how can I read the time table of a schedule to activate an external function some times before ?
( if there is a time to turn on a light al 10.00 o'clock I 'd like activating the termostate 30' before of it )

BR,
Alberto


RE: Scheduler read - CristianAgata - 09.11.2022

(09.11.2022, 16:28)toujour Wrote: Hi,

how can I read the time table of a schedule to activate an external function some times before ?
( if there is a time to turn on a light al 10.00 o'clock I 'd like activating the termostate 30' before of it )

BR,
Alberto

Hi Alberto,
Take a look at this, maybe it can help you.
https://forum.logicmachine.net/showthread.php?tid=2899&highlight=Scheduled.time
Best regards Cristian


RE: Scheduler read - admin - 10.11.2022

Create a scheduled script that runs every minute. Make sure that the event you want to check has a unique name.
Code:
now = os.date('*t')
now_mins = now.hour * 60 + now.min

name = 'unique event name'
evt = db:getrow('SELECT * FROM scheduler_events WHERE name=?', name)

if evt then
  evt_mins = evt.start_hour * 60 + evt.start_min
  delta = evt_mins - now_mins

  if delta == 30 then
    -- 30 minutes before the event
    -- do something here
  end
else
  alert('event not found')
end