Import org.joda.time.* does not work

I’m using the Eclipse Smarthome Designer with openHAB1 and openHAB2 without any problems, maybe you should try that one: Archived Projects | The Eclipse Foundation

Thanks @sihui, that almost works.

The one problem I have is that it doesn’t recognize DecimalType as a number so that for lines like

        if ((Visibility.state as DecimalType) < 20) {

it reports the error

Ambiguous binary operation.
The operator declarations
operator_lessThan(Number,
Number) in NumberExtensions and
operator_lessThan(Type, Number)
in NumberExtensions
both match.

I’ll play around with this for a bit, to see if I can get it to work

have you found a solution for this?
I have the same problem in some rules.

This is not a problem with it not recognizing DecimalType as a Number. This is a problem caused by the fact that DecimalType is a Number. There are two methods, one that takes Number, Number and another that takes Type, Number and DecimalType matches both methods. The Rules DSL won’t guess which one you really want so it throws the error.

Simply cast the state to Number and it will fix the problem:

if((Visibility.state as Number) < 20) {

I know this post is super-old, but relevant to the last remaining problem I have in migrating from OH1 to OH2. With the absence yet still, as far as I can see, as any binding that does just what the AlarmClock binding does from OH1, this is my best bet. I really like this feature and want to continue using it, but keep getting the Ambiguous Binary operation errors. I tried casting to Number but still have the error.

//Copy the Alarm-Time from the UI to local variables
  	var hour = alarmClockHour.state as DecimalType
  	var minute = alarmClockMinute.state as DecimalType
  	
  	//Combine the hour and minutes to one string to be displayed in the
  	//user interface
  	if ((alarmClockHour.state as Number) < 10) {msg = "0"}
  	msg = msg + alarmClockHour.state.format("%d") + ":"
  	
  	if ((alarmClockMinute.state as Number) < 10) {msg = msg + "0" }
  	msg = msg + alarmClockMinute.state.format("%d")
  	postUpdate(alarmClockMessage,msg)

Still getting:

Ambiguous binary operation.
The operator declarations
	operator_lessThan(Number, Number) in NumberExtensions and
	operator_lessThan(Type, Number) in NumberExtensions
both match.

Thanks!

I’m surprised by this error and it might be tricky to solve.

One of the following will work.

  1. Instead of casting to Number, cast to Type for the how and minute. I’m not sure why this would all of a suddenly be a problem but if I interpret the error correctly this should fix it.

  2. Call intValue to get a primitive int which shouldn’t have a problem. E.g. ((alarmClockMinute.state as Number).intValue < 10