Rule for counting open windows: The argument 'state' must not be null or empty

Hey there,

just trying to create my first rule and getting the same error every time the rule is triggered:

I want to count all closed windows in the group gFenster.

The items are defined:
Group gFenster

    Contact KEG_Fenster "Fenster" (gFenster)  { channel="homematic:HM-Sec-SC-2:LiNaDo_ID:LEQ0175072:1#STATE"}
    Contact GEG_Fenster "Fenster" (gFenster) {channel="homematic:HM-Sec-SCo:LiNaDo_ID:MEQ0723287:1#STATE"}
    Contact WEG_Fenster_V "Fenster" (gFenster) { channel="homematic:HM-Sec-SCo:LiNaDo_ID:MEQ0723295:1#STATE"}

Here is my rule:

rule "AnzFenster"
when
Item gFenster received update
then
val numOpened = gFenster.members.filter(contact | contact.state == CLOSED).size
gFenster.postUpdate(numOpened)

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


end

The log gives me the following errors:

2017-01-18 18:54:50.843 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'AnzFenster': The argument 'state' must not be null or empty.
2017-01-18 18:55:53.910 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'LiNaDo.rules'
2017-01-18 18:55:54.128 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'KEG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.132 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'GEG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.136 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'WEG_Fenster_V'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.140 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'WEG_Fenster_L'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.144 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'BOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.147 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'SOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.151 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'LOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.155 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'AOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.218 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'LiNaDo.rules'
2017-01-18 18:55:54.469 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'KEG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.473 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'GEG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.477 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'WEG_Fenster_V'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.481 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'WEG_Fenster_L'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.485 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'BOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.489 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'SOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.493 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'LOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:55:54.496 [WARN ] [.rule.jvmmodel.RulesJvmModelInferrer] - Duplicate field: 'AOG_Fenster'. Ignoring 'org.eclipse.smarthome.core.library.items.ContactItem'.
2017-01-18 18:57:22.237 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state == UNDEF

Could anyone help me, what I´m doing wrong?

Greetings Dominic

You might like to think about what you expect to happen when you post a number value to a group of Contacts ; what is the group going to do with that? I’d have a separate Number item for counting.

Having said that,it looks like your .size is not giving aresult and I cannott see why not.

It is possible that one or more of your Contacts has not received an update yet?

Try

val numOpened = gFenster.members.filter[contact | contact.state != NULL].filter[contact | contact.state == CLOSED].size

And I’m with @rossko57, what are you trying to accomplish by sending a Number to gFenster? When you sendCommand or postUpdate to a Group, that command/update gets passed on to all the members.

Have you tried defining your Group as:

Group:Number:SUM gFenster

If you put that on your sitemap as a Text I think it will show the count of the number of open windows. If I’m right and this works, you can simply get the count from the Group’s state.

Hi Rich,

thank you very much. I tried your hint and edited my rule as the following:

rule "AnzFenster"
when
Item gFenster received update
then

val numClosed = gFenster.members.filter[contact | contact.state != NULL].filter[contact | contact.state == CLOSED].size
//val numOpenend= gFenster.members.filter[contact | contact.state != NULL].filter[contact | contact.state == OPEN].size

sendCommand(FensterG, numClosed)
//FensterO.sendCommand(numOpenend)

 //logInfo("Fensterkontakte", "Fensterkontakte state offen == " + numOpened) 
  logInfo("Fensterkontakte", "Fensterkontakte state cloesed== " + numClosed) 
 end

The problem is, that my logs show me an an infinity loop:

2017-01-20 22:19:30.413 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:30.712 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:31.015 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:31.319 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:31.617 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:31.916 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:32.240 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:32.539 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:32.839 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:33.146 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:33.451 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:33.810 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:34.112 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:34.438 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:34.767 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:35.066 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:35.381 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:35.676 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:35.992 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:36.308 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:36.624 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 22:19:36.927 [INFO ] [arthome.model.script.Fensterkontakte] - Fensterkontakte state cloesed== 8
2017-01-20 2

Do you have another hint for me?

Yes, and I had this hint above too.

There is absolutely no reason you should be calling sendCommand(FensterG, numClosed). It makes no sense to send a command to a Group of Contacts cannot be commanded.

When you send a command or post an update to a Group that command or update gets passed on to all the members of the Group.

If you want the Group’s state to be the number of open windows you cannot do it by sending the number to the Group.

As I said above, Define your Group as Group:Number:SUM gFenster and eliminate the sendCommand.

You are in an infinite loop because on every update to gFenster you send a command to it which results in more updates which trigger the rule and so on.

To be fair, we don’t know what FensterG actually is, that is getting sent the command. Guess it also a member of the group though? Or it is a group including gFenster? Either way the command-update loop is expected.

Based on the code, gFenster is the group containing the contacts.