[SOLVED] 'state' is not a member of 'java.lang.Iterable

  • Platform information:
    • Hardware: Rpi 2
    • OS: openhabian
    • Java Runtime Environment: openjdk version “1.8.0_222”
    • openHAB version: 2.5.0-1

I have a problem with a rule / group filtering:

 rule "Heating - Check Demand"
                    Member of Heating_temps changed
                    or Member of Heating_setpoints changed
    		if (Heating_Main_Switch.state == ON) {
                                    val String baseName = sp.name.split("_").get(0)+"_"+sp.name.split("_").get(1)
                                    var current_temp = Heating_temps.allMembers.filter[m|m.name.startsWith(baseName)].state as Number
                                    var currentSetpoint = sp.state as Number

The ‘var current_temp =’ line always throw the following error:

Rule 'Heating - Check Demand': 'state' is not a member of 'java.lang.Iterable<org.eclipse.smarthome.core.items.Item>'; line 32, column 52, length 68

Items in Group Heating_temps are configured in Paper UI. Here is one of them’s config:

I have tried different solutions but without success.
Any help is appreciated.

var current_temp = Heating_temps.allMembers.filter[m|m.name.startsWith(baseName)].state

Change that to

var current_temp = Heating_temps.allMembers.filter[m|m.name.startsWith(baseName)].head.state

You are trying to get the state on the iterator object (so all the filtered items), that won’t work without reducing or summing, or just picking the head.

Or use findFirst instead of filter.

Or just go directly to the Item…

Thank you, this works like a charm. :wink: