What would work is that I get the values inside MQTT.fx for /messages/states/iKonferenz_Homematic_Fenster1_Position if I subcribe to it. I got the values OPEN, TILTED and CLOSED. Inside my rules following triggers would work:
rule "WindowsClosed"
when
Item iKonferenz_Homematic_Fenster1_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster2_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster3_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster4_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster5_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster6_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster1_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster2_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster3_Position changed to CLOSED
then
....
end
rule "WindowsTilted"
when
Item iKonferenz_Homematic_Fenster1_Position changed to TILTED or
Item iKonferenz_Homematic_Fenster2_Position changed to TILTED or
Item iKonferenz_Homematic_Fenster3_Position changed to TILTED or
Item iKonferenz_Homematic_Fenster4_Position changed to TILTED or
Item iKonferenz_Homematic_Fenster5_Position changed to TILTED or
Item iKonferenz_Homematic_Fenster6_Position changed to TILTED or
Item iMultimedia_Homematic_Fenster1_Position changed to TILTED or
Item iMultimedia_Homematic_Fenster2_Position changed to TILTED or
Item iMultimedia_Homematic_Fenster3_Position changed to TILTED
then
....
end
rule "WindowsOpen"
when
Item iKonferenz_Homematic_Fenster1_Position changed to OPEN or
Item iKonferenz_Homematic_Fenster2_Position changed to OPEN or
Item iKonferenz_Homematic_Fenster3_Position changed to OPEN or
Item iKonferenz_Homematic_Fenster4_Position changed to OPEN or
Item iKonferenz_Homematic_Fenster5_Position changed to OPEN or
Item iKonferenz_Homematic_Fenster6_Position changed to OPEN or
Item iMultimedia_Homematic_Fenster1_Position changed to OPEN or
Item iMultimedia_Homematic_Fenster2_Position changed to OPEN or
Item iMultimedia_Homematic_Fenster3_Position changed to OPEN
then
....
end
So the problem is not only inside my .rules file to read it correctly. As you can see it never changes inside the sitemap so I have also problems inside my .items file.
I think this should’t be the problem. Because this code works:
rule "WindowsClosed"
when
Item iKonferenz_Homematic_Fenster1_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster2_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster3_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster4_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster5_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster6_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster1_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster2_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster3_Position changed to CLOSED
then
// Switch lamps off
for(var int i = 0; i < hueLampsMWBright.size(); i++){
hueLampsMWBright.get(i).sendCommand(100)
}
Thread::sleep(100)
for(var int i = 0; i < hueLampsMWColor.size(); i++){
hueLampsMWColor.get(i).sendCommand(HSBType.WHITE)
}
Thread::sleep(100)
for(var int i = 0; i < hueLampsMWToggle.size(); i++){
hueLampsMWToggle.get(i).sendCommand(OFF)
}
end
What I want to do is that the lights only get switched off when all windows are closed. To use AND instead of or is not right in the WHEN-Clause because you can open, tilt and close only one window at one time or does human have multiple arms?
So I added an if-Clause which should detect if there is still a window opened or tilted.
rule "WindowsClosed"
when
Item iKonferenz_Homematic_Fenster1_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster2_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster3_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster4_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster5_Position changed to CLOSED or
Item iKonferenz_Homematic_Fenster6_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster1_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster2_Position changed to CLOSED or
Item iMultimedia_Homematic_Fenster3_Position changed to CLOSED
then
//if(iKonferenz_Homematic_Fenster1_Position.state == CLOSED && iKonferenz_Homematic_Fenster2_Position.state == CLOSED && iKonferenz_Homematic_Fenster3_Position.state == CLOSED && iKonferenz_Homematic_Fenster4_Position.state == CLOSED && iKonferenz_Homematic_Fenster5_Position.state == CLOSED && iKonferenz_Homematic_Fenster6_Position.state == CLOSED && iMultimedia_Homematic_Fenster1_Position.state == CLOSED && iMultimedia_Homematic_Fenster2_Position.state == CLOSED && iMultimedia_Homematic_Fenster3_Position.state == CLOSED) {
logInfo("rules", "All windows are closed")
logInfo("rules", "Fenster 1 state {}", iKonferenz_Homematic_Fenster1_Position)
logInfo("rules", "Fenster 1 state {}", iKonferenz_Homematic_Fenster1_Position.state.toString)
// Switch lamps off
for(var int i = 0; i < hueLampsMWBright.size(); i++){
hueLampsMWBright.get(i).sendCommand(100)
}
Thread::sleep(100)
for(var int i = 0; i < hueLampsMWColor.size(); i++){
hueLampsMWColor.get(i).sendCommand(HSBType.WHITE)
}
Thread::sleep(100)
for(var int i = 0; i < hueLampsMWToggle.size(); i++){
hueLampsMWToggle.get(i).sendCommand(OFF)
}
}
end
But I have found the problem. If I run the rule first all states are NULL. I got something like this:
13:21:09.873 [INFO ] [.eclipse.smarthome.model.script.rules] - Fenster 1 state NULL
13:21:09.882 [INFO ] [.eclipse.smarthome.model.script.rules] - Fenster 2 state NULL
13:21:09.899 [INFO ] [.eclipse.smarthome.model.script.rules] - Fenster 3 state CLOSED
13:21:09.909 [INFO ] [.eclipse.smarthome.model.script.rules] - Fenster 4 state NULL
13:21:09.923 [INFO ] [.eclipse.smarthome.model.script.rules] - Fenster 5 state NULL
13:21:09.929 [INFO ] [.eclipse.smarthome.model.script.rules] - Fenster 6 state CLOSED
Item states are NULL at system start time, and stay that way until they get updated with something else. Often that will be from a report from a device.
Persistence services can be used to “remember” states and restore at start-up.
That’s not always a good idea if you want to know “real” states, like here. NULL represents “don’t know yet”, which might be more useful than “it was like this in the past”.
Item states may also get reinitialized to NULL when editing Things or Items.
It’s a String type Item. The state will never be CLOSED, which is a valid state but only for Contact type Items (this is why the rule does not error).
String type will be “CLOSED”
yourItem.state == “CLOSED”
NULL is a valid state but not a string.
yourItem.state == NULL
APPLE is neither a string nor a known system constant type.
The handler for when clause is less picky. But will likely mess up e.g. with a space PART OPEN or with a keyword like end.
Keep your own sanity by treating strings as “strings”.