Pushover error only after reboot

I have a strange error with pushover that only occurs after a reboot. The error remains until I make whatever small change to the rule and save it again. Even adding a comment clears the error.
This is my rule:

var alarmOn = false

var Timer tBlink = null  // Timer for light flashing
var int iBlink = 0       // counter for light flashing

var actions = getActions("pushover", "pushover:pushover-account:account")
val thuis = 1
val afwezig = 2
val slapen = 3 

// The rule AlarmOnOff is triggered whenever the alarmarea is changed. If the alarm area is set to anything other then "Thuis" it will switch on the alarm 
// after a 20 second delay time. Within this delay time the alarm can be switched of, if not the house is armed. 
rule "AlarmOnOff"

when 
    Item AlarmArea changed  
then
    switch(AlarmArea.state){
        case (thuis):{        
            Sirene.sendCommand(OFF)
            //AlarmWarningBeep.sendCommand(OFF)
            alarmOn = false
            gLampen.sendCommand(OFF)
            actions.sendHtmlMessage("Alarm Tuoro uitgeschakeld", "openHAB")
            if(tBlink !== null ) {
                tBlink.cancel()
                tBlink = null
            }
        }
        case(afwezig):{    
            actions.sendHtmlMessage("Alarm Tuoro bijna ingeschakeld: Afwezig", "openHAB")                
            iBlink = 0
            tBlink = createTimer(now,[|
                iBlink++
                if(iBlink < 20) {
                    BvnWnkmrLmp.sendCommand(if(BvnWnkmrLmp.state != ON) ON else OFF)
                    tBlink.reschedule(now.plusSeconds(1))
                } else {
                    alarmOn = true
                    actions.sendHtmlMessage("Alarm Tuoro ingeschakeld: Afwezig", "openHAB")
                    tBlink = null
                }
            ])
        }   
        case(slapen):{  
            actions.sendHtmlMessage("Alarm Tuoro bijna ingeschakeld: Slapen", "openHAB")
            iBlink = 0
            tBlink = createTimer(now,[|
                iBlink++
                if(iBlink < 20) {
                    BvnWnkmrLmp.sendCommand(if(BvnWnkmrLmp.state != ON) ON else OFF)
                    tBlink.reschedule(now.plusSeconds(1))
                } else {    
                    alarmOn = true
                    actions.sendHtmlMessage("Alarm Tuoro ingeschakeld: Slapen", "openHAB")
                    tBlink = null
                }
            ])
        }
    }
end

// Rule Alarm activated when any one of the items of gAlarm changes to on. If alarm area != thuis the alarm is activated
rule "AlarmActivated" 
when 
    Item gAlarm changed to ON
then 
    if (((AlarmArea.state == slapen) && (gAlarmSlapen.state == ON)) || ((AlarmArea.state == afwezig) && (gAlarmAfwezig.state == ON))) {        
        gLampen.sendCommand(ON)
        //Sirene.sendCommand(ON)
        actions.sendHtmlMessage("Alarm Tuoro " +LastMotion.state, "openHAB")
    }   
end

// If the any of the items og gAlarmDelayes  goes to on the alarm is suspended for x seconds to allow for disarming the alarm.
rule "Delayed alarm activated"
when 
    Item gAlarmDelayed changed to ON 
then 
    if (alarmOn && Sirene.state == OFF) {                                           // if Sirene is already ON no need to sound the beeper again              
        iBlink = 0                                                                  // set initial counter
        tBlink = createTimer(now,[|                                                 // create a timer which is executed immediately
            iBlink++                                                                
            if(iBlink < 20) {
                BvnWnkmrLmp.sendCommand(if(BvnWnkmrLmp.state != ON) ON else OFF)
                tBlink.reschedule(now.plusSeconds(1))
            } else {
                //Sirene.sendCommand(ON)
                actions.sendHtmlMessage("Alarm Tuoro " +LastMotion.state, "openHAB")
                tBlink = null
            }
        ])
    }
end

        

rule "No Internet" 
when 
    Item InternetConnected changed to OFF
then     
    actions.sendHtmlMessage("Alarm Tuoro Lost internet connection","openHAB")
    //BvnWnkmrRouterPower.sendCommand(OFF)
end

rule "Internet Restored"
when 
    Item InternetConnected changed to ON
then
    actions.sendHtmlMessage("Alarm Tuoro internet connection restored","openHAB")
    //BvnWnkmrRouterPower.sendCommand(OFF)
end

rule "Camera detected Person"
when 
  Item Person changed to ON
then 
    if (((AlarmArea.state == slapen) && (gAlarmSlapen.state == ON)) || ((AlarmArea.state == afwezig) && (gAlarmAfwezig.state == ON))){
        if ((BtnVrdrLichtnivo.state as Number) < 40) {
            BtnOprtLmpGrt.sendCommand(ON)
        }
        actions.sendHtmlMessage("Alarm Tuoro Persoon alarm","openHAB")
    }
end

rule "Camera detected Intrusion"
when 
  Item Intrusion changed to ON
