[OH3] Moving from DSL rules to python or javascript

  • Platform information:
    • Hardware: RPi 3
    • OS: opehabian 1.62b
    • openHAB version: 3.0

Hi there,

I have migrated to OH3 from 2.x and loaded all my DSL rules as script actions within the UI. It seems to become unresponsive after some time to the point that OH crashes. Looking around it appears others have has similar experiences with high CPU ect.

In the short term I have disabled all my rules with DSL scripts in the THEN area of the UI. This seems to have stabilised my OH instance successfully.

As maybe at the moment adding DSL parts of rules can cause problems via the UI, I would like to transition all my DSL rules to python or javascript and add them back in as scripts.

I don’t have very complex needs. Just some if X & Y items are ON then do A and log it Else do B and log it. I would like to learn how to implement timers as well.

  • Does anyone have any script examples I could change to suit? Either languages is fine.
  • To help me learn a little could anyone point me in the right direction for starters in the languages.

I am not a programmer I just really wish to write some rules in the format that can drop into the script part of OH. I got my DSL rules from just modifying others work here in the community.


I’m not sure how you mean “in the THEN area of the UI”. Did you remove the Script Actions? Do you really mean that you added a but only if… condition to block the rule? Or did you click the || pause icon at the top of the Rule?

A lot of the more simple rules don’t even need code. See [wiki] Getting Started with OH3: rewriting the tutorial - 8. Rules (will become a part of the Getting Started Tutorial soon I hope.

There are a number of JavaScript examples for doing some things in Experimental Next-Gen Rules Engine Documentation 4 of : Writing Scripts (follow the links at the bottom to the Actions page too which will show how to create a Timer). Keep in mind I wrote that years ago now and there might be some things that are not quite current at this time. For example, Anytime you see DateTime you need a ZonedDateTime instead.

There are some more JavaScript examples of some more advanced rules at OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules.

There are tons of Python examples on the forum including in all of the Design Pattern posts. However, those are all written from the perspective of writing rules in .py files and not through the UI and using the Helper Libraries. But they still work as piece part examples for how to do things like creating Timers and such. At some point soon hopefully the helper libraries will be available as an add-on so those examples will become more relevant.

I was having the same issues with DSL rules created through the UI and then I saw this:

I converted all my scripts to Javascript and have no issues anymore



Hi Rich,

Thanks for replying.

When moving from 2.x to 3.0 I decided to try to use the UI as much as possible, the main UI is great and will really boost OH as a platform.
To recreate my rules I added the triggers to the ‘When’ area and thought it was ok to add the part of my existing rules as a DSL script to the ‘Then’ area. From my experience this has caused my instance to work initially however over several hours become unresponsive and eventually crash.
I have around 6 or so rules triggering when various people enter/leave locations, turning on/off stuff and sending notifications.
To get my instance stable I disabled the rules, by pressing pause. For nearly two days now my instance has been running smoothly, no errors ect.

Thanks for the links, I will have a good look over and go from there.

Kind Regards,

Hi Tom,

Perfect, thanks for your ‘spam’ :wink:, that template will be a great help.

Much appreciated.

Kid Regards,