Variable is not initialized on startup

I have a very basic question that I don’t understand and cannot resolve at the moment.

I’m using OH2 on a RasPI.

I have tried to define some constants at the beginning of a rule file and using them to initialize a variable (see code below). I’m using then the variable in a rule that currently fails. The reason it fails is that the variable is null. It seems not to get initialized with the code below. I have also checked in Karaf using “echo $Var_Home_Status” and also there the variable is null.

Any ideas why this is not working?

/***************** Constants *******************************/
val int		HOME_STATUS_ZUHAUSE_AUT			= 0
val int		HOME_STATUS_ZUHAUSE_MAN			= 1
val int		HOME_STATUS_ABWESEND			= 2
val int		HOME_STATUS_SCHLAFEN			= 3
/***************** Variables *******************************/
var int Var_Home_Status = HOME_STATUS_ZUHAUSE_AUT

Known and very annoying problem with OH startup. Once OH is started, try to reload your rule file with a command like touch conf/rules/myrules.rules and then it will be ok.

Thanks for feedback.

I tried now in putty to touch the rules file which comprises the variable:

openhabian@openHABianPi:/$ touch etc/openhab2/rules/szenen.rules

However, then in Karaf I still get null when doing:

openhab> echo $Var_Home_Status
null

Am I implementing your recommendation in a wrong way?

I’ll bet you would find the variable assignment to a constant works inside a rule. Perhaps a startup rule would suit you.
There seems to be an oddity in Rules DSL where ‘base level’ variables/constants/functions etc. (that you might expect to be global) are not visible to their peers, and so only usable within rules.

There is an open issue with the simple equivalent demonstration failure
val Number x = 1
val Number y = x

Thanks for the helpful replies. I’m using now for the moment a startup rule to cover it until the open issue is resolved.