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.
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.
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
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!)
“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.
)
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?
Have the Astro binding as well as the NTP binding installed.
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
Sitemap - have an entry like this at the place you thik it fits best:
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
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?
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.