How to use Eascheduler?

Hi, me again, trying to work out how to use your class Eascheduler outside the HABApp.Rule, but does not get it right. My attempt yields ‘RuntimeError: no running event loop’. What am I missing?

from eascheduler.executors import AsyncExecutor
from eascheduler.schedulers import AsyncScheduler
from eascheduler import SchedulerView
from datetime import timedelta, datetime

class ScheduleTest:

    def __init__(self):
        self.scheduler_view = SchedulerView(scheduler=AsyncScheduler(), executor=AsyncExecutor)
        print('init A')
        self.repeat_job = self.scheduler_view.every(, interval=timedelta(seconds=5), callback=self.do_something())
        print('init B')

    def do_something(self):
        print(f'Current time: {}')




[2023-01-07 12:44:09,268] [             HABApp.Rules]    ERROR |   File "C:\_HG\PN_AUTOMATION\CODING\Python\habapp_test_env\rules\dev\", line 12, in __init__
[2023-01-07 12:44:09,268] [             HABApp.Rules]    ERROR |     self.repeat_job = self.scheduler_view.every(, interval=timedelta(seconds=5), callback=self.do_something())
[2023-01-07 12:44:09,269] [             HABApp.Rules]    ERROR |   File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\eascheduler\", line 60, in every
[2023-01-07 12:44:09,269] [             HABApp.Rules]    ERROR |     job._schedule_first_run(start_time)
[2023-01-07 12:44:09,269] [             HABApp.Rules]    ERROR |   File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\eascheduler\jobs\", line 46, in _schedule_first_run
[2023-01-07 12:44:09,269] [             HABApp.Rules]    ERROR |     self._set_next_run(self._next_run_base)
[2023-01-07 12:44:09,269] [             HABApp.Rules]    ERROR |   File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\eascheduler\jobs\", line 48, in _set_next_run
[2023-01-07 12:44:09,269] [             HABApp.Rules]    ERROR |     self._parent.add_job(self)
[2023-01-07 12:44:09,270] [             HABApp.Rules]    ERROR |   File "C:\Users\perno\PycharmProjects\HABApp\venv\lib\site-packages\eascheduler\schedulers\", line 53, in add_job
[2023-01-07 12:44:09,270] [             HABApp.Rules]    ERROR |     self.worker = create_task(self._run_next())
[2023-01-07 12:44:09,270] [             HABApp.Rules]    ERROR |   File "C:\Users\perno\AppData\Local\Programs\Python\Python310\lib\asyncio\", line 336, in create_task
[2023-01-07 12:44:09,270] [             HABApp.Rules]    ERROR |     loop = events.get_running_loop()
[2023-01-07 12:44:09,270] [             HABApp.Rules]    ERROR | RuntimeError: no running event loop

It makes no sense to use it outside of rule in the HABApp context.
The smallest object is a rule, there is no benefit in not using it.

Ok, thanks. I feel sometimes using the Rule for smaller tasks is overqualified.

For me I like to think of the Rule as the “automation part” where you define your logic. The specific use-case for the eascheduler in this case was a sub-class for a 1 channel double-click detection (implement the wait-time before evaluating incoming sequence as a countdown-job). Do you see an alternative to the HABApp.rule in this case?

So basically I’m looking for a way to organize the Rules/code hierarchy and distinguish/hide “util/devices”-logics from the “automation”-rules logics.

Its not supercritical in any way, if its not possible/practical then I just use the Rule.

Why not put the utilities in a sub folder?