How to check Group State with "if" in rules?

Hell,
not very clear the topic…
I have a Group with WindowContacts, which diplays the SUmm of all contacts:

Group:Contact:OR(OPEN, CLOSED) Fensterkontakte “Offene Fenster [(%d)]” (All)

This is working, at least with one contact (till now I have only one). So it displays “(1)” or “(0)”.
Now I want to switch on a lamp, when there is no “(0)”, means, at least one window is open.

rule "Warn on Window open with flashing Laser"
when
Item Fensterkontakte changed
then
if(Fensterkontakte.state != 0) {
LaserCommand.sendCommand(“ON”)
}
else {
LaserCommand.sendCommand(“OFF”)
}
end

The if-clause is not working correctly, because when the contact is triggered, allways the next line “LaserCommand.sendCommand(“ON”)” is fired. So, what must be the syntax of the if-clause to check for the Number/state/count of the Group?
Thanks…

p.s.: not important, but for integrety:
String LaserCommand “[%s]” {mqtt=">[broker:haus/HWR/Fenster/Laserwarnung:command:*:default]"}
The String (comand) on MQTT is send correctly, I see it in MQTT.fx

It works better to use the state names rather than numbers.

Try:

if(Fensterkontakte.state != OPEN) { // no windows open

Try swapping the conditional as well:

if(Fensterkontakte.state == CLOSED) {
    LaserCommand.sendCommand("OFF")
}
else {
    LaserCommand.sendCommand("ON")
}

Finally, log the state of Fensterkontakte as the first line so you know what state it actually is in.

logInfo("Fensterkontakte state == " + Fensterkontakte.state.toString)

Thanks for this very fast answer. It’s working!
In the line with the logInfo was something missing. Here for others the code:

rule "Warn on Window open with flashing Laser"
when
        Item Fensterkontakte changed
then
    logInfo("Fensterkontakte", "Fensterkontakte state == " + Fensterkontakte.state.toString)
    if(Fensterkontakte.state == CLOSED) {
        LaserCommand.sendCommand("OFF")
    }
    else {
        LaserCommand.sendCommand(2)
    }
end

Thanks again,
Ingo