Global variable issue in OH3 after reboot


I have the feeling that my global variables are not loaded after a reboot.
If I overwrite the files again, it works again.

Can anyone say anything about this?

Tell us more. My crystal ball tells me you might be talking about DSL xxx.rules files? And ‘global’ variables, as defined outside of rules at the head of the file?
Not sure about your feelings, but it is testable if you need reassurance.

rule "test global"
   System started
   // if someGlobal was not created at all, this will just blow up loudly.
   logInfo("diag", "Testing my global")
   if (someGlobal !== null) {
      logInfo("diag", "my global is set to {}", someGlobal)
   } else {
      logWarn("diag", "Help!  my global did not get a value")

// some rule you have feelings about
rule "whatever it does"
   // if someGlobal was not created at all, this will just blow up loudly.
   if (someGlobal !== null) {
      logInfo("diag", "my global is set to {}", someGlobal)
   } else {
      logWarn("diag", "Help!  my global has been emptied")

You might need to think about file loaded (and populating globals) is not the same event as System started, which can happen at other times for other reasons e.g. Thing edits.

You right :smiley: your crystal ball works very good. Thanks
Yes I’m talking about DSL and the variables are defined outside of the rule at the head of the file?

After restart the variable are not defined but after edit.

Show me.
I do not mean to belittle “feelings” here, by the way. A good diagnostician takes his hunches and gut feelings into account. But you should use them in practice to decide where/when to get your real evidence.
As shown above, it’s very easy to find out for certain if what you suspect is true.

I will try this.

Are the global variables file spanning?

NO, never have been. They are not really globals, but shared local to every rule in just one xxx.rules file.

Thank you rossko57 for your help and information.

Hello again,
I have noticed that the action in a rule is not loaded after the restart. After editing, the action is loaded. This happens to me with all rules with this action:

val telegram = getActions("telegram","telegram:telegramBot:703145")

here is my example

val telegram = getActions("telegram","telegram:telegramBot:703145")
rule "keiner zuhaus licht an"
	Member of familie changed to OFF
	if(gLGesamt.state != OFF)
		telegram.sendTelegramQuery(-XXXXL,"Es ist keiner Zuhause, aber Licht ist noch an.\nSollen die Lichter ausgeschaltet werden?", "Warn_light_on", "Ja", "Nein")

rule "Reply handler for Lights on"
    Item telegramReplyId received update Warn_light_on
	if (telegramMessage.state.toString == "Ja") 
		telegram.sendTelegram(-XXXXXL, "Lichter wurden ausgeschaltet.")
		telegram.sendTelegram(-XXXXXL, "Licht bleibt an.")

What could be the problem?

The actions were not ready at the moment the rule file loaded. It depends how long it takes the supplying binding to get organized - maybe that Thing hasn’t connected yet. You only get one attempt doing it that way, it doesn’t wait.

Circumvention is to get the Action later when you need it, at rule run time, by doing getActions() within your rule(s).

I can now isolate the problem. All the rules that were defined before all the rules variables are not loaded after a restart. it can also happen after a while that precisely the rules are forgotten. What could be the cause?
Here is an example:

 	var boolean st__vorDusk 	= false
 	var boolean st__nachDawn    = false
	var boolean st__nachAD		= false
	var boolean st__RL_East     = false
	var boolean st__RL_South    = false
	var boolean st__RL_West     = false

	var Number t__Dusk         	= 0
	var Number t__now         	= 0
	var int RLEGoffen			= 0
	var int RLEGripp			= 0
	var int RLEGzu				= 0
	var int RLOGoffen			= 0
	var int RLOGripp			= 0
	var int RLOGzu				= 0
	var int RLoffen				= 0
	var int RLripp				= 0
	var int RLzu				= 0
	var Timer XmasTime = null

rule "Sonnenschutz"

Please explain.
I don’t know what “rules that were defined before all the rules variables” are.
If you are talking about the order stuff is placed in, in a xxx.rules file, you must put ‘globals’ first and all rules after.

Forgotten how, what does or does not happen that you expected?

Umm, it’s a long list of variables. What is it supposed to be showing us?

That’s what I did, the variables are at the beginning of an xxx.rules file and after the variables come my rules. The variables I have defined are used in several rules.

When I go to the GUI (openhab:8080) I see under rules that the rules in xxx.rules have not been loaded. After “editing” (without changing) the rules are displayed in the GUI.

The example is only to show you how I have defined the variables.

Who cares, for file based rules. More important - do they work? I’m trying to focus on the actual problem.

Why do you suspect that has anything to do with variables?

You should be aware of this issue about Item files editing -