Migrating my rules to Jython

Wherever the workspace file is located… probably at the root of openhab-conf.

Placing it in the root of openhab-conf doesn’t help. I will try to find out where it will work.

This is where mine is located…

I remember getting it setup at first was tricky. I think restarting VSC helped, but I also enabled/disabled the linter.

I managed to get it working. Placing in the conf folder is right.
However after a restart VSCODE said that there is a pylint file, should pylint be enabled or something like this. But after pressing Yes, the same happened.
Opening the command palette and selecting Python Linter as pylint helped.

However if you can specify what should be turned off… Can it be somehow enabled (I mean specifying these in the pylintrc file) to auto-complete these default variables? Like you said items, and ir, events, etc… are in the default scope so it will be always available, so only a static list of these variables would be enough and really could help in the migration process, especially in typos…

I have saved this rule in the personal folder, but when it should trigger nothing happens. I suspect that I least should see the logging in the openhab.log but not. Even saving the file doesn’t give any output. Should it give something similar to Rules DSL when saving a file?

Yes… I had spent some time refining this and have had a commit that I’ve been testing since early November that needs to be pushed… similar to what you see in the PR that Michael submitted.

Read through the setup instructions again. You probably did not set the logging level for jsr223. Out of curiousity, did you manually install jython or are you trying out the bundle?

I don’t think so. When restarting openHAB I can see that the initial scripts (“StartupTrigger.py”) is loading. I suspect the same should happen when I save a file but not. A restart is required when saving a new file?

Nope. What do you see when you execute this in the console?


Logger                                             │ Level
ROOT                                               │ WARN
javax.jmdns                                        │ ERROR
javax.mail                                         │ ERROR
org.apache.karaf.jaas.modules.audit                │ INFO
org.apache.karaf.kar.internal.KarServiceImpl       │ ERROR
org.apache.karaf.shell.ssh.SshUtils                │ ERROR
org.apache.karaf.shell.support                     │ OFF
org.eclipse.lsp4j                                  │ OFF
org.eclipse.smarthome                              │ INFO
org.jupnp                                          │ ERROR
org.openhab                                        │ INFO
org.openhab.ui.paper                               │ WARN
org.openhab.ui.paper.internal                      │ INFO
org.ops4j.pax.url.mvn.internal.AetherBasedResolver │ ERROR
org.ops4j.pax.web.pax-web-runtime                  │ OFF
smarthome.event                                    │ INFO
smarthome.event.InboxUpdatedEvent                  │ ERROR
smarthome.event.ItemAddedEvent                     │ ERROR
smarthome.event.ItemRemovedEvent                   │ ERROR
smarthome.event.ItemStateEvent                     │ ERROR
smarthome.event.ThingAddedEvent                    │ ERROR
smarthome.event.ThingRemovedEvent                  │ ERROR
smarthome.event.ThingStatusInfoEvent               │ ERROR

Ok, I know what the problem is now.
It worked before, but yesterday I have updated to 2.5 stable and changed to release through openhabian-config. That replaced the /etc/default/openhab2 file to the default one, so there is no extra Java opts there.

Your org.ops4j.pax.logging.cfg file was probably wiped during the upgrade. Set the logging level again for jsr223…

log:set DEBUG jsr223

If you do not have an EXTRA_JAVA_OPTS, Jython would not work. Unless you are using the Jython bundle…

Ok, thanks I will try!

I have added the extra JAVA_OPTS again, I will retry after a restart!

How can I specify the used Persistance service when calling the previousState?

I can only find this example in the docs:

PersistenceExtensions.previousState(ir.getItem(“Weather_SolarRadiation”), True).state

I want to transfer this to Python:

ArmCurrState.previousState(false, “mapdb”) != NULL



from core.actions import PersistenceExtensions

if PersistenceExtensions.previousState(ir.getItem("ArmCurrState"), False, "mapdb").state != NULL:

But this would never be true, since NULL is never persisted.

But I need the previousState not the time when changed.
And I need to use mapDB and mapDB is not the default Persistance service for me, that’s why I have to specify there to use that one.
What is the “True” in the previousState call?

What you might be looking for is…

if event.oldItemState != NULL:

Thanks really! I saw it earlier…
But that will use which persistance service?

Persistence is not being used here… the event provides the previous state to the rule engine. What is available depends on the event type. I’ve documented these here as event object attributes…


Thanks that makes sense, and when I started to use these in Rules DSL I also thought that no persistance is needed here, but DSL worked differently…

The implicit variables available in the DSL are the same type of thing… no persistence needed for them either.

So, how is the migration going?