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::0.2.4.2.0.0::0::/2), 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"
when
Item Gast_Name_UG_Gaestezimmer received update
then
g_UG_Gaestezimmer_Rollladen.Label = Gast_Name_UG_Gaestezimmer.state.toString()
end
unfortunately not, tired it, similar error (shame I did not tried it before . 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 {
openHABItems.get(i).postUpdate("geschlossen")
}
i++
}
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
rule "Gaeste_initialisieren"
when
System started
then
{
postUpdate(Gast_Name_UG_Gaestezimmer, "Gästezimmer")
}
end
rule "Gast_Name_UG_Gaestezimmer_changed"
when
Item Gast_Name_UG_Gaestezimmer received update
then
g_UG_Gaestezimmer_Rollladen.label=Gast_Name_UG_Gaestezimmer.state.toString()
end
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.
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"
when
Item Tex_Window_W10_GV_Bureau_Zijkant received update
then
// 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)
end
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#|::0.2.2.2.0.1::0::/2)
I’m not sure what I am doing wrong. Or maybe it is just not possible?
rule "Update label"
when
Item Tex_Window_W10_GV_Bureau_Zijkant received update
then
Tex_Window_W10_GV_Bureau_Zijkant.label = String::format("Last update on %s ", Tex_Window_W10_GV_Bureau_Zijkant.lastUpdate.toString)
end
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 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?
OK, here is the full example using the tankerkoenig binding. Idea is to get fuel prices and display them in a sorted order or display “closed” if the station is closed.
To achieve that i defined item to hold the actual price, item with the information if station is closed and display items. the rule iterates trough the prices copy them to a map that will be sorted and then transferred to the display items (with korrekt label).
Here are items, rules, transformations and sitemaps. Items
import java.util.ArrayList
import java.util.Map
import java.util.HashMap
//------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Rule: Retrieve and process fuel station information
//
//------------------------------------------------------------------------------------------------------------------------------------------------------------
rule "Retrieve and process fuel station information"
when
System started or
Time cron "0 0/15 * * * ?" or // Every 15 min.
Item VT_FuelStation_Source received update
then
val Map <String, Double> PriceMap = new HashMap<String, Double>() // Price map = Station name -> gas price
var ArrayList<StringItem> DisplayItems = new ArrayList<StringItem>()
var Integer i
VT_FuelStation_LastUpdate.postUpdate(new DateTimeType())
// Build map with prices
VT_FuelStation_Source?.members.forEach[ PriceItem |
if (PriceItem.state != NULL) {
PriceMap.put(PriceItem.label, (PriceItem.state as DecimalType).doubleValue)
} else {
PriceMap.put(PriceItem.label, 0.0)
}
]
// Build array with display items
DisplayItems.add(0, VT_Display_Fuelstation_1)
DisplayItems.add(1, VT_Display_Fuelstation_2)
DisplayItems.add(2, VT_Display_Fuelstation_3)
DisplayItems.add(3, VT_Display_Fuelstation_4)
DisplayItems.add(4, VT_Display_Fuelstation_5)
DisplayItems.add(5, VT_Display_Fuelstation_6)
// Combine prices with display items
i = 0
for (PriceEntry : PriceMap.entrySet.sortBy[value]) {
// Set the label of the display items
DisplayItems.get(i).label = PriceEntry.getKey()
// Set price according to label of display items
if (PriceEntry.getValue() != 0.0)
{
DisplayItems.get(i).postUpdate(String::format("%.3f €", PriceEntry.getValue()))
} else {
DisplayItems.get(i).postUpdate("Geschlossen")
}
// Switch to next display items
i = i+1
}
end
Sitemap
Text item=VT_Display_Fuelstation_1 icon="scene_gas_station" {
Text item=VT_FuelStation_LastUpdate label="Letztes Update [%1$tH:%1$tM]" icon="time_clock"
Text item=VT_Display_Fuelstation_1 icon="scene_gas_station"
Text item=VT_Display_Fuelstation_2 icon="scene_gas_station"
Text item=VT_Display_Fuelstation_3 icon="scene_gas_station"
Text item=VT_Display_Fuelstation_4 icon="scene_gas_station"
Text item=VT_Display_Fuelstation_5 icon="scene_gas_station"
Text item=VT_Display_Fuelstation_6 icon="scene_gas_station"
}
And thats it. Any optimizations and changes are welcome.