Item.name used as Item.name.state

Hello,

my rule should change the light color with the color i stored in an item.
Is it possible to do this with a group.

Without Group (it works):

if (WZ_Haengelampe_Color.state.toString != WZ_Haengelampe_Color_Szene_Speicher.state.toString)
        {
            if(Motion_WZ_Status.state != 11)
            {
                Motion_WZ_Status.sendCommand("10")
            }                
            WZ_Haengelampe_Color.sendCommand(WZ_Haengelampe_Color_Szene_Speicher.state.toString)
        }
        if (WZ_Spotlight_Color.state.toString != WZ_Spotlight_Color_Szene_Speicher.state.toString)
        {
            if(Motion_WZ_Status.state != 11)
            {
                Motion_WZ_Status.sendCommand("10")
            }                
            WZ_Spotlight_Color.sendCommand(WZ_Spotlight_Color_Szene_Speicher.state.toString)
        }

with group (doesn’t work):

    gLampen_WZ_Motion_Einschalten.members.forEach[item | 
        var xxx = item.name
        if (item.state.toString != xxx+"_Szene_Speicher".state.toString)
        {
            if(Motion_WZ_Status.state != 11)
            {
                Motion_WZ_Status.sendCommand("10")
            }                
            item.sendCommand(xxx+"_Szene_Speicher".state.toString)
        }
        ]

That’s just a string. You can’t get the .state of string.

The correct way to do it, is to use a second group for the scene store, too. like this:

gLampen_WZ_Motion_Einschalten.members.forEach[item | 
	val Speicher = gLampen_Szene_Speicher.members.filter[i| i.name.contains(item.name)].head
	if(item.state.toString != Speicher.state.toString) {
		if(Motion_WZ_Status.state != 11) {
			Motion_WZ_Status.sendCommand("10")
		}
		item.sendCommand(Speicher.state.toString)
	}
]
1 Like

It works. Thank you so much.

gLampen_Szene_Speicher.members.forEach[item | 
        val Speicher = gLampen_WZ_Motion_Einschalten.members.filter[i| i.name.contains(item.name)].head
            item.sendCommand(Speicher.state.toString)
        ]

if I try it this way, to save the lamps color, it doesn’t work. What do i have to change?

Well, I used a shortcut here :slight_smile: The name of the Item that holds the value contains the whole name of the item which shall be set.
this is a oneway function for sure…
But as you know the last part of the name is “_Szene_Speicher” and there is no other Item which is identical to the first part of the name, you can use the reverse function:

val Speicher = gLampen_WZ_Motion_Einschalten.members.filter[i| item.name.contains(i.name)].head
1 Like