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
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
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)