How does your line 13 and the lines before and after look like ?
I made a little test with this Rule
rule "change item- name"
when
Item Dummy4 changed to ON
then
val vRadiator = radiator_valve_07_Temp.name.replace("_Temp","")
logInfo("change item- name","Name: {}", vRadiator)
val vTriggerItem = triggeringItem.name.replace("4","_new").replace("Dummy","Flummy")
logInfo("change item- name","Name: {}", vTriggerItem)
Dummy4.setLabel("Test4")
end
and used the syntax Scott advised (see Line next to last). And for me it works. But you have to know that your sitemap will nt change directly. You have to refresh it.
Rule 'Raumtemperatur ändert sich': 'setLabel' is not a member of 'java.lang.String'; line 21, column 2, length 30
In line 21:
bmitem.setLabel("Hallo Welt!")
Hole code in rules:
rule "Raumtemperatur ändert sich"
when
Member of gTTermostate changed
then
val bmitem = triggeringItem.name.replace("_T_","_BM_")
sendLogNotification("my BM Item:\n" + bmitem,"radiator","Debug") //all right
bmitem.setLabel("Hallo Welt!") //line 21
end
You are getting the rror because bmitem is not an Item but a String. setLabel is a method of GenericItem. You first need to get the Item (see may second post ).
This is another example of how scripted automation with Jython is easier to use than the DSL…
from core.rules import rule
from core.triggers import when
@rule("Raumtemperatur ändert sich")
@when("Member of gTTermostate changed")
def example_rule(event):
bmitem = event.itemName.replace("_T_","_BM_")
sendLogNotification("my BM Item:\n" + bmitem,"radiator","Debug")
itemRegistry.getItem(bmitem).setLabel("Hallo Welt!")
As Scott said you are dealing with a simple variable(primitive) not with an item and so there’s no method “setLabel” for simple variables.
First to say, it is easier to use Jython an you have a lot more possibilities. I have migrated all my DSL-Rules to Jython and using scripted automation (NGRE/Jython).
So looking on your problem, the DSL-Rule could look:
import org.eclipse.smarthome.model.script.ScriptServiceUtil
rule "change item- name1"
when
Item Dummy4 changed to ON
then
val vTriggerItem = triggeringItem.name.replace("4","5") // find Triggering item name (Dummy4)and change it as you want (Dummy5)
logInfo("change item- name1","Name: {}", vTriggerItem)
var GenericItem bmitem = ScriptServiceUtil.getItemRegistry.getItem(vTriggerItem) as GenericItem // now get the new Item as Generic
bmitem.setLabel("Hello World") // and change the label
logInfo("change item- name1","Name: {}", bmitem)
end