Sending a state to an item, after splitting the state item

Hey, i hope you guys can help me. I want my radiators to turn off, whenever my window opens. My windowsensors (switches, no contacts) are all in a group.

windowsensors.items

Switch Window_RoomA (gWindows)
Switch Window_RoomB (gWindows)
Switch Window_RoomC (gWindows)

radiators.items

Number Temperature_RoomA
Number Temperature_RoomB
Number Temperature_RoomC

Number TemperatureWhenWindowOpen_RoomA
Number TemperatureWhenWindowOpen_RoomB
Number TemperatureWhenWindowOpen_RoomC

I want to do all this with only ONE rule. I would like to NOT use val or vars. (If its possible)

rule WindowRadiator
when
    Member of gWindows changed to ON
then
    ("Temperature_" + triggeringItemName.split('_').get(1)).sendCommand(("TemperatureWhenWindowOpen_" + triggeringItemName.split('_').get(1)).state as DecimalType)
end

I tried different things like. toString or “as Text” and stuff. Always getting errors like: “Could not cast TemperatureWhenWindowOpen_RoomA to void” or “.state is not a member of String” and stuff like that.

logInfo(“Trigger”, "Item is: " + triggeringItemName.split(‘_’).get(1)) always give me the correct Room (RoomA, RoomB or RoomC)

Hope someone can help me with an easy fix :slight_smile:

That just makes it difficult for you to manage and debug. They do not cost you anything.

Okay, that is a string

Strings do not have a .sendCommand() method.

There is a sendCommand("someItem", "someCommand") Action, you would need to give that two strings as arguments.

That’s a string as well.

Strings do not have a .state method.

Not so easy to work around this time, you need the technique to get hold of an Item object from its itemname string

1 Like

In addition to rossko57: There is no implicit var named triggeringItemName in rules that are triggered by Member of.
To be honest, it’s a bit difficult:

triggeringItem → the actual Item which triggered the Member of
triggeringItemName → the name of the item which triggered the rule when using Item as trigger (as a String Object).
As all of your window contacts are already in a group, please consider to also put the other two types of items in additional groups:

rule "Window Radiator"
when
    Member of gWindows changed to ON
then
    gTemperatures.members.filter[i|i.name.endsWith(triggeringItem.name.split("_").get(1))].
        heaad.sendCommand(gTemperatureWhenWindowOpen.members.filter[j|j.name.endsWith(triggeringItem.name.split("_").get(1))].head.state as DecimalType)
end

or way more readable (with val)

rule "Window Radiator"
when
    Member of gWindows changed to ON
then
    val strRoom = triggeringItem.name.split("_").get(1)
    val myTemperatureItem = gTemperatures.members.filter[i|i.name.endsWith(strRoom)].head
    val myOldTemperature = gTemperatureWhenWindowOpen.members.filter[j|j.name.endsWith(strRoom)].head.state.toString
    myTemperatureItem.sendCommand(myOldTemperature)
end

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.