[SOLVED] Help with rule and case selection

Hi i am using OH2 on win 10
i need help with a Rule.
In the following Rule i have to update 3 Items depending wich room changes temperature.
Temperature sensors are all in group (temp)
Now i want to update the value of the items that show the temperature in sitemap.
items in sitemap are :
SolltemperaturWz
SolltemperaturSz
SolltemperaturBad
The Items are also in a Group (gTemp_show)
My question is how can i shorten the rule to update group members of gTemp_show without case selection.
My rule is working good but i would like a rule without case selection to avoid to add lines when i add another sensor.

Here is my rule
Thank you for your help.

rule "Change Temp Label in Rooms" 
    when   
   		  Member of temp received update
   		 
    then   
			 var Number sollTW = (triggeringItem.state)
			 switch(triggeringItem.name) {
      			case "Aquara_Temp_Wohn": {
		  			SolltemperaturWz.sendCommand(sollTW)
              		logInfo("Rulesxxxxxxxxxxxxx", "Soll_Temperatur_"+ triggeringItem.name +" value updated to: " + sollTW)
									      }
      case "Aquara_Temp_Schlaf": {
		  SolltemperaturSz.sendCommand(sollTW)
              		logInfo("Rulesxxxxxxxxxxxxx", "Soll_Temperatur_"+ triggeringItem.name +" value updated to: " + sollTW)
             
      }
      case "Aquara_Temp_Bad": {
		  SolltemperaturBad.sendCommand(sollTW)
              		logInfo("Rulesxxxxxxxxxxxxx", "Soll_Temperatur_"+ triggeringItem.name +" value updated to: " + sollTW)
            
				      }
			}
end

ces

If the ending of your triggering items would be named like: *_WZ, *_Sz and *_Bd you could split those endings from the triggeringItem.name and use it like:

sendCommand("Solltemperatur"+Ending, ´sollTW)

The SolltemperaturBad would also need to be renamed to SolltemperaturBd!

iI am sorry but i get an error on the logs
I changed my rule in

rule "Change Temp Label in Rooms" 
    when   
   		  Member of temp received update
   		 
    then   
			 var Number sollTW = (triggeringItem.state)
			 val  ending = triggeringItem.name.split("_").get(2)
			 val  item = "Solltemperatur_"+ending
			logInfo("Rulesxxxxxxxxxxxxx", item +" value updated to: " + sollTW)
			 sendCommand(item, sollTW)

now i get in logs

10:15:16.924 [INFO ] [thome.model.script.Rulesxxxxxxxxxxxxx] - Solltemperatur_Sz value updated to: 25.34
10:15:16.926 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Change Temp Label in Rooms': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

Any other advice?

Add more logging:
And don’t use the variable name item

rule "Change Temp Label in Rooms" 
when   
    Member of temp received update
then   
    var Number sollTW = triggeringItem.state as Number
    logInfo("NUMBER: ", sollTW.toString)
    val  ending = triggeringItem.name.split("_").get(2)
    logInfo("NAME:", ending)
    val  itemName = "Solltemperatur_"+ending
    logInfo("ITEM:", itemName)
    logInfo("Rulesxxxxxxxxxxxxx", item +" value updated to: " + sollTW)
    sendCommand(item, sollTW)

Sorry same error

10:56:44.215 [INFO ] [smarthome.event.ItemStateChangedEvent] - Aquara_Temp_Sz changed from 26.14 to 26.2
10:56:44.216 [INFO ] [lipse.smarthome.model.script.NUMBER: ] - 26.2
10:56:44.217 [INFO ] [smarthome.event.ItemStateChangedEvent] - mihome_sensor_weather_v1_158d0002c148f7_temperature changed from 26.14 �C to 26.2 �C
10:56:44.217 [INFO ] [.eclipse.smarthome.model.script.NAME:] - Sz
10:56:44.218 [INFO ] [.eclipse.smarthome.model.script.ITEM:] - Solltemperatur_Sz
10:56:44.219 [INFO ] [thome.model.script.Rulesxxxxxxxxxxxxx] - Solltemperatur_Sz value updated to: 26.2
10:56:44.220 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Change Temp Label in Rooms': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java```
sendCommand(itemName, sollTW.toString)
1 Like
sendCommand(itemName, sollTW.toString)

Thanks for your help.
The parameter toString was the problem.
Now it seems to work.

But it´s a strange behavior because

Solltemperatur_Sz.sendCommand(sollTW)

worked.
But if this is the solution i am pleased.

This is normal, nithing strange here:

The action `sendCommand(itemName, value) takes strings as arguments

The method item.sendCommand(value) takes any value accepted by the item type.

See:

1 Like

Perfect.
Thank you for this advice.
now i understand the difference.