Display concatenated strings in sitemap

Hi everybody
I’m playing around with the System Info binding and I was able to output the system data that I want without issues. How can I concatenate the individual items’ output in a single string? Example:
I have the total memory and the % used as independent values, could it be possible to generate a string with <Total_memory> “/” <Percentage_used> and to show it in the sitemap?
Thanks to all!

Create another Item and a Rule to update that Item with the concatenated String when either one of those other Items changes.

Thanks for the info!
This is indeed what I thought: I created a new String item, a new Text element in the sitemap but I’m stucking at the rules level: could you please drop two indicative lines of code that would help me finding the solution? Thanks!

Combined.postUpdate(Total.state + " " + Percent.state)

I created the following rule:

rule "Concatenate"
when CPU_Load1 changed
then
concat.postUpdate("a"+"b")
end

but I get the error:

2020-04-22 23:33:15.631 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'first.rules' has errors, therefore ignoring it: [18,6]: no viable alternative at input 'CPU_Load1'

Where CPU_Load1 is defined as Number item

Bad syntax

when
   Item CPU_Load1 changed

Hi Rossko!
Thanks for spotting!
I am now able to build the string I wanted, but how can I show the state of the string ‘concat’ in the sitemap?

If I add to my sitemap the line

Text item=CPU_Load1 "CPU usage"

then I see a value.
Can I do this with my concatenated string?

Actually, I can’t display the value of any string using the Text element in the sitemap, irrespective of whether it’s the result of a concatenation. Anyone with similar experiences?

It’s not clear if you are talking about the content of a String type Item. You can only display Items with a sitemap.

The label of any Item contains a format field in square brackets [ ].
Empty brackets means no display of Item state.
Items that are linked to bindings often get a default format supplied by the binding, so you may not need to do anything to display state.
Items solely defined by you however, do what you tell them. No [format], no display.

You can define format in your item definition label
String myItem "my description [%s]" ...
or you can override it in your sitemap line
Text item=myItem label="description [%s]"
%s for showing state as a string is fairly idiot proof, but you can do fancier things too.

What I want to achieve is not to change the label of the item using the status of the string, rather to display the content (maybe I should say ‘the state’) of that string as if it was the value of a Number item.
In one of my previous posts I mentioned that if I include

Text item=CPU_Load1 "CPU usage"

in the sitemap I get a field labelled “CPU usage” and the actual CPU load. What I want to do is to exactly the same but showing a string instead of the CPU load.

Yes. The [format] embedded in the Item label is about displaying the Item state, not about the Item label. Read my post and the docs again.

Thank you Rossko. You guys have so much patience! But I fear that when I will receive my bme280 sensor I will be again here hassling you gurus!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.