Can I calculate Values without VS extenstion

Hi all,

I want to create a rule like this:
Can I do this in the Openhub gui also, or am I forced to use the VS plugin?


rule "iPhone Home"
    Item iPhone_Location changed
    // specify your home location
    val PointType home_location  = new PointType(new DecimalType(51.0), new DecimalType(4.0))
    val PointType phone_location = iPhone_Location.state as PointType
    val int distance = phone_location.distanceFrom(home_location).intValue()
    // specify your preferred radius (in meters)
    if ( distance < 200) {
        logInfo("iPhone Home", "iPhone is at home.")
    } else {
        logInfo("iPhone Home", "iPhone is away.")

If I understand correctly, you would like to add a rule using DSL (aka “the old openHAB2 way”?) instead of ECMAScript (aka “one of the rules-integrated scripting languages”)? :wink:

Yes, you can:

  1. create a new rule
  2. chose “Run Script” in “Add Action”
  3. chose “DSL” from the list of rule engines
  4. enjoy

1 Like


Thanks for the reply.
The issue here is I found this example in the documentation of OpenHAB.
For sure I can try to do it in another script.

But just to make sure. I need a script for this, right? I cannot click it :slight_smile:


Please check the steps I posted here:

This should bring you to the point, where you can paste the DSL script into the OH3 GUI, and you should be able to edit the DSL script itself.

If you come to an dead end, please describe what you were doing and we can help you from there

Thanks a lot I’ll give it a try

Do not copy-paste the whole of a “file” type DSL rule into a GUI entered rule’s script action.
The GUI takes care of all the when-then-end stuff and you only need the rule body.

1 Like

That’s correct - but one step at a time I guess! :wink:
if you copied all the “old” rule as a whole, you get the corresponding error-entries in the logs and can work from there! :wink:

I managed to it thanks to all!
The only thing that did initially was not clear to me is that
“The Rule can embed a script”.
I thought I have to create a script and link it.

This helped a lot