[SOLVED] Text item gets ignored when PI restarts

I am using an alarm rule and for activation of that rule I am using a text item called “AlarmOn”
Generally this works, but when “ON” and I am restarting my PI, Openhab remembers the state, it still shows “ON” but the rule doesn´t work.

I noticed that I need to switch OFF and ON again, for having the rule working as it should.

What can I do to have Openhab recognizing that AlarmOn is “ON”?

What means the rule does not work? A rule with the trigger AlarmOn is not triggered?

I would think that you use some persistence and have restore on stardup. This will the restore the states of your items. And as the rule for the state change was allready executed when this items changed originally it should not execute a second time.

There is a rule which is executed on startup this could be used to fire the rule or handle related stuff.

rule "Initialize system when started"
when
    System started
then
   if( AlarmOn.state == On){ //Fire the rule }
end

Is it a realy a String or a Switch?

if( AlarmOn.state == ON){ //Fire the rule }

or if it’s a String

if( AlarmOn.state.toString == "ON"){ //Fire the rule }

ˋˋ

when
	Item Sonbas10b changed from OFF to ON or
	Item Sonoff3 changed from OFF to ON
then
	if(shutoffTimer !== null || AlarmOn.state == OFF || lastRun.isAfter(now.minusMinutes(1))) return;
	if(timers.size < 3) {
		val t = createTimer(now.plusMinutes(1), [ | timers.remove(t) ] )
		timers.add(t)

}
ˋˋ
This is that peace of code and here is the switch I am reading, AlarmOn.state
When the PI gets restarted it does not recognize the state. In this case the switch is “on” before restart and “on” after restart, but the rule doesn´t work.
When I now manually switch Off and On again, it starts working

If you only set the Switch AlarmON to OFF and to ON and it works, why don’t try @Josar suggestion. Set OFF, maybe a delay and ON.
If AlarmON after start automaticly get the last state before poweroff, you use restoreOnStartup-persistence. Do you want?
If I see your code, not AlarmOn is triggering the rule. What does Sonbas10b and/or Sonoff3 switch?

Sonbas10b and Sonoff3 are PIR detectors and I am counting the activations when 3 times in a minute then activate the siren. And as a prerequisite the switch AlarmOn needs to be “ON”. What it usually is.
When I restart PI the ArlarmOn switch is still “ON” but somehow it doesn´t get recognized.
Manually switching OFF and ON and all is OK.

When restoreOnStartup-persistence can help I definitely would be highly interested how to do that.

This is the rule:

rule "Sonbas Motion changed from OFF to ON 3 times in a minute"
	when
		Item Sonbas10b changed from OFF to ON or
		Item Sonoff3 changed from OFF to ON
	then
		if(shutoffTimer !== null || AlarmOn.state == OFF || lastRun.isAfter(now.minusMinutes(1))) return;
		if(timers.size < 3) {
			val t = createTimer(now.plusMinutes(1), [ | timers.remove(t) ] )
			timers.add(t)
}
		if(timers.size == 3) {
			sendMail("xxx@gmail.com", "Sonbas10b", "Sonbas10b motion")
			TH03.sendCommand(ON)
			lastRun = now
			logInfo("RuleInfo", "Siren START")
         timers.clear()
			shutoffTimer = createTimer(now.plusSeconds(30)) [ |
			TH03.sendCommand(OFF)
			logInfo("RuleInfo", "Siren STOP")
			shutoffTimer = null ]
}
end 

Install the mapdb persistence

The in the persistence folder setup mapdb.persist as follow:

// mapdb persistence

Strategies {
	default = everyChange
}
Items {
	AlarmOn : strategy = everyChange, restoreOnStartup
}

What are totaly different statements.
Yes, I have understand, only the second ist correct.

Hm still not correct behaviour.

AlarmOn ist active after restart now as it should.
When I restart PI and trying the rule, I just activate the sonbas10b 3 times nothing happens.
When I now manually switch the TH03 in BasicUI and switching AlarmOn OFF&ON then suddenly it works.Cannot exactly repeat what I do.

What can this be? It looks like the mqtt devices aren´t acting as they should, any idea?