< operator in rule not working in example from wiki

Hello,

I tried to implement the alarm clock (example III from the wiki.

Unfortunately here

var hour = alarmTimeHour.state as DecimalType var minute = alarmTimeMinutes.state as DecimalType if (hour < 10) { msg = "0" } msg = msg + alarmTimeHour.state.format("%d") + ":"

The SmarHome Designer complains

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

I already postet it on this thread, but I think that the problem there is a different one (?) so in hindsight posting there was not optimal.

I am using Openhab2.

ANyone have any idea how to proceed?

thank you
Daniel

What happens when you change the name of hour to something like alarmHour and minute to something like alarmMinute? It looks as though the use of the word hour is ambiguous.

that changes nothing unfortunately.

And it doesn’t work when running in openHAB2? There’s nothing immediately obvious to me about the less than operator.

Does directly stating the var’s type help at all (e.g: var int hour)? Also, I’ve been using the less than operator directly with the state type: e.g:

if (Bedroom_MotionSensor_Luminance.state < 25)

var int hour throws the error

[QUOTE]
Type Mismatch: cannot convert from State to int
[/QUOTE]

EDIT:
However when using

if (alarmTimeHour.state < 10) { msg = "0" }
the designer does not complain, so this seems to solve it.

1 Like

See my reply on the linked thread.

The error is caused by the fact that DecimalType is a Number and a Type and the language can’t figure out which one you really want. If you just cast the state to Number or, as you saw, letting the language itself figure it out will fix the problem.

2 Likes