I always had the statement
postUpdate(Martin_home_time, new DateTimeType())
to store the moment something has happend.
How would this be translated in Jython?
In Python, you don’t need the
new keyword to create an instance of a Python or Java type. You can do the update with
And maybe a second question:
How am I canceling a timer?
You’ll need to save a reference to the timer somewhere. Usually, an attribute of your rule instance is a good choice. For example…
self.mytimer = oh.createTimer(expire_time, self.handle_timer)
In general I am struggling quite a bit with the lack of documentation and examples
I agree. Like most of openHAB the documentation is rather sparse. I assume you’ve been looking at the documentation on the wiki.
The syntax to interact with the specific openhab classes therefore is not clear for me. For example, > is it possible to create a trigger that triggers if a certain state is reached.
the equivalent to
Item Presence_Martin_big changed to OFF
ChangedEventTrigger class has three constructor arguments, the first is the item name, the second is the “from” state and the third is the “to” state. It also can take just the item name and then it will trigger on every change (but updates to the same value won’t trigger it). It’s important to pay attention to the argument types that have been declared in the openHAB Java code. For example, this would not work…
ChangedEventTrigger("Switch", "OFF", "ON")
since the second and third argument must be state objects. You’d need to use…
ChangedEventTrigger("Switch", OnOffType.OFF, OnOffType.ON)
instead. If you are using the OnOffType enums frequently in a rule file, you might want to simplify the syntax a bit by putting the following code near the top of your rule file.
OFF = OnOffType.OFF ON = OnOffType.ON
Then you can define the trigger with
ChangedEventTrigger("Switch", OFF, ON)
If you don’t care about one of the states in the trigger, you can use the Python None value for it (the same as null in Java). For example,
ChangedEventTrigger("Switch", None, ON)
Could you provide a link to the github of the source?
Maybe I will find some questions to my answers there.
Because of the transition between OH1 (1.8.x) and OH2 (1.9.x), you must be one the 1.8 branch of the openhab git repository since the code is not on the master branch. On the web, you can see it at…
Keep in mind that Jython is mostly Python but there is a learning curve when interacting with Java code. A good resource for Jython-specific topics is…