[SOLVED] Simple IF statments not working

HI All, new to openHAB

I am using pushover to send notifications to my android device but for some reason if statements will not work
what so ever. what am I missing?

this code here works:

rule "Enable/Disable Alarm"
when
    Item Arm_Alarm changed to ON
then
    sendPushoverMessage(pushoverBuilder("Kitchen Door Opened").withEmergencyPriority())
end

This does not work for some reason:

rule "Enable/Disable Alarm"
when
    Item Arm_Alarm changed to ON
then
    if (XiaomiSensorKitchen_OpenStatus.state == OPEN){
        sendPushoverMessage(pushoverBuilder("Kitchen Door Opened").withEmergencyPriority())
    }
end

Am I missing some sort of Import or have I forgotten to enable something in a config file somewhere?

Thanks in advance

What is this item, please?

its a window / door sensor: https://www.openhab.org/addons/bindings/mihome/

so i think it comes under a contact state

Does it?
Show the channel and item,please?

Perhaps this isn’t going to do what you expect. It isn’t an “alarm” for the kitchen door. The rule runs only once when ‘Arm’ is turned on, checks if the kitchen door is open at that time, and messages if so.

Did you mean to have a rule that runs when the door is opened, checks to see if the alam is armed, and messages if so?

Yeahhhhh thats what I need to do…

so how would that be created?
I can see the logic I’m using is flawed

not sure what you mean by Channel

Come on, it’s just a case of altering what change triggers your existing rule, and what state you check within it.

2 Likes

Well, you need to do a bit of reading to understand the basics of openHAB:

TIP: It’s the wrong way around…
Follow this:

Thanks guys, got it working! :slight_smile:

rule "Enable/Disable Alarm"
when
    Item XiaomiSensorKitchen_OpenStatus changed from CLOSED or 
    Item XiaomiSensorFrontDoor_OpenStatus changed from CLOSED
then
    if(Arm_Alarm.state == ON)
    {
        if(XiaomiSensorKitchen_OpenStatus.state == OPEN){
        sendPushoverMessage(pushoverBuilder("Kitchen Door Opened").withEmergencyPriority())
        }else if(XiaomiSensorFrontDoor_OpenStatus.state == OPEN){
        sendPushoverMessage(pushoverBuilder("Front Door Opened").withEmergencyPriority())
        }
    }
end
1 Like

Another way:

rule "Enable/Disable Alarm"
when
    Item XiaomiSensorKitchen_OpenStatus changed to OPEN or 
    Item XiaomiSensorFrontDoor_OpenStatus changed to OPEN
then
    if(Arm_Alarm.state == ON) {
        val String doorName = triggeringItem.name.toString.split("_").get(0).substring(12) // returns "Kitchen or FrontDoor"
        sendPushoverMessage(pushoverBuilder(doorName + " Door Opened").withEmergencyPriority())
    }
end
1 Like

Thank you, appreciate it a lot