Openhab-designer help

I’m a former Vera Lite user and recently switched to OH on Pi as I was struggling with reliability issues with UI7. I’m struggling with the designer (win 7). It shows syntax errors for anything to do with time, except cron expressions such as

var DateTime quietNext = now.plusMinutes(90)

That actually appears to work, despite the designer showing it wrong. Others are actually wrong. But not knowing the language, it is making it very tedious to get my rules working. Also, in searches, I see screen shots showing pop up windows with what look like suggestions, which I don’t get.

At the moment, I’m trying to limit a rule to certain hours. Designer is showing it wrong and OH is choking on it.

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*
...
    rule "Occupied"
    	when
    		Item Garage_Door received update OPEN or
    		Item Aeon_Motion received update OPEN
    	then
    	if(new LocalTime.getLocalMillis >= new LocalTime.parse("5:30:00").getLocalMillis &&
    		new LocalTime.getLocalMillis <= new LocalTime.parse("20:30:00").getLocalMillis	)	 then {
    			sendCommand(occupied,ON)
    			quietNext = now.plusMinutes(occupiedDuration)
    			sendCommand(Fountain_DS, ON)
    		}
    	
    end

I’ve tried reloading the project and deleting my user settings folder (sorry, can’t recall the exact folder, but saw a thread that suggested this.)

Is this abuser error or is designer not behaving correctly? I believe I’m using 1.4 with OH 1.8.3. Any help appreciated.

thanks

I don’t know if LocalTime… should work, but I use this one:

if(now.plusMinutes(210).getMinuteOfDay > 540)

It’s a bit weird to explain it. The first step is, to add the number of minutes, remaining from upper limit to 12am, so 20:30:00 to 24:00:00 is 210 minutes.
The second step is, to check, if elapsed minutes then are above the lower limit (plus 210), lower limit is 05:30:00, so 330 Minutes past 00:00:00, plus 210 Minutes from the addition -> 540
getMinuteOfDay is always between 0 and 1439.
Certainly, you could also use

if(now.getMinuteOfDay > 330 && now.getMinuteOfDay < 1230)

:slight_smile:

That’s cleaver. Thanks.

What am I doing wrong here?

rule "test"
	when
		Item Occupied received update ON
	then
		if(now.plusMinutes(210).getMinuteOfDay > 540) {
			LogInfo("FILE","Test")
		}
end

the “if” line produces these errors.

Multiple markers at this line

  • Couldn’t resolve reference to JvmIdentifiableElement ‘>’.
  • Couldn’t resolve reference to JvmIdentifiableElement ‘plusMinutes’.
  • Couldn’t resolve reference to JvmIdentifiableElement ‘getMinuteOfDay’.
  • Couldn’t resolve reference to JvmIdentifiableElement ‘now’.

Thanks

If you hover your mouse over an underlined bit of text, or the red circle with the X to the left of the line it will pop-up the error.

If you start typing a line and press CTRL-SPACE it will pop-up a dialog with all valid ways you can complete the line.

For example typing Garage_Door<CTRL><SPACE> will pop-up a dialog with all the methods that are part of the Garage_Door Item. You can arrow down through the list and select the method you want and it will auto-complete the line.

Here is some code I use to determine whether the current time is between two time periods (scroll down to the “Get time period for right now” rule):

It would be best to use the latest version of Designer as there are minor changes necessary to keep the syntax highlighting up to date with changes in the server.

Thanks.
I’m using the designer from the 1.8.3 download. I was confusing the splash screen for habmin. I’ll try CTRL-Space again when I get home, but I had previously tried that without success.

The first time you open Designer it can take a surprisingly long amount of time (30 seconds in my experience) to pop up that dialog. If there is no valid autocomplete nothing will pop up.

CTRL-Space seems to work sometimes. On lines with ‘now’ or ‘DateTime’ is does nothing. I seem to be suffering the same problem described in this post. Designer is on Win-7. OH is on Pi. It looks like his cure was removing multiple versions of an addon. I don’t seem to have that.

Any ideas?