[Solved] Type cast problem in rule

I’m using that for getting the item that triggered my rule. That works fine.
val vent = gIrrVents.members.findFirst[name.equals(triggeringItem.name)]

Unfortunately I cannot set the label anymore because vent is now an item not a switch anymore. I tried to “cast” it to another variable but that doesn’t work.
vent.label = “test” <- not allowed anymore
var switch v = vent <- not allowed

I’m still looking for a detailed and complete class/method overview but cannot find a detailed version. So please, can anyone help me. Thank you

I do not really understand your approach. From the use of triggeringItem i see that you are using the new group commands. So triggeringItem is the item taht triggered the rule and with your members… you select from the group of Vents the one with the name of the triggeringItem. That should be the triggering item.

It should be possible to set the label like that

triggeringItem.label = "New Labeltext"

i do that on the latest build of openhab with the following line

(GRP_PlantStatus.members.filter[ i | i.name == groupIdentifier+"_Status" ].head as NumberItem).label = String::format("%s (%s)", plantName, plantLocation)

This worked like a charm. In addition i suggest to specify the item types. so vent should be a SwitchItem

Hope this helps

Thomas

The triggeredItem works. I can access it, yes. However, I cannot change the label text of it anymore. The Smarthome Designer shows an error and if I ignore that, the label doesn’t change anymore and I get the following error in the log file.

-> An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid

However, your variant works. The cast is correct. Thank you!

Solution: The cast statement was missing. Correct code line would be:



val vent = gIrrVents.members.findFirst[name.equals(triggeringItem.name)] as SwitchItem
or
val vent = gIrrVents.members.filter[ i | i.name == triggeringItem.name ].head as SwitchItem