String manipulation in rules

Try declaring windowName as a variable at the top of the file (Before all the rules)

var String windowName = ""

rule "Rolladen Wohnzimmer schliessen"
when 
    Item EG_wz_switch_3_long received update OFF
then
  gH_Rolladen_wz_switch.members.forEach[rs|
    var nameParts = rs.name.split("_")
    windowName = nameParts.get(0) + "_" + nameParts.get(1) + "_fk_" + nameParts.get(3)
    logInfo ("Fensterkontakt der offen is:", windowName)
        if(gH_Contact_global.members.filter [fk | fk.name == windowName].head.state != OPEN){
           postUpdate(rs,DOWN)
           }]
end

Thanks Vincent for your answer.

Still getting the same error:

20:53:41.324 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Rolladen Wohnzimmer schliessen': 3

At the moment I save the rule, follwoing appears in the log:

20:52:51.958 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'Rolladen.rules', using it anyway:
This expression is not allowed in this context, since it doesn't cause any side effects.
``

Any more on the log about that error?

postUpdate(rs.name.toString,"DOWN")

This one, when saving the rule:

20:52:51.958 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'Rolladen.rules', using it anyway:
This expression is not allowed in this context, since it doesn't cause any side effects.

No idea, how to get more details…

Still the same. Sorry…

You are using a Lambda inside a Lambda…
let’s add another var at the begining

var String windowName = ""
var String rsString = ""

and the rule:

rule "Rolladen Wohnzimmer schliessen"
when 
    Item EG_wz_switch_3_long received update OFF
then
  gH_Rolladen_wz_switch.members.forEach[rs|
    var nameParts = rs.name.split("_")
    rsString = rs.name.toString
    windowName = nameParts.get(0) + "_" + nameParts.get(1) + "_fk_" + nameParts.get(3)
    logInfo ("Fensterkontakt der offen is:", windowName)
        if(gH_Contact_global.members.filter [fk | fk.name == windowName].head.state != OPEN){
           postUpdate(rsString, "DOWN")
           }]
end

Hey Vincent,

I would be happy to say, that your code solved the problem, but still -

[ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Rolladen Wohnzimmer schliessen': 3

Any other idea - I am fully lost here…

Does the rule run?
Are there any lines after that error message in the log?

What are the items in the group gH_Contact_global?

I don’t think so - as I don’t receive any update from logInfo, which I build in.

No - nothing, except the errors I listed above.

Here is the full log of the rule:

13:33:25.462 [INFO ] [smarthome.event.ItemStateChangedEvent] - EG_wz_switch_3_long changed from OFF to ON
13:33:25.528 [INFO ] [smarthome.event.ChannelTriggeredEvent] - homematic:HG-HM-PB-6-WM55:3#PRESS triggered LONG
13:33:25.604 [INFO ] [smarthome.event.ChannelTriggeredEvent] - homematic:HG-HM-PB-6-WM55:3#PRESS triggered LONG
13:33:25.682 [INFO ] [smarthome.event.ChannelTriggeredEvent] - homematic:HG-HM-PB-6-WM55::3#PRESS triggered LONG_RELEASE
13:33:27.206 [INFO ] [smarthome.event.ItemStateChangedEvent] - homematic_HG_HM_PB_6_WM55_3_PRESS_LONG changed from ON to OFF
13:33:27.306 [INFO ] [smarthome.event.ItemStateChangedEvent] - EG_wz_switch_3_long changed from ON to OFF
13:33:34.063 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Rolladen Wohnzimmer schliessen': 3

The group of gH_Contact_global contains just a simple set of Homeatic windows contacts:

Contact EG_wz_fk_tuer "Fensterkontakt Wohnzimmertür" <window> (gEG_wz,gH_Contact_global) {channel="homematic:HG-HM-Sec-SC:1#STATE"}
Contact OG1_sz_fk_tuer "Fensterkontakt Schlafzimmertür" <window> (gOG1_sz,gH_Contact_global) {channel="homematic:HG-HM-Sec-SC:1#STATE"}
Contact OG1_ak_fk_tuer "Fensterkontakt Ankleidezimmertür" <window> (gOG1_ak,gH_Contact_global) {channel="homematic:1#STATE"}

Thanks for your effort so far

Try:

sendCommand(rsString, "DOWN")

instead of:

postUpdate(rsString, "DOWN")

I meant to ask the items of the group gH_Rolladen_wz_switch, please

Already tried - same result.

Within the group gH_Rolladen_wz_switch are following items:

Rollershutter EG_az_rs_fenster "Rollade Spielzimmer" <rollershutter> (gEG_az,gEG_Rolladen_wz) ["Lighting"] {channel="homematic:HG-HM-LC-Bl1PBU-FM:1#LEVEL"}
Rollershutter EG_wz_rs_seite "Rollade Wohnzimmer Seite" <rollershutter> (gEG_wz,gEG_Rolladen_wz) ["Lighting"] {channel="homematic:HG-HM-LC-Bl1PBU-FM:1#LEVEL"}
Rollershutter EG_wz_rs_tuer "Rollade Wohnzimer Tür" <rollershutter> (gEG_wz,gEG_Rolladen_wz) ["Lighting"] {channel="homematic:HG-HM-LC-Bl1PBU-FM:1#LEVEL"`

There is an error at the end of the third one:

Rollershutter EG_wz_rs_tuer "Rollade Wohnzimer Tür" <rollershutter> (gEG_wz,gEG_Rolladen_wz) ["Lighting"] {channel="homematic:HG-HM-LC-Bl1PBU-FM:1#LEVEL"}

Sorry Vincent, happend, when I paste and copy it into this topic. The line looks like you described.

Rollershutters work fine, also if I trigger them via another rule i.e.:

rule "Rolladen Wohnzimmer öffnen"
when 
    Item EG_wz_switch_3_short received update ON
then
    gH_Rolladen_wz_switch.members.forEach[ra | sendCommand(ra,UP)] 
end

The error comes from somewhere else - any chance to get are more detailed log?

gH_Rolladen_wz_switch.members.forEach[ra | sendCommand(ra.name.toString,"UP")]

Maybe try changing the UP and DOWN commands to 0 and 100

If you use snapshot try

gH_Rolladen_wz_switch.members.forEach[ ra | sendCommand(ra,UP)]

Hello Dominik,

I think that your rule in post 14 was quite correct, except the +windowName as @hr_2 pointed out and split("_") as @vzorglub flagged. But the issue is that in post 21 you replaced val windowName by var windowName. That was the meaning of the cryptic sentence of @hr_2 : “Cannot refer to the non-final variable windowName inside a lambda expression”. val introduces a final variable and var a non-final variable (cf. : http://www.eclipse.org/xtend/documentation/203_xtend_expressions.html#variable-declaration ).
I made a little simulation to test your rule :

Items :

Group gH_Contact_global
Group gH_Rolladen_wz_switch
Contact EG_wz_fk_tuer "Fensterkontakt Wohnzimmertür"  (gH_Contact_global)
Contact OG1_sz_fk_tuer "Fensterkontakt Schlafzimmertür"  (gH_Contact_global)
Contact OG1_az_fk_tuer "Fensterkontakt Ankleidezimmertür"  (gH_Contact_global)


Rollershutter  EG_wz_rs_tuer "Rollade Wohnzimer Tür"  (gEG_Rolladen_wz,gH_Rolladen_wz_switch)
Rollershutter OG1_sz_rs_tuer  "Rollade Schlafzimmertür"    (gH_Rolladen_wz_switch)
Rollershutter  OG1_az_rs_tuer  "Rollade Ankleidezimmertür"   (gH_Rolladen_wz_switch)

Switch EG_wz_switch_3_long

Rules:

rule "Test_ON (prepares simulation)"
when 
	Item Declenche_switch changed to ON
then 
    EG_wz_switch_3_long.postUpdate(ON)
    EG_wz_fk_tuer.postUpdate(CLOSED)
    OG1_sz_fk_tuer.postUpdate(OPEN)
    OG1_az_fk_tuer.postUpdate(CLOSED)

    EG_wz_rs_tuer.postUpdate(UP)
    OG1_sz_rs_tuer.postUpdate(UP)
    OG1_az_rs_tuer.postUpdate(UP)
end

rule "Test_OFF"
when 
	Item Declenche_switch changed to OFF
then 
    EG_wz_switch_3_long.postUpdate(OFF)
end 

rule "Rolladen Wohnzimmer schliessen"
when 
    Item EG_wz_switch_3_long received update OFF
then
    gH_Rolladen_wz_switch.members.forEach[rs|
    var nameParts = rs.name.split("_")
    val windowName = nameParts.get(0) + "_" + nameParts.get(1) + "_fk_" + nameParts.get(3)
    logInfo("DEBUG", "windowname = " + windowName)
    //logInfo ("Fensterkontakt der offen is:", windowName)
        if (gH_Contact_global.members.filter [fk | fk.name == windowName].head.state != OPEN){
           logInfo("DEBUG", "Fensterkontakt " + windowName + " is CLOSED")
           postUpdate(rs,DOWN)
           }
           else {
               logInfo("DEBUG", "Fensterkontakt " + windowName + " is OPEN")
           }]
end

Results (when Declenche_switch is moved to OFF on my sitemap):

2018-03-27 17:51:50.271 [INFO ] [eclipse.smarthome.model.script.DEBUG] - windowname = OG1_sz_fk_tuer
2018-03-27 17:51:50.276 [INFO ] [eclipse.smarthome.model.script.DEBUG] - Fensterkontakt OG1_sz_fk_tuer is OPEN
2018-03-27 17:51:50.279 [INFO ] [eclipse.smarthome.model.script.DEBUG] - windowname = OG1_az_fk_tuer
2018-03-27 17:51:50.283 [INFO ] [eclipse.smarthome.model.script.DEBUG] - Fensterkontakt OG1_az_fk_tuer is CLOSED
2018-03-27 17:51:50.288 [INFO ] [eclipse.smarthome.model.script.DEBUG] - windowname = EG_wz_fk_tuer
2018-03-27 17:51:50.291 [INFO ] [eclipse.smarthome.model.script.DEBUG] - Fensterkontakt EG_wz_fk_tuer is CLOSED

events.log:

2018-03-27 17:51:50.266 [ItemStateChangedEvent     ] - EG_wz_switch_3_long changed from ON to OFF
2018-03-27 17:51:50.286 [ItemStateChangedEvent     ] - OG1_az_rs_tuer changed from 0 to 100
2018-03-27 17:51:50.294 [ItemStateChangedEvent     ] - EG_wz_rs_tuer changed from 0 to 100

You can see that the two contacts OG1_az_rs_tuer and EG_wz_rs_tuer receive the command DOWN (=100).

Another thing to take care of :
in your post 33, I don’t see gH_Rolladen_wz_switch as a group name the Rollershutters belong to :

Rollershutter EG_az_rs_fenster "Rollade Spielzimmer" <rollershutter> (gEG_az,gEG_Rolladen_wz) ["Lighting"] {channel="homematic:HG-HM-LC-Bl1PBU-FM:1#LEVEL"}
Rollershutter EG_wz_rs_seite "Rollade Wohnzimmer Seite" <rollershutter> (gEG_wz,gEG_Rolladen_wz) ["Lighting"] {channel="homematic:HG-HM-LC-Bl1PBU-FM:1#LEVEL"}
Rollershutter EG_wz_rs_tuer "Rollade Wohnzimer Tür" <rollershutter> (gEG_wz,gEG_Rolladen_wz) ["Lighting"] {channel="homematic:HG-HM-LC-Bl1PBU-FM:1#LEVEL"`

Best regards.

Edit: I left the postUpdate for the simulation, but

sendCommand(rs,DOWN)

is probably necessary.

Hello Alain,

Thanks for your detailed help - really appreciated.

I tried your comments and unfortunately I run into the same error. As I could see, that at your end everything works well, I took your scripts and copied them into my ‘test’-environment as well.

I copied them 1:1 except, that I enlarged all items,names and groups with ‘_test’ to avoid having double entries with the same name.

I trigger the switch, I receive the following message in the log:

11:11:17.481 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Declenche_switch' received command OFF
11:11:17.535 [INFO ] [.eclipse.smarthome.model.script.DEBUG] - windowname = EG_wz_fk_tuer_test
11:11:17.637 [INFO ] [smarthome.event.ItemStateChangedEvent] - Declenche_switch changed from ON to OFF
11:11:17.796 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Rolladen Wohnzimmer schliessen': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.items.Item.getState() on null
11:11:17.923 [INFO ] [smarthome.event.ItemStateChangedEvent] - EG_wz_switch_3_long_test changed from ON to OFF

Still not working, but new error.

Thanks for help in advance.
Dom