Ap scheduler

https://apscheduler.readthedocs.io/en/stable/index.html
I started defining rules (like a beginner :slight_smile:) in JYTHON.
I succeeded to start a rule at sunset. Then I wanted a rule to start at a time “to be defined” in a virtual Item in the sitemap. So, couldn’t use CRON, because you can’t use uit with variables. I searched for a solution… got different examples… but they didn’t fully satisfy me.
At last,I stumbled on APSCHEDULER. It’s a Python library.
Well, although I’m a programming for a living, I don’t know java,python or Jython…
Just trying to learn Jython(python) now, so I can define rules.
I didn’t install APSCHEDULER yet. I first want to know:
is it possibile to install it in OPENAB 2.5 ?
is is possible to use it in Jython (I guess it is)
Someone has already used this library?

thx!
ps: maybe an interesting library to add to OH 3.0 ? Since, rules will rely more and more on Jython and a descent scheduler comes in handy?

You can program to create a rule and thus use variables to create that cron rule. The rule to create this rule should trigger on the item change. I have no concrete example for you. But adding a library for something that should also be possible to do with the current functionality seems looking in the wrong direction.

This seems a misconception. Rules don’t reply more and more on Jython. Rules rely on the script engine that supports among others Jython, but also JavaScript. So any support in openHAB itself should never rely on a single language run on the script engine. That doesn’t mean you shouldn’t use it, but there is also the risk people familiar with a specific language will try to solve it in that language because the script engine is powerful and allows them to do so. This is actual the biggest risk that we’ll see a lot of solutions in the rules that are either language specific or reinventing the wheel.

Assuming it can be used with Python 2.7 than yes to the first two. But likely no to the last question because there is no need. OH already has all the capabilities that APScheduler provides:

For a relatively extensive example of “start at a time defined in a virtual Item” see Initial check in for Ephemeris Time of Day by rkoshak · Pull Request #282 · openhab-scripters/openhab-helper-libraries · GitHub which is an implementation of the Time of Day DP that uses Ephemeris. The whole code is driven by Timers set based on the state from DateTime Items.

This is incorrect. You can create a rule with a cron trigger based on an Item’s state, but you’ll need another rule to delete that rule and recreate it when the Item changes value. Here is an example…

As for apscheduler, it is reported as compatible w/ 2.7, but I agree with Rich that it is not needed.

Python libraries are not a part of OH. A scheduler is more appropriate in openHAB core, so I will not include this in the core Jython helper libraries. However, you are welcome to submit something to the Community section!

thx
The “dynamic set days and time for rules…” looks promising.

about the misconception:
Directions for openHAB 3 …
“The NG rule engine should be the only one - existing Xbase-rules should be supported by it as well and the Jython-rules should be made a first class citizen.”
This is what i meant…