Scheduler-API

There are two ways to access the API

  1. Directly

    Use it the following way to access the api, if you have no access to the sh object in your method or function:

    # to get access to the object instance:
    from lib.scheduler import Scheduler
    scheduler = Scheduler.get_instance()
    
    # to access a method (eg. to trigger a logic):
    scheduler.trigger(...)
    
  2. Through the main SmartHome object

    If you have access to the sh object in your method or function, you can use the following way:

    # to access a method (eg. to trigger a logic):
    sh.scheduler.trigger(...)
    

The API is implemented through the following library:

lib.scheduler

class lib.scheduler.Scheduler(smarthome)[source]

Bases: threading.Thread

static get_instance()[source]

Returns the instance of the scheduler class, to be used to access the scheduler-api

Use it the following way to access the api:

from lib.scheduler import Scheduler
scheduler = Scheduler.get_instance()

# to access a method (eg. to trigger a logic):
scheduler.trigger(...)
Returns:scheduler instance
Return type:object or None
run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

stop()[source]
trigger(name, obj=None, by='Logic', source=None, value=None, dest=None, prio=3, dt=None)[source]

triggers the execution of a logic optional at a certain datetime given with dt

Parameters:
  • name
  • obj
  • by
  • source
  • value
  • dest
  • prio
  • dt – a certain datetime
Returns:

always None

remove(name, from_smartplugin=False)[source]

Remove a scheduler entry with given name. If a call is made from a SmartPlugin with an instance configuration the instance name is added to the name to be able to distinguish scheduler entries from different instances

Parameters:
  • name – scheduler entry name to remove
  • from_smartplugin
check_caller(name, from_smartplugin=False)[source]

Checks the calling stack if the calling function (one of get, change, remove, trigger) itself was called by a smartplugin instance. If there is an instance name of the calling smartplugin then the instance name of that calling smartplugin is appended to the name

Parameters:
  • name – the name of a scheduler entry
  • from_smartplugin
Returns:

returns either the name or name combined with instance name

return_next(name)[source]
add(name, obj, prio=3, cron=None, cycle=None, value=None, offset=None, next=None, from_smartplugin=False)[source]

Adds an entry to the scheduler.

Parameters:
  • name
  • obj
  • prio – a priority with default of 3 having 1 as most important and higher numbes less important
  • cron – a crontab entry of type string or a list of entries
  • cycle – a time given as integer in seconds or a string with a time given in seconds and a value after an equal sign
  • value
  • offset – an optional offset for cycle. If not given, cycle start point will be varied between 10..15 seconds to prevent too many scheduler entries with the same starting times
  • next
  • from_smartplugin
get(name, from_smartplugin=False)[source]

takes a given name for a scheduler and returns either the matching scheduler or None

change(name, **kwargs)[source]