Design Pattern - Timer Management

That’s why I haven’t done it yet myself. :wink:

It’s important to remember that almost everything to do with a Timer is working with Java classes. Therefore, with some minor adjustments to account for different syntax in the various languages, creating and interacting with a Timer is going to be the same. They are all working with the same Java Timer and ZonedDateTime class.

Therefore, you should be able to use a JavaScript example for creating a Timer or a Rules DSL example for creating a Timer and, with some minor changes to account for differences in the language, it will work the same.

In Python’s case you need to import ScriptExecution and java.time.ZonedDateTime instead of Joda DateTime. Then call ScriptExecution.createTimer passing a ZonedDateTime Object as the time to run the Timer instead of a Joda DateTime.

To get by you could just simply remove the Joda DateTime stuff from time_utils.py which will break OH 2.5 support but you don’t need 2.5 support. See DateTime Conversion (openHAB 3.x). Even though that’s all Rules DSL, because it’s talking about the same Java Objects and Classes you should be able to translate that to Python relatively easily. Some of the examples there will work line for line.