Page 2 of 3
Re: eg.scheduler
Posted: Sun Aug 10, 2014 8:05 am
by Sem;colon
TRIROG1 wrote:
I read in the manual that the eg.scheduler.AddTask should return an object, that you can use as the task identifier for CancelTask() - but i dont know how or where to get it ... the eventlog is empty?
Yes, it returns an object, but it doesn't trigger an event at default - you can store the returned value in a variable:
Code: Select all
eg.globals.mySchedulerObject = eg.scheduler.AddTask(10.0, eg.TriggerEvent, "MyEvent")
After that you can do a:
Code: Select all
eg.scheduler.CancelTask(eg.globals.mySchedulerObject)
to cancel the schedule.
Re: eg.scheduler
Posted: Sun Aug 10, 2014 9:17 am
by TRIROG1
Sem;colon wrote:
Yes, it returns an object, but it doesn't trigger an event at default - you can store the returned value in a variable:
Code: Select all
eg.globals.mySchedulerObject = eg.scheduler.AddTask(10.0, eg.TriggerEvent, "MyEvent")
After that you can do a:
Code: Select all
eg.scheduler.CancelTask(eg.globals.mySchedulerObject)
to cancel the schedule.
Hi
Thanks for quick reply but where exactly in my script should i put this ?
Code: Select all
eg.globals.ResetTimerObject = eg.scheduler.AddTask(10, ResetTimer)
Do i put it berofe the last line (eg.scheduler.AddTask(10, ResetTimer))
Thx
Re: eg.scheduler
Posted: Sun Aug 10, 2014 9:26 am
by TRIROG1
Never mind figured it out ... I think...
Didn't know i could start the "timer" with
Code: Select all
eg.globals.ResetTimerObj = eg.scheduler.AddTask(10, ResetTimer)
This is correct right?
Here is the changed code
Code: Select all
import urllib
if not "Shutters_movie_timeout" in eg.globals.__dict__:
eg.globals.Shutters_movie_timeout = 0
if not "Shutters_movie_mode" in eg.globals.__dict__:
eg.globals.Shutters_movie_mode = 0
def ResetTimer():
print 'Timer expired-setting movie mode to 0'
eg.globals.Shutters_movie_timeout = 0
eg.globals.Shutters_movie_mode = 0
if eg.globals.Shutters_movie_timeout == 1:
if eg.globals.Shutters_movie_mode == 1:
print "Movie mode OFF"
#urllib.urlopen('http://192.168.0.240:8080/movieoff')
eg.globals.Shutters_movie_mode = 0
eg.scheduler.CancelTask(eg.globals.ResetTimerObj)
else:
print "Doing nothing - Movie mode OFF"
eg.scheduler.CancelTask(eg.globals.ResetTimerObj)
eg.globals.Shutters_movie_timeout = 0
else:
print 'Setting eg.globals.Shutters_movie_timeout to 1 and starting timer...'
eg.globals.Shutters_movie_timeout = 1
eg.globals.ResetTimerObj = eg.scheduler.AddTask(10, ResetTimer)
Re: eg.scheduler
Posted: Sun Aug 10, 2014 3:31 pm
by Sem;colon
Yes
Re: eg.scheduler
Posted: Mon Aug 11, 2014 5:49 pm
by TRIROG1
Thanks!
this might seem like an odd question (perhaps not considering it's comming from a newb) but i just need a confirmation:
for smaller timings in the script i should use eg.scheduler.AddTask instead of eg.plugins.EventGhost.Wait since the scheduler runs in background and Wiat pauses the whole script right?
whereas using schedulghost eggtimer in a script wont matter since i will need another macro with an event assigned to it to run ...
Also are smaller timers / timings like up to 300 seconds (5 min) safe to preform with the eg.scheduler.AddTask or is another method recommended?
Can i run multiple eg.scheduler.AddTask at the same time?
Thanks for your time

Re: eg.scheduler
Posted: Mon Aug 11, 2014 7:03 pm
by krambriw
for smaller timings in the script i should use eg.scheduler.AddTask instead of eg.plugins.EventGhost.Wait since the scheduler runs in background and Wiat pauses the whole script right?
Correct, the 'Wait' is actually pausing the whole EG (except for tasks running in separate threads). I always use eg.scheduler if possible and in threads, I use to set the threads in wait state if I need that.
using schedulghost eggtimer in a script wont matter since i will need another macro with an event assigned to it to run ...
Pako knows this for sure but I assume that SchedulGhost plugin is in fact using eg.scheduler
Also are smaller timers / timings like up to 300 seconds (5 min) safe to preform with the eg.scheduler.AddTask or is another method recommended?
Sure, it is safe, I have executed much longer (and shorter) schedules successfully. However, if you restart EG while schedules are running, they will not continue where they stopped, there is no persistence remembering this.
Can i run multiple eg.scheduler.AddTask at the same time?
Yes, if you use the latest version or add a fix Pako made lately and described in the first post in this thread, scheduled tasks will run in parallel.
BR Walter
Re: eg.scheduler
Posted: Mon Aug 11, 2014 9:53 pm
by TRIROG1
krambriw wrote:
Can i run multiple eg.scheduler.AddTask at the same time?
Yes, if you use the latest version or add a fix Pako made lately and described in the first post in this thread, scheduled tasks will run in parallel.
BR Walter
Is that the fix posted in the first post that you have in mind?
Re: eg.scheduler
Posted: Tue Aug 12, 2014 4:13 am
by krambriw
Yes, unless you are already running version 1669, you need to apply the fix manually
Re: eg.scheduler
Posted: Wed Aug 13, 2014 8:35 pm
by TRIROG1
bee messing around witht he scheduler lately ...
what i'm trying to accomplish is to gradually open a shutter in the bedroom ... this i the code i'm playing with but there seems to be something wrong ...
Code: Select all
import urllib
def VentModeDS():
import urllib
print 'Stopping'
urllib.urlopen('http://192.168.0.240:8080/dss')
eg.globals.VentModeDS = 1
eg.scheduler.AddTask(5, OpenGrad)
def OpenGrad():
import urllib
print 'Opening all the way gradually '
urllib.urlopen('http://192.168.0.240:8080/dsu')
eg.globals.VentModeDS = 0
eg.scheduler.AddTask(5, Stop)
def Stop():
import urllib
print 'Stopping'
urllib.urlopen('http://192.168.0.240:8080/dss')
if not "OpenGradRuns" in eg.globals.__dict__:
eg.globals.OpenGradRuns = 0
eg.globals.OpenGradRuns =+1
print eg.globals.OpenGradRuns
if eg.globals.OpenGradRuns < 3:
eg.scheduler.AddTask(5, OpenGrad)
urllib.urlopen('http://192.168.0.240:8080/dsu')
eg.globals.ShutterTimerObj = eg.scheduler.AddTask(5, VentModeDS)
It works just fine up until the OpenGrad function ... I'm sure its just a stupid error since i have no background in programming ...
Code: Select all
22:26:54 Python Script
22:27:00 Stopping
22:27:05 Traceback (most recent call last) (1640):
22:27:05 File "C:\Program Files (x86)\EventGhost\eg\Classes\Scheduler.py", line 137, in MainLoop
22:27:05 func(*args, **kwargs)
22:27:05 TypeError: 'NoneType' object is not callable
Could anyone help please?
Re: eg.scheduler
Posted: Thu Aug 14, 2014 6:15 am
by krambriw
The samples below run ok in my tests (just commented out the url calls). In general, I would try to avoid 'eg.globals' variables unless you have a very specific reason to use them.
As in the first sample below (my choice) you bring the variables with you in the function calls as parameters. The second sample is also working fine but uses global variables.
Code: Select all
def VentModeDS(VModeDS, OpenGradRuns):
print 'Stopping'
#urllib.urlopen('http://192.168.0.240:8080/dss')
VModeDS = 1
eg.scheduler.AddTask(5, OpenGrad, VModeDS, OpenGradRuns)
def OpenGrad(VModeDS, OpenGradRuns):
print 'Opening all the way gradually '
#urllib.urlopen('http://192.168.0.240:8080/dsu')
VModeDS = 0
eg.scheduler.AddTask(5, Stop, VModeDS, OpenGradRuns)
def Stop(VModeDS, OpenGradRuns):
print 'Stopping'
#urllib.urlopen('http://192.168.0.240:8080/dss')
OpenGradRuns += 1
print OpenGradRuns
if OpenGradRuns < 3:
eg.scheduler.AddTask(5, OpenGrad, VModeDS, OpenGradRuns)
#Execution starts here
import urllib
OpenGradRuns = 0
VModeDS = 0
#urllib.urlopen('http://192.168.0.240:8080/dsu')
ShutterTimerObj = eg.scheduler.AddTask(5, VentModeDS, VModeDS, OpenGradRuns)
Code: Select all
def VentModeDS():
global VModeDS
print 'Stopping'
#urllib.urlopen('http://192.168.0.240:8080/dss')
VModeDS = 1
eg.scheduler.AddTask(5, OpenGrad)
def OpenGrad():
global VModeDS
print 'Opening all the way gradually '
#urllib.urlopen('http://192.168.0.240:8080/dsu')
VModeDS = 0
eg.scheduler.AddTask(5, Stop)
def Stop():
global OpenGradRuns
print 'Stopping'
#urllib.urlopen('http://192.168.0.240:8080/dss')
OpenGradRuns += 1
print OpenGradRuns
if OpenGradRuns < 3:
eg.scheduler.AddTask(5, OpenGrad)
#Execution starts here
import urllib
OpenGradRuns = 0
VModeDS = 0
#urllib.urlopen('http://192.168.0.240:8080/dsu')
ShutterTimerObj = eg.scheduler.AddTask(5, VentModeDS)
Re: eg.scheduler
Posted: Thu Aug 14, 2014 7:07 am
by TRIROG1
Hi Walter! Thanks for the help!
I'm using the eg.globals variables because i understood that these are the variables are accessible between different scripts e.g. i can sheck if the VentMode is activated on a certain shutter from another python script...or did i misunderstand?
well perhaps there is really no need to put OpenGradRuns in the global dict - will correct that
Is using the command
global VariableName
the same as
eg.globals.VariableName
can i also use global VariableName to get value of that variable or is it just for declaring?
Can you please explain why did you add all the bolded text below to the AddTask and the function definition command? What does it do?
ShutterTimerObj = eg.scheduler.AddTask(5, VentModeDS, VModeDS, OpenGradRuns)
def VentModeDS(VModeDS, OpenGradRuns):
Re: eg.scheduler
Posted: Thu Aug 14, 2014 7:52 am
by TRIROG1
Hi again ... just ran the script but it doesnt seem to be working ... it stops after the function VendModeDS ends.
Seems like the eg.scheduler.AddTask(5, OpenGrad, VModeDS, OpenGradRuns) doesent call the OpenGrad function?
Here is the code:
Code: Select all
def VentModeDS(VModeDS, OpenGradRuns):
print 'Ventilation mode'
#urllib.urlopen('http://192.168.0.240:8080/dss')
VModeDS = 1
eg.scheduler.AddTask(5, OpenGrad, VModeDS, OpenGradRuns)
print 'Ventilation mode ended'
def OpenGrad(VModeDS, OpenGradRuns):
print 'Opening all the way gradually '
#urllib.urlopen('http://192.168.0.240:8080/dsu')
VModeDS = 0
eg.scheduler.AddTask(5, Stop, VModeDS, OpenGradRuns)
def Stop(VModeDS, OpenGradRuns):
print 'Stopping'
#urllib.urlopen('http://192.168.0.240:8080/dss')
OpenGradRuns += 1
print OpenGradRuns
if OpenGradRuns < 3:
eg.scheduler.AddTask(5, OpenGrad, VModeDS, OpenGradRuns)
#Execution starts here
print "Starting..."
import urllib
OpenGradRuns = 0
print OpenGradRuns
VModeDS = 0
print VModeDS
#urllib.urlopen('http://192.168.0.240:8080/dsu')
eg.scheduler.AddTask(5, VentModeDS, VModeDS, OpenGradRuns)
And the log file it generates:
Code: Select all
09:49:38 Python Script - wk
09:49:38 Starting...
09:49:38 0
09:49:38 0
09:49:43 Ventilation mode
09:49:43 Ventilation mode ended
Nothing else ...
Re: eg.scheduler
Posted: Thu Aug 14, 2014 8:07 am
by krambriw
I'm using the eg.globals variables because i understood that these are the variables are accessible between different scripts e.g. i can sheck if the VentMode is activated on a certain shutter from another python script...or did i misunderstand?
well perhaps there is really no need to put OpenGradRuns in the global dict - will correct that
OK, fine, then you should use eg.globals. Variables declared as such are globally accessible in EG
Is using the command
global VariableName
the same as
eg.globals.VariableName
Is not the same, global VariableName is global inside the running script so to say, eg.globals.VariableName is global in EG, also from different scripts.
eg.globals.VariableName stays 'alive' until EG is closed or they are del(eted) on purpose
global VariableName is only 'alive' while your script/code is running
can i also use global VariableName to get value of that variable or is it just for declaring?
This is for 'telling' python that the globally declared variable shall be used instead of creating a new local one
Can you please explain why did you add all the bolded text below to the AddTask and the function definition command? What does it do?
ShutterTimerObj = eg.scheduler.AddTask(5, VentModeDS, VModeDS, OpenGradRuns)
def VentModeDS(VModeDS, OpenGradRuns):
This is when it is needed to send parameters when calling a function. The def VentModeDS(VModeDS, OpenGradRuns): specifies that the function requires two parameters, the eg.scheduler.AddTask(5, VentModeDS, VModeDS, OpenGradRuns) schedules the function to run with the required parameters in 5 seconds.
Re: eg.scheduler
Posted: Thu Aug 14, 2014 8:14 am
by krambriw
Your script runs fine in my environment
Code: Select all
10:11:02 Python Script
10:11:02 Starting...
10:11:02 0
10:11:02 0
10:11:07 Ventilation mode
10:11:07 Ventilation mode ended
10:11:12 Opening all the way gradually
10:11:17 Stopping
10:11:17 1
10:11:22 Opening all the way gradually
10:11:27 Stopping
10:11:27 2
10:11:32 Opening all the way gradually
10:11:37 Stopping
10:11:37 3
Re: eg.scheduler
Posted: Thu Aug 14, 2014 10:28 am
by TRIROG1
Works here too ... Funny thing
But if a make any alterations and press the Test button it will stop at the " Ventilation mode ended".
But if i press ok and then reopen the script and click Test it works normally ... bug in EG?