[SOLVED] 2 items in one line

Hi everybody
I would like to have to items into 1 line.
For exemple, give me the status of a contact and the last time it was changed.
I defined 2 items.
First is a item that as the contact definition (open/closed)
The second one is an item that is updated via a rule and it contains the date/hour of the last change.
How can I put those 2 informations into the same line.

Thanlks for your help
I’M new into openHAB

You can’t. Items must be on separate lines.

That is not quite correct. Somewhere in the Wiki is a solution. You should be able to display the status of two items in one Line by using a String Item and a rule. It is not possible to have functionality of two items in one Item e.g. a Switch with da Date or something like this.



Contact DoorContact { yourbinding="..." }
String DoorContactStatus "door [%s]"


rule DoorContactStatusChanged
  Item DoorContact changed
  DoorContactStatus.postUpdate(DoorContact.state.toString + " at " + now.toString)
1 Like

I guess I misunderstood. I thought op wanted to define two items on the same line, not display two items on the same line in the sitemap. That’s what I get for posting on little sleep.

As @Dibbler42 and @watou have said, you can do it with a rule to update a String when the contact changes. However, you have to do some extra work to get the icon to work on the sitemap (i.e. door-open when opened and door-closed when closed). I’m repeating much of what watou posted primarily because I typed it before he posted his comment. :slight_smile:

But note that I and others have seen some issues where the sitemap on Android and iOS doesn’t always update immediately with this approach.


Contact cont { ... }
String contStatus "Contact [%s]"


rule "Update contact"
    Item cont changed
    contStatus.postUpdate(cont.state.toString + " at " + not.toString)


Text item=contStatus <door-opened> visibility=[cont=="OPEN"]
Text item=contStatus <door-closed> visibility=[cont!="OPEN"]

Hi Everybody

Thanks for your help.
The last configuration does work. I had to change the sitemap to icon="" .
The probleme that I currently have is that the definition in the item that
I gave doesn’t show in the sitemap. Instead of having “Windows contact” I
have “Contact” only. In the right side, i would like to have the date only.
Currently I have “CLOSED at 2015-09-29T17:16:18.141-04:00”. Since the icon
works, the state “Closed or open” is not necessary and the date 29-09-2015
16:18 would be appreciated.

Thanks again for your implication.

The part in quotes for the Item definition determines the label text. The part in brackets (i.e. [%s]) determines what goes on the right. The %s stands for the state of the Item. So if you want it to saw “Window Contact” you would define the item as:

String contStatus "Windows Contact [%s]"

Simple enough, change the rule to:


That will just put the date on the right hand side.


It does work!!! Your great!

Do you have any idea how to log changes inside a rule to a different file.
For exemple, if I change the state of a light, then it will be logged with
a personalized message to a file
“Light Room 1 change to ON at xxx xxxx”

Thanks Again!

See this thread on the old forum.

i made a line in my sitemap with this example. It works finde. But i get a string similar to this:

“CLOSED at 2015-09-29T17:16:18.141-04:00”

How can i format the time and date to a better readable format? Maybe like this:

“CLOSED at 17:16”


“CLOSED at 29.09., 17:16”

I finally got it to work!

Here is my complete rule:

rule "Xiaomi Temp 1 Status Changed"
    Item Xiaomi_Temp_1 received update
    var SimpleDateFormat df = new SimpleDateFormat( "dd.MM., HH:mm" )
    var String timestamp = df.format( new Date() )
    Xiaomi_Temp_1_komplett.postUpdate(String::format("%.1f", (Xiaomi_Temp_1.state as DecimalType).floatValue()) + " °C / " + String::format("%.0f", (Xiaomi_Humidity_1.state as DecimalType).floatValue()) + " % (" + timestamp + ")")

But i have another question:

How can i do this with groups, so that i only have to write one rule and it works for every temp-sensor in the group?

Some useful ideas here

I’ll also add this which contains more complete Group examples.

Will there be an easier way to do this in openHAB 2? I like the idea of having last change date / time for all my doors and windows, but creating an item for status for every device and then having 2 lines for every device in sitemap sounds like a lot of lines. My sitemap already is over 2K lines.

If there is an issue created for it and someone decides to implement it then it will change. I know of no plans to make this any different at this time. I suspect the primary focus will be on developing a repalcement for sitemaps in general (that is the reason why Habpanel 2 lacks the ability to create a sitemap, chris didn’t want to spend time implementing something that would become OBE in the near future). That UI may be Habpanel (I don’t know).

I’ve not fully explored Habpanel yet to know whether that might make this sort of thing better. I have messed with it enough to say it is pretty awesome on tablets and the ability to create custom widgets should make combining this sort of information on a single display unit more likely.

It is clear that BasicUI does not scale as well as it could and creating it is pretty painful. I don’t know if Habpanel does either, but alt least there is more chance for customization.

I personally maintain two UIs, one for control and the other for status. The control sitemap is pretty simple as I have very few manual controls in my system. The status UI is much larger and complicated but I don’t really care how it looks because I’m the only one who will ever see it. Knowing when the last time a door opened is one of those status things that only I would care to look at and even then only if something weird is going on. So I have this info tucked away in a subpanel of a subpanel on the status sitemap and I just use the Group tag to list them all without modification.

I’m experimenting with using Habpanel for the status but haven’t got very far yet. I keep my sitemap for control right now as my wife knows how to use the openHAB phone app and I’m not ready to train her to use Habpanel. Plus I think I remember reading that it had some problems behind a reverse proxy. Though now that I think about it that may be Habmin that I’m thinking of.

var SimpleDateFormat df = new SimpleDateFormat( “dd.MM., HH:mm” )

If I tried this, smarthome designer tells me “SimpleDateFormat cannot be resolved”

Have I to import something in the rules file like:
import org.joda.time.*

I have this imported on top of my rules file:

import java.text.SimpleDateFormat

Don´t know if it´s necessary.

Perfect, solved by adding this line

But how to know this? What to include for which syntax?

No idea, i got help from this forum some time ago. And i made the rule file the same way like explained here - so it worked.