[SOLVED] Openhab rule java.lang.number problem

I’m using Alarm Clock script (link below) to make kinda my own schedule.
I think that it should work but i get this error.

var Timer timerPERSON1Wecker = null

rule "Termostat urnik"
    Time cron "0 0/1 * * * ?" // note, one could use an external event to trigger the rule if the alarm is implemented elsewhere (e.g. Tasker)
    val person = "PERSON1_WECKER_"

    var dayName= "NA"
    switch now.getDayOfWeek{
        case 1: dayName = "PO"
        case 2: dayName = "TO"
        case 3: dayName= "SR"
        case 4: dayName= "CE"
        case 5: dayName= "PE"
        case 6: dayName= "SO"
        case 7: dayName= "NE"
    val person1On = gAlarm.members.filter[s | s.name == person+dayName].head.state
    if(person1On == ON){
        var sollMinute = (gAlarm.members.filter[s | s.name == person+"M"].head.state as Number).intValue
        var sollStunde = (gAlarm.members.filter[s | s.name == person+"H"].head.state as Number).intValue
        var runTime = (gAlarm.members.filter[s | s.name == person+"RUN"].head.state as Number).intValue

        if(sollMinute == now.getMinuteOfHour && sollStunde == now.getHourOfDay) {
            //sendCommand(person+"_AKTIV", ON)
            postUpdate("termostat1_zelena_temperatura", "25")
			if(PERSON1_WECKER_ONOFF.state == ON){
				logInfo("Urnik", "Log2")
				postUpdate("termostat1_zelena_temperatura", "25")
            // do stuff
            timerPERSON1Wecker = createTimer(now.plusMinutes(runTime), [|
                // do stuff
                timerPERSON1Wecker = null

In console log i get

15:26:00.016 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Termostat urnik: java.lang.Number

Does anyone know what is wrong?

I’m going to guess one of your Number Items is uninitialized. Uninitialized Items have the state NULL (not to be confused with the all lowercase null). Since NULL is not a java.lang.Number you are getting an exception when you try to cast it to one.

That is just a guess. The code looks OK at a glance.

1 Like

Tose are my items. Trying to search what is missing…

Group gAlarm
//Wecker Montag
Switch PERSON1_WECKER_PO      "Wecker Montag"                  <clock>	(gAlarm)
Number PERSON1_WECKER_H    "Weckzeit Montag Stunde [%s]"    <calendar>	(gAlarm)
Number PERSON1_WECKER_M    "Weckzeit Montag Minute [%s]"    <calendar>	(gAlarm)
Number PERSON1_WECKER_RUN    "Wecker Montag Laufzeit [%s]"    <clock>	(gAlarm)
//Wecker Dienstag
Switch PERSON1_WECKER_TO      "Wecker Dienstag"                  <clock>	(gAlarm)
//Wecker Mittwoch
Switch PERSON1_WECKER_SR      "Wecker Mittwoch"                  <clock>	(gAlarm)
//Wecker Donnerstag
Switch PERSON1_WECKER_CE      "Wecker Donnerstag"                  <clock>	(gAlarm)
//Wecker Freitag
Switch PERSON1_WECKER_PE      "Wecker Freitag"                  <clock>	(gAlarm)
//Wecker Samstag
Switch PERSON1_WECKER_SO      "Wecker Samstag"                  <clock>	(gAlarm)
//Wecker Sonntag
Switch PERSON1_WECKER_NE      "Wecker Sonntag"                  <clock>	(gAlarm)

Switch PERSON1_WECKER_AKTIV "Wecker PERSON1 Aktiv" (gAlarm)
Number PERSON1_WECKER_PRESETS "Wecker Preset Laden"				<calendar>	(gAlarm)

I’m not saying your Items do not exist. I’m saying they do not have a state yet. They are in an uninitialized state. You need to give them a state before the rule above will work or you need to test that their states are not NULL before blindly trying to cast them to Number.

On your sitemap uninitialized Items will appear with a state of -.

1 Like


This one was null and now it works.
Thanks again! :slight_smile: