Using .rules-variable as item label?

Hi! I’ve got a “var Number tParty = 19.5” in my heating.rules. I would like to have a switch on my sitemap that is labeled “Party [value_of_tParty] °C”. Is that possible?

If you have item for that then you can use something like that:

Number MyTemperature "Temperature [%.1f °C]" { someBinding:somevalue }

In general formatting of items is described here:

If you do not have item but rule variable you need to create “virtual” item which will be updated from rule code.

1 Like

If i understand you right, the label besides the switch should be a dynamic one with the temperature. The switch then should start some heating or colling to the desired temperature. Right?


Party 19,0°c (Switch)

I have done simlar thing with fuelstation display in my rules.

Switch item=MyPartySwitch label="Party -,- °C" icon="party"

This should display a switch in your sitemap with the label “Party -,- °C” and a party icon

Now the trick:

rule "Display party temp"
    Item tParty received update
    MyPartySwitch.Label = String::format("Party %.3f °C", tParty.state as DecimalType)

The rule just set the label each time the Number item receives an update.

It think that gives you an idea.


Hi Dibbler42,

just tried for my usecase what you suggested here, but I get an error.

xxx [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘xxx’: org.eclipse.xtext.util.PolymorphicDispatcher$NoSuchMethodException: Couldn’t find method ''assignValue’’ for objects [JvmVoid: (eProxyURI: xxx.rules#xtextLink::, Label , xxx, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@22d20afb, org.eclipse.xtext.util.CancelIndicator$1@d574100]

So “.Label” is not working for my Item.

That is my Code (I set the String Item Gast_Name_UG_Gaestezimmer in a sitemap with a selection)

rule "Gast_Name_UG_Gaestezimmer_changed"
		Item Gast_Name_UG_Gaestezimmer received update
    	g_UG_Gaestezimmer_Rollladen.Label = Gast_Name_UG_Gaestezimmer.state.toString()

Can you help me?

Thanks in advance

maybe help is very simple, just use .label instead of .Label. I check it with my rule and found that i use .label

Did you use the Designer to develop your rules? With ctrl + Space you should be able to browse trough all the options.


Thanks for quick reply.

unfortunately not, tired it, similar error (shame I did not tried it before :slight_smile: . I use the Designer and was wondering why the Content Assist did not show Label nor label. Therefore I asked for help.
Even tried to set a fixed name in rule with no success either.
Also tried a single item instead of a group item, no success, “.label” coud not be resolved. Do I need another import?

Very funny. here are my lines of code and it works like a charme

		for (MapEntry : StationPrices.entrySet.sortBy[value]) {
			// Set the item label to station name
			openHABItems.get(i).label = StationNames.get(MapEntry.getKey())
			// Set price
			if (MapEntry.getValue() != Double.MAX_VALUE) {
				openHABItems.get(i).postUpdate(String::format("%.3f €", MapEntry.getValue()))
			} else {

Which type of item do you use? A Text item? I want to change the label of a Rollershutter, perhaps that is the issue?

Tested it with different single item types (number, switch, string), no success, could not change the label dynamically

I change the labels of string items. Could you post your code again? Maybe we find something

For sure, tried to reduce it:


String	Gast_Name_UG_Gaestezimmer		"Gastname im UG Gästezimmer"	(g_Namen)
Group:Rollershutter:OR(UP,DOWN)	g_UG_Gaestezimmer_Rollladen	"Rollladen Gästezimmer[%d %%]"	<rollershutter>	(g_UG_Rollladen, g_UG_Gaestezimmer)

sitemap to change the guest name:

Selection item=Gast_Name_UG_Gaestezimmer label="Gastname im UG Gästezimmer" icon="info" mappings=["Gast A"="Gast A", "Gast B"="Gast B", "Gästezimmer"="Gästezimmer"]


rule "Gaeste_initialisieren"
	System started
	postUpdate(Gast_Name_UG_Gaestezimmer, "Gästezimmer")

rule "Gast_Name_UG_Gaestezimmer_changed"
		Item Gast_Name_UG_Gaestezimmer received update

sitemap which should show dynamic label:

Switch item=g_UG_Gaestezimmer_Rollladen	mappings=[UP="Hoch", STOP="X", DOWN="Runter"]

I assume you build the items in your rules file, don’t you?
I want to change the label of an existing item

No, the items are not Build in the rule. The items are placeholders for different fuelstation values and i sort the prices and then i need to change the label according to che cheapest station.

Maybe it is a problem with groups. you could try it with a string item. if it work we are one step ahead.


Tried a single item as well, with no success (see post #6 and post 9)

Even found your code on and tried your imports (just to elimimate this even if I didn’t think so)

Hi @Dibbler42,

A very interesting post. I tried applying this logic to have the “lastUpdate” in my item’s label. This is to avoid duplicating all my items (_DateTime update items) and showing the lastUpdate as a separate line on my sitemap.

I tried it like this:

rule "Update label"
    Item Tex_Window_W10_GV_Bureau_Zijkant received update
	// logInfo("Window", Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate)
    // Tex_Window_W10_GV_Bureau_Zijkant.Label = String::format("ABC Raam Bureau zijkant %1$td.%1$tm.%1$tY %1$tT ", Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate)
    Tex_Window_W10_GV_Bureau_Zijkant.Label = String::format("ABC Raam Bureau zijkant %s ", Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate)

However, when the rule is triggered, I get:

2017-05-29 18:03:23.624 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Update label': An error occured during the script execution: Couldn't invoke 'assignValueTo' for feature JvmVoid:  (eProxyURI: test.rules#|::

I’m not sure what I am doing wrong. Or maybe it is just not possible?

Sorry no idea, maybe you should try first to assign a non dynamic string.


Maybe that needs a .toString


I have made some progress.

This seems to do the trick:

rule "Update label"
	Item Tex_Window_W10_GV_Bureau_Zijkant received update
	Tex_Window_W10_GV_Bureau_Zijkant.label = String::format("Last update on %s ", Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate.toString)

The “.toString” was missing and it should be “.label” instead of “.Label”.

The only problem is that I am not getting a nice date format. It is shown as “Last update on 2017-05-30T09:39:44.310+02:00

I tried changing it to:

Tex_Window_W10_GV_Bureau_Zijkant.label = String::format("Last update on %1$td.%1$tm.%1$tY %1$tT ", Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate.toString)

But then I get a “d != java.lang.String”. When I remove the “toString”, I get a “d != org.joda.time.DateTime”.

So how do I get it displayed nicely (e.g. 30-05-2017 09:46)?


I’ve found it! :slight_smile:

Tex_Window_W10_GV_Bureau_Zijkant.label = "Last update on: " + Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate.toDateTime.toString("dd-MM-yy hh:mm")

I want to sort a group of items from largest to smallest and then show this order in a sitemap - perhaps by changing some placeholder items labels and values - your code here looks similar but wondering if you could show an example from start to finish including items/groups, sitemaps and rules?