OH2 rule execution of if clause not logical for me

Hi guys,

I have the following rule for checking a door contact. If the contact is triggered to ON, an if check follows to check the general presence in the house (number item JemandAnwesend):

rule "Terrassentür auf"
when
        Item Terrassentuer changed from OFF to ON
then
        if(JemandAnwesend.state  == 0) {
        sendBroadcastNotification("Terrassentür auf!!")
    }
end

Unfortunately, the notification is never broadcasted. I checked the item “JemandAnwesend”, which was set to 0 according to the event log:

2016-12-03 18:16:25.694 [ItemStateChangedEvent ] - JemandAnwesend changed from 1 to 0

Oddly enough, the rule is triggered when it’s:

if(JemandAnwesend.state == "0") (Value set in exclamation mark)

Is this logical? I have other rules and haven’t set values in exclamation marks anywhere. But here it seems to be the only solution to get this rule running.

Any thoughts from the rule gurus out here are appreciated! :slight_smile:

Thanks,
Stefan

In case “JemandAnwesend” is defined as a String item, it is very logical to me.

And even if JemandAnwesend is of type Number, you will have to use

if ((JemandAnwesend.state as DecimalType) == 0) 

to prevent the DSL of misinterpreting the state as a state and not a number. :smiley:

@Udo_Hartmann Are you sure? I’d actually think that DecimalTypes are correctly compared against integers in rules, but I might be wrong…

Well, I did not test this, in OH1 it is, I did not change my rules so far…

@Kai: Yes, that would be logical. But it is defined as a Number item.

@Udo: I’ve already tried this with no luck. But I will try it again.

Wait…

It was a number item, but I changed it to String some hours ago to get a better layout on the main menu (mapping in the item file to get the mapped state as a text item on the sitemap).

Well, then everything makes sense and is absolutely logical.

Thanks guys!