then 
    if (((AlarmArea.state == slapen) && (gAlarmSlapen.state == ON)) || ((AlarmArea.state == afwezig) && (gAlarmAfwezig.state == ON))){
        if ((BtnVrdrLichtnivo.state as Number) < 40) {
            BtnOprtLmpGrt.sendCommand(ON)
        }
        actions.sendHtmlMessage("Alarm Tuoro Intrusie alarm","openHAB")
    }
end


This is the error I get in my openhab log file directly after the reboot.

2022-08-21 10:46:07.725 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Alarm.rules'
2022-08-21 10:46:10.885 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'Alarm.rules', using it anyway:
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object
The field Tmp_AlarmRules.actions refers to the missing type Object

When I trigger the rule so a pushover message should be send nothing happens no message is send and this error apears in the openhab log file:

2022-08-21 11:35:19.849 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Alarm-1' failed: null in Alarm

Now I edit the rule file by just typing a space on an empty line and saving the rule file again. After this the rule loads with no errors and the pushover messages are being delivered as requested.

2022-08-21 11:49:04.670 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Alarm.rules'

I have to repeat this after every reboot to get pushover to work what am I doing wrong here.
It’s not a huge problem but anoing to have to edit the file after every reboot.

Kind Regards,
Will van Gemert

Do you use .rules files or the UI to run the rules under OH3 ?
In case you use the UI to define the rules then Global variables in rules defined in UI with RulesDSL? - #8 by rlkoshak might be the root cause.

It looks to me like during boot up your rule file is loading before the pushover action is registered, so the global action variable cannot be properly set. Any tweak to the file that causes it to reload later allows the global variable to become properly set

Try just moving the action variable inside any of the rules that require it so that the pushover action doesn’t get accessed before it’s ready.

I use only .rules files, I still do everything in files, although it is recommended not to, I feel more comfortable with text files then with a graphic interface, might have something to do with my age :wink:

Hi justin,

Problem is that I use Pushover from within a timer, so I need to define it global.

Just access the action directly in the timer. This will not result in any noticeable loss of performance.

Hi Justin,

You right with the problem, I now defined the variable twice inside and outside the rule, I stll get a warning on boot but Pushover works imwdatly after boot up so no changes needed to the .rules file.:slight_smile:

var alarmOn = false
var Timer tBlink = null  // Timer for light flashing
var int iBlink = 0       // counter for light flashing
var actions = getActions("pushover", "pushover:pushover-account:account")

val thuis = 1
val afwezig = 2
val slapen = 3 

// The rule AlarmOnOff is triggered whenever the alarmarea is changed. If the alarm area is set to anything other then "Thuis" it will switch on the alarm 
// after a 20 second delay time. Within this delay time the alarm can be switched of, if not the house is armed. 
rule "AlarmOnOff"
when 
    Item AlarmArea changed  
then
var actions = getActions("pushover", "pushover:pushover-account:account")    
    switch(AlarmArea.state){
        case (thuis):{        
            Sirene.sendCommand(OFF)
            //AlarmWarningBeep.sendCommand(OFF)
            alarmOn = false
            gLampen.sendCommand(OFF)
            actions.sendHtmlMessage("Alarm Tuoro uitgeschakeld", "openHAB")
            if(tBlink !== null ) {
                tBlink.cancel()
                tBlink = null
            }
        }
        case(afwezig):{    
            actions.sendHtmlMessage("Alarm Tuoro bijna ingeschakeld: Afwezig", "openHAB")                
            iBlink = 0
            tBlink = createTimer(now,[|
                iBlink++
                if(iBlink < 20) {
                    BvnWnkmrLmp.sendCommand(if(BvnWnkmrLmp.state != ON) ON else OFF)
                    tBlink.reschedule(now.plusSeconds(1))
                } else {
                    alarmOn = true
                    actions.sendHtmlMessage("Alarm Tuoro ingeschakeld: Afwezig", "openHAB")
                    tBlink = null
                }
            ])
        }   
        case(slapen):{  
            actions.sendHtmlMessage("Alarm Tuoro bijna ingeschakeld: Slapen", "openHAB")
            iBlink = 0
            tBlink = createTimer(now,[|
                iBlink++
                if(iBlink < 20) {
                    BvnWnkmrLmp.sendCommand(if(BvnWnkmrLmp.state != ON) ON else OFF)
                    tBlink.reschedule(now.plusSeconds(1))
                } else {    
                    alarmOn = true
                    actions.sendHtmlMessage("Alarm Tuoro ingeschakeld: Slapen", "openHAB")
                    tBlink = null
                }
            ])
        }
    }
end

Always understood that variables used inside Timers needed to be defined global, But just followed your advice evrything functions as it should without warnings.

Thanks

That’s not a correct understanding. Perhaps you are instead thinking that to store the timer itself in a variable, that variable needs to be a global variable, or else you’ll lose access to that timer (e.g. to cancel it later) as soon as the rule exits.

The lambda passed to the timer will inherit all the variables that exist at the time it’s created in rules DSL. So the timer will also have access to all the variables local to that rule as well as the globals that exists at that point. When the rule exits, the timer will retain a copy of the variables for itself.

The only other case where a global variable would be required when working with timers is when you have more than one Timer that needs to share the same variable for some reason.