rule "Window state changed"
when
Item MyWindow changed
then
if(MyWindow.state ==OPEN) MyRollerShutter.sendCommand(UP)
else MyRollerShutter.sendCommand(DOWN)
end
By applying the design patterns you can make this generic for lots of windows.
rule "A window state changed"
when
Item Window_1 changed or
Item Window_2 changed or
...
then
val winNum = triggeringItem.name.split("_").get(1)
var cmd = if(triggeringItem.state == OPEN) ON else OFF
sendCommand("Rollershutter_"+winNum, cmd)
end
I don´t understand how the value winNum with the triggeringItem.name.split("_").get(1) command has to look like, to make my rollershutter go up and down.
I acually don´t understand what the triggeringItem.name.split command do, so i don´t understand the whole rule.
Sorry for beeing annoying, but now i have many and partially big rules and i think, after i know how rules with design Patterns works that would be much easier.
To use triggeringItem you must (for now) put each Item as a separate trigger.
To use the second more generic Rule you have to name your Items so that you can parse the name (the split above) and use the result to build the name of the other associated Item. See the Design Pattern link for details.
Again, see the link to the DP. It is all explained there.
when
Item Kontakt_19 changed
then
val winNum = triggeringItem.name.split("_").get(1)
var cmd = if(triggeringItem.state == OPEN) ON else OFF
sendCommand("Rollershutter_"+winNum, cmd)
end
But i get an error at triggeringItem (cannot be resolved to an item or type)
And if the Type cmd at the sendcommand is without quotes i get the error:
An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null
when
Item Kontakt_19 changed
then
val winNum = triggeringItem.name.split("_").get(1)
var cmd = if(triggeringItem.state == OPEN) UP else DOWN
logDebug("rollok","Rollershutter_"+winNum + cmd)
sendCommand("Rollershutter_"+winNum, cmd)
end
But there is still al litte Problem.
If the rollershutter is up and i open a window, the rollershutter is closing, after i Close the window again.
But the rule should match only when the rollershutter is closed.
How do i get the actual rollershutterstate with the calculated winNUM?
I´ll tried out (although it will not work) to put a && with the rollershutter + winNum after i query the open state of the window.
Here is the rule i tried out. (according to the log cmd is sending “null”)
when
Item Kontakt_1 changed or
Item Kontakt_2 changed or
Item Kontakt_3 changed or
Item Kontakt_4 changed or
Item Kontakt_5 changed or
Item Kontakt_6 changed or
Item Kontakt_7 changed or
Item Kontakt_8 changed or
Item Kontakt_9 changed or
Item Kontakt_10 changed or
Item Kontakt_11 changed or
Item Kontakt_12 changed or
Item Kontakt_13 changed or
Item Kontakt_14 changed
then
val winNum = triggeringItem.name.split("_").get(1)
var cmd = if(triggeringItem.state == OPEN && "Rollo_" +winNum == DOWN) "UP" else "DOWN"
sendCommand("Rollo_"+winNum, cmd)
end
then
val winNum = triggeringItem.name.split("_").get(1)
if (triggeringItem.state == OPEN && "Rollo_"+winNum == DOWN)
sendCommand("Rollo_"+winNum, UP)
end
This rule only sends the UP-command if the roller shutter is down and the window opens.
If you shut the window, nothing happens.
The rule, should recognize the rollershutter state.
So if the rollershutter was closed before, it should close again, after the window is closing again.
If the rollershutter is up nothing should happen.
Is that possible?
My Workaround would be, to Close the rollershutter (after the rule match) after 5 minutes anyway with a sleep command.
This if command doesn´t match - it seems that the state DOWN is not recogniced.
I tried the value decimal, number, string but nothing works.
The rule never fires.
How do i get the actual state of a rollershutter?
My Rollershuter actuator sends active the state in decimal (so 100 is DOWN and 0 UP) but also sends DOWN and UP.
OH also Shows the right state in the Log Files, but how can i query the state in the rule?
thanks for help, but i was not able to get a state out of the changing winNum.
So i solved it with a different way.
That woks fine, but you have to make one rule for each window/rollershutter.
It looks like this:
rule "open Rollershutter with contact "
when
Item Kontakt_1 changed
then
if (Kontakt_1.state == OPEN && Rollo_1.state == 100){ /*If the rollershutter is down and the window opens*/
Rollo_1.sendCommand(UP)
Rollo_Dummy_1.sendCommand(ON)} /*you have to make a dummy item each rollershutter to store the value*/
if (Kontakt_1.state == CLOSED && Rollo_Dummy_1.state == ON) { /*if the dummy value is "on" the Rollershutter is Closing again*/
Rollo_1.sendCommand(DOWN)
Rollo_Dummy_1.sendCommand(OFF) /*The value reset to Off*/
}
end
I have also a rule to open all Rollershutters in the morning a the same time.
With that rule i also reset all Rollershutter Dummy states to OFF (e.g Rollo_Dummy_1.sendCommand(OFF) Rollo_Dummy_2.sendCommand(OFF) so on…)