MQTT item state upon reconnection of WiFi or WLAN

I have a custom home alarm setup with my OpenHAB system which includes the item “alarmState” which holds the value of the alarm as either “Disarmed”, “Armed”, or “Triggered”. I’ve noticed that after several recent power outages in my area, the default state for “alarmState” is “Armed” when I would prefer it to be “Disarmed”. I am unsure as to why the initial item state isn’t “null”. Additionally after a power outage today, the alarm reinitialized as “Armed” and then was subsequently “Triggered” thereafter by motion from my family. One thing to add was that although our WiFi connection was restored, our WLAN/Internet connection was still knocked out. Several hours later when I went to reset our modem in attempts to restore the Internet connection, the alarm state was once again reset to “Armed”. I’ve noted the event below with a screenshot from the OpenHAB log, Internet was restored about 2 minutes before the timeout occurred.

.items

String alarmStatus “[%s]” {mqtt="<[mosquitto:/home/alarm/controller/state:state:default"}
String alarmControllerCommand {mqtt=">[mosquitto:/home/alarm/controller/command:command:*:default]"}
String alarmKeypadInput “Input [%s]”
String alarmZone1 {mqtt="<[mosquitto:/home/alarm/zone1/state:state:default"}
String alarmZone2 {mqtt="<[mosquitto:/home/alarm/zone2/state:state:default"}

.rules

rule “Motion detected”
when
Item alarmZone1 changed to Motion or Item alarmZone2 changed to Motion
then
if(alarmStatus.state.toString == “Armed”) { //If motion is detected and system is armed
alarmStatus.sendCommand(“Triggered”)
}
if(alarmStatus.state.toString == “Chime”) { //If motion is detected and system is on chime
playSound(“chime.mp3”)
}
end

rule “Keypad input”
when
Item alarmKeypadInput received command
then
if(alarmKeypadInput.state.toString == “***”) { //If correct PIN is entered
if(alarmStatus.state.toString != “Disarmed”) { //And system is not disarmed
alarmStatus.sendCommand(“Disarmed”)
}
}
if(alarmKeypadInput.state.toString != “***”) { //If incorrect PIN is entered
playSound(“incorrect.mp3”)
}
end

rule “Alarm given command”
when
Item alarmStatus received update
then
switch(alarmStatus.state.toString) {
case “Arm”: {
alarmControllerCommand.sendCommand(“Arm”)
}
case “Armed”: {
playSound(“armed.mp3”)
}
case “Disarmed”: {
alarmControllerCommand.sendCommand(“Disarmed”)
playSound(“welcome.mp3”)
}
case “Chime”: {
alarmControllerCommand.sendCommand(“Chime”)
playSound(“chime.mp3”)
}
case “Triggered”: {
alarmControllerCommand.sendCommand(“Triggered”)
playSound(“alarm triggered.mp3”)
sendNotification("***", “WARNING, home alarm triggered!”)
}
}
end

Anyone have any ideas why a power reboot on OpenHAB or a restoration of a WLAN connection could cause “alarmState” to be set to “Armed”?

I just got my rule for power outages written today. Well the first draft but it works. Maybe something here can help you. New Rule: Having a moment of what am I doing wrong?. Has an example of a system started rule.

Also, have a look at this post Resend MQTT command to nodemcu(or ESP 8266) after power failure

Regardless, I can suggest you set a system startup rule that sets the alarm to disarmed on boot. The other option is setting up persistence to restore to the last state.