How to "add" multiple items into one sitemap string

Hi guys,

I have a very simple question, but somehow did not find an answer yet.
In my sitemap I would like to display the following line:
“Date: 30.11.2015 (Autumn)”
I have two items: first one is “myDate” the second is “mySeason”.
In the sitemap I tried somethink like this, but the Designer complains about it:

Text item=myDate + “(” + mySeason +")"

How do I need to concatinate those strings?
Thanks a lot.

You will have to create another (string) item that is only used for the UI and then create a rule to concatenate your two strings into the new one.

There is an example on the Wiki that you may build upon:

Thanks for the fast reply.
I’ll try use this example. It seems to be a little over complicated to create a meaningful string, but if this is the only way to do it I give it a try.

Happily, you don’t need the linked code for your purpose.
in .items:

Date myDate ... {...}
String mySeason ... {...}
String myFullDate "Date: [%s]" //no Binding needed

in .rules:

rule "update myFullDate"
when
    Item myDate updated //or
    // Item mySeason updated // not needed, every time season changes, date changes too :) 
then
    myFullDate.postUpdate(myDate.state.toString + "(" + mySeason.state + ")") //mySeason should be string already
end

Now in sitemap you only need to use myFullDate.

3 Likes

Oh yes this is simpler. Thanks!

One more question - in my item definition I can “translate” the item state to a readable state.
e.g. with
String mySeason “Jahreszeit [MAP(season.map):%s]”
the season gets translated into German. How can I do the same thing within a rule.
The mySeason.getState() (or state) returns “Autumn” = which I now want to map to “Herbst”.
Similar thin applies to myDate - I need to cut the time off similar to what I do in Item definition “Datum [%1$tA, %1$td.%1$tm.%1$tY]”
Thanks for the help.
(The rule works already!)

In a rule, it’ll be something like:

var mappedSeason = transform("MAP", "season.map", mySeason.state.toString)

“Can’t resolve reference to … ‘transform’” - does anyone have a working example in which he manipulates a string with similar logic like in item definition.
(FYI - I tried to import like this:
import org.openhab.core.transform.actions.Transformation.transform
or
import org.openhab.core.transform.actions.*
which did not help.
)

Thanks.

The Designer does not recognize the transform action, but it still works when used – no import statements needed.

I fixed that and the fix will appear in openHAB 1.8.

Oh OK - great!

Hopefully my final question how do I make out of a Datetime item a String “Monday, 30.11.2015” in my rule?
The item is defined as this:
DateTime myDate “Datum [%1$tA, %1$td.%1$tm.%1$tY]” { ntp=“Europe/Berlin:de_DE” }
Beeing a little naiv and using transform like this:
var mappedDate = transform("[%1$tA, %1$td.%1$tm.%1$tY]",myDate.getState())
Did not do the job. I see “Error during the execution of rule ‘update Datum_Saison’: Index: 2, Size: 2”.
Any idea on this?

OK - I now found the solution. Since it took me a while and thanks to the help of the writers above my sitemap now shows the current date as well as the current season.
What is needed to do this?

  1. Have the Astro binding as well as the NTP binding installed.

  2. Item definition:
    DateTime Datum “Datum [%1$tA, %1$td.%1$tm.%1$tY]” { ntp=“Europe/Berlin:de_DE” }
    String Datum_Saison “Datum [%s]”
    String Season_Name_Ger “Jahreszeit [MAP(season.map):%s]” {astro=“planet=sun, type=season, property=name”}

  3. Rule (no extra import required)
    /**

  • Anzeige Datum mit Saison
    */
    rule “update Datum_Saison”
    when
    Item Datum received update
    then
    var mappedSeason = transform(“MAP”, “season.map”, Season_Name_Ger.state.toString)
    Datum_Saison.postUpdate(Datum.getState().format("[%1$tA, %1$td.%1$tm.%1$tY]") + “(” + mappedSeason + ") ")
    end
  1. Sitemap - have an entry like this at the place you thik it fits best:

Frame label=“Datum” {
Text item=Datum_Saison
}

Hope this helps other beginners a bit.

1 Like

Hi.
Sorry for replying to a very old thread, but I’m trying to do about the same thing, just wondering if this is still the way to do it? I’ve got three items containing the artist, album and title played on one of my Sonos speakers. In my sitemap I’d like to combine them, showing something like “Artist - Album - Title”. Does that mean I’ll have to make a rule triggering on changes to any of those three items which then makes a postUpdate to a fourth item which I then use in my sitemap? Just checking so I don’t over-complicate things unnecessarily :wink:

That’s what I would do!

1 Like

Ok. This sounded like the easiest rule I’d ever write. For some weird reason it doesn’t work though, can’t understand why. My rule looks like this:

rule "Låtinfo kök"
when
        Item SonosKK_CurrentAlbum changed
        Item SonosKK_CurrentArtist changed
        Item sonos_PLAY1_RINCON_B8E937BECD0001400_currenttitle changed
then
        postUpdate(sonoskok_completetrackinfo, SonosKK_CurrentArtist.state + " - " + SonosKK_CurrentAlbum.state + " - " + sonos_PLAY1_RINCON_B8E937BECD0001400_currenttitle.state)
end

(kindly ignore the super ugly item names, will fix them later)
What I get in my log now every time I start a new track is this:

Rule 'Låtinfo kök': Script does not contain any expression

Isn’t postUpdate an expression?

Btw, is there any real difference between using the form itemname.postUpdate(whatever) or postUpdate(itemname, whatever) or is it only a difference between thinking oop or not?

You need to use or in the when clause

Should be a FAQ

1 Like

Doh. It’s always the obvious errors that I don’t spot…

Thanks for the link as well, guess I’ll start using the Item methods instead.

is this also possible with a url ?

in my sitemap i have this:
Image url ="Image url ="http://mysite.blub/VAR/image.jpg

the VAR is a item
ITEM:
String VAR {http="<[http://mysite.blub:10000:JSONPATH($.IMAGE.VALUE)]"}
(return today 10)

so, the correct path is
Image url ="http://mysite.blub/10/image.jpg

how can i create a correct ITEM / SITEMAP / RULE ?

thx

No, this isn’t possible as the item url has to be static.
I would try to copy the image to a static address by using a script and linking the item to this new static url.
You can use the openHAB webserver itself to serve the image.