Rule with IF not working

I am trying to build a simple alarm system with OpenHAB. I have a MQTT Siren and an mqtt door contact.
I created this rule:

rule "Alwin_Alarm ON"
when
  Item Alwin_Door changed from CLOSED to OPEN
then
  if (Item Alwin_Alarm_auto === ON) {
      Alwin_Alarm.sendCommand(ON)
  }
  end
end

But it does not work.

My Items file:

Group     Home            "Our Home"   <house>
Group     Alwin_Zimmer        "Alwins Zimmer"   <door>     (Home)              ["Alwins Zimmer"]

Group:Contact:OR(OPEN, CLOSED)   gDoor   "Door"   <door>   (Home)   ["Door"]
Group:Switch:OR(ON, OFF)   gAlarm   "Alarm"   <alarm>   (Home)   ["Alarm", "Switchable"]

Contact   Alwin_Door   "Door"       <door>        (Alwin_Zimmer, gDoor)   ["Door"]       {channel="mqtt:topic:0fd0632a:alwin_t$

Switch   Alwin_Alarm   "Alarm"      <alarm>       (Alwin_Zimmer, gAlarm)   ["Alarm", "Switchable"]   {channel="mqtt:topic:1952$
Switch Alwin_Alarm_auto "Alarmanlage" <alarm> (Alwin_Zimmer, gAlarm) ["Alarm", "Switchable"]

It worked with this:

rule "Alwin_Alarm ON"
when
  Item Alwin_Door changed from CLOSED to OPEN
then
      Alwin_Alarm.sendCommand(ON)
  end
end

Whats wrong with the If?

You can’t request the value of an object

rule "Alwin_Alarm ON"
when
  Item Alwin_Door changed from CLOSED to OPEN
then
  if (Alwin_Alarm_auto.state == ON) {
      Alwin_Alarm.sendCommand(ON)
  }
  
end

You request the state.

1 Like

You only want one end for each rule, though

Didn’t see that second end when I made the correction :roll_eyes:

Okay, thanks.
I just discovered flowmaker, I thhink i will use that.

Can you mark my post as the solution.