OpenHAB - Explanation of Sitemaps

Post date: May 01, 2015 1:2:42 PM

Introduction

Sitemaps are used to create elements of a user interface for making openHAB items accessible to various frontends.

Sitemaps are a declarative UI definition. With a few lines it is possible to define the structure and the content of your UI screens. Sitemap files are stored in${openhab_home}/configurations/sitemaps. (Syntax: yourSitemapName.sitemap)

If you create a sitemap with the name default.sitemap and the sitemap element 'default' then you do not need to specify a sitemap parameter in your URL. The URL "http://localhost:8080/openhab.app" has the same behaviour as "http://localhost:8080/openhab.app?sitemap=default".

The openHAB runtime comes with a demo sitemap file, which should let you easily understand its structure.

For easy editing, the openHAB Designer brings full IDE support for these files, so you can easily check the syntax and find out about the options you have. (Again, for the technically interested, this is also an Xtext DSL.)

Syntax

Sitemaps can be composed by grouping various user interface elements into areas, which will be rendered by openHAB.

This element is mandatory in a sitemap definition file:

Element name

sitemap

Description

This will be the first line. It is mandatory and it states the name of your sitemap (demo) and the title of the main screen.

Element 'Sitemap'

Syntax:

sitemap [sitemapname] [label="<title of the main screen>"]

The following elements can be used optionally in a sitemap definition file (alphabetical order):

Element 'Colorpicker'

Syntax:

Colorpicker [item=<itemname>] [label="<labelname>"] [icon="<iconname>"] [sendFrequency=""]

Element 'Chart'

Syntax:

Chart [item=<itemname>] [icon="<iconname>"] [label="<labelname>"] [service="<service>"] [period=xxxx] [refresh=xxxx]

Note that charts are rendered by a chart provider. By default, openHAB provides a default chart provider which will work with all queryable persistence services. Other chart providers can be user to render the chart by changing the chart:provider=defaultconfiguration in openhab.cfg to the name of the alternative provider. Currently, the only alternative is to use the rrd4j provider to render the graphs.

A few technical constraints and details to be aware of:

Charts from rrd4j can also be generated and shown as images. Visit Charts in the Wiki for examples.

Element 'Frame'

Frames are used to create a visually separated area of items.

Syntax:

Frame [label="<labelname>"] [icon="<icon>"] [item=<item>] {     [additional sitemap elements] }

Element 'Group'

A Group element creates a clickable area that opens up on a new page, where you can show various elements (including nested Groups).

Syntax:

Group [item=<itemname>] [label="<labelname>"] [icon="<iconname>"]

Note that all the parameters are optional, but if you don't specify at least one of them, the group will not appear in the interface (unlike the frame).

If you specify at least one parameter, the Group item will appear as a clickable white box. By clicking, you access a new page that shows the contents inside the group. Group items can be nested and mixed with frames: this gives a very powerful method to organise your information.

itemname can be a single item, or a item group: in the latter case, the new page will contain all items belonging to it.

If you don't set labelname but specify itemname, the group will get the label from the item. If you don't set both labelname and itemname, the group will appear as a blank box. You can see another effect of setting a labelname in the interface navigation bar: the left link that moves you to the previous level shows the text of labelname, or "Back" if the label is not specified.

Element 'Image'

Syntax:

Image [item=<itemname>] [icon="<iconname>"] url="<url of image>" [label="<labelname>"] [refresh=xxxx]

refresh is the refresh period of the image in milliseconds

Element 'List'

Syntax:

List item=<itemname> [label="<labelname>"] [icon="<iconname>"] [separator=""]

Element 'Selection'

Syntax:

Selection item=<itemname> [label="<labelname>"] [icon="<iconname>"] [mappings="<mapping definition>"]

An explanation for mappings you can find here.

Note: Selection renders the elements in the mappings as a list of texts in a separated page. If you prefer a list of buttons in the same page, then use Switch with an associated mapping.

Element 'Setpoint'

Syntax:

Setpoint item=<itemname> [label="<labelname>"] [icon="<iconname>"] minValue="<min value>" maxValue="<max value>" step="<step value>"

Element 'Slider'

Syntax:

Slider item=<itemname> [label="<labelname>"] [icon="<iconname>"] [sendFrequency="frequency"] [switchSupport]

Element 'Switch'

Syntax:

Switch item=<itemname> [label="<labelname>"] [icon="<iconname>"] [mappings="<mapping definition>"]

You can find an explanation for mappings you can here. Also note that Switch elements with and without mapping are rendered differently in the interface.

Element 'Text'

Syntax:

Text item=<itemname> [label="<labelname>"] [icon="<iconname>"]

Element 'Video'

Syntax:

Video item=<itemname>  [icon="<iconname>"] url="<url of video to embed>" [encoding="<video encoding>"]

encoding is the video encoding. Be sure to specify "mjpeg" for MJPEG video. Leave empty for autoselection, but autoselection does not work properly for MJPEG.

Element 'Webview'

Syntax:

Webview item=<itemname> [label="<labelname>"] [icon="<iconname>"] url="<url>" [height="<heightvalue"]

Mappings

Mappings can be used to let the user chose an item from a list.

Syntax:

mappings = [ "value1"="name1", "value2"="name2" ]

Quotes can be omitted if the value string and name string do not contain spaces.

Examples:

mappings = [ "1"="ON", "0"="OFF" ] mappings = [ 1="BBC", 2="CNN", 3="BLOOMBERG" ]

Dynamic Sitemaps

Note The following is only available in v1.4 and above.

Sitemaps can be designed to show items dynamically, or add colors depending on their state, or the state of another item. A few use cases for this are:

All widgets in the sitemap have the following three parameters available -:

It is important to note that in all cases rules are parsed from left to right, and the first rule that returns true will take priority.

Visibility

To dynamically show or hide an item, the visibility tag is used. By default, an item is visible if the visibility tag is not provided. If provided, a set of rules are used to indicate the items visibility status. If any of the rules are true then the item will be visible, otherwise it will be hidden.

The format of the visibility tag is as follows -:

visibility=[item_name operator value, ... ]

Multiple rules can be provided using a comma as a delimiter. Valid operators are the ==, >=, <=, !=, >, <.

Examples

visibility=[Weather_Chart_Period!=ON] visibility=[Weather_Chart_Period=="Today"] visibility=[Weather_Chart_Period>1, Weather_Temperature!="Uninitialized"]

Colors

Colors can be used to emphasise an items label or its value.

The format of the labelcolor and valuecolor tags are as follows -:

labelcolor=[item_name operator value = "color", ... ]

Multiple rules can be provided using a comma as a delimiter. Valid operators are the ==, >=, <=, !=, >, <.

itemname and operator are optional - if not provided, itemname will default to the current item and operator will default to ==. So the following three rules will all do the same thing, and all are valid.

Text item=Weather_Temperature valuecolor=[22="green"] Text item=Weather_Temperature valuecolor=[==22="green"] Text item=Weather_Temperature valuecolor=[Weather_Temperature==22="green"]

openHAB supports a standard set of colors, based on the CSS definitions. This is a set of 17 colors that should be supported by any UI. The colors are defined by name, and within openHAB they are translated to the CSS color format (ie "#xxxxxx"). This should ensure a standard interface for these colors.

Below is a list of the standard colors and their respective CSS definitions. Note that case is not important.

For any color other than those defined above, "color" is passed directly through to the UI, so its exact implementation is up to the UI. It is generally expected that valid HTML colors can be used (eg "green", "red", "#334455") but a UI could for example define abstract colors that are defined internally depending on the theme. For example, "warning" could be defined and used in a UI dependant way, but there is currently no standardisation of these terms.

Examples

valuecolor=[>25="orange",>15="green",>5="orange",<5="blue"] valuecolor=[Weather_LastUpdate=="Uninitialized"="lightgray",Weather_LastUpdate>600="lightgray",>15="green",>=10="orange",<10="red"]

Hint: for dynamic icons see the section on icons on the items page.

Example

You may find descriptions like:

   Frame label="Demo" {          Text label="Group Demo" icon="1stfloor" {                 Switch item=Lights mappings=[OFF="All Off"]                 Group item=Heating                 Group item=Windows                 Text item=Temperature          }          Text label="Multimedia" icon="video" {                 Selection item=Radio_Station mappings=[0=off, 1=HR3, 2=SWR3, 3=FFH, 4=Charivari]                 Slider item=Volume             }     }

A note about rule comparison

Further examples for defining sitemaps can be found in our openHAB-Samples section