Mapping questions


I’ve encountered the idea of mapping in a few different places when reading around the Wiki and this community.

I’ve been trying to map the output of the opening/closing item as follows:

> User Opening: 0001=Disarmed by <User>

Without the mapping (obviously) the sitemap displays “User Opening: 0001”, which is kind of fine, as there are only 5 users, and I know all their user numbers. But clearly I’d like to tinker and get it to display something like “Disarmed by Chris”.

Which I thought would be dead easy, but I’m just getting blank output. I thought it might be because of the “:” in the string, but even if I escape that as “%3A” I get the same result:

> 2015-11-19 21:42:39.723 [WARN ] [t.i.s.MapTransformationService] - Could not find a mapping for 'User Opening: 0001' in the file ''.

But, now it’s dawning on me that perhaps mapping only works on Number items? I’m struggling to find a definitive ‘mapping help’ anywhere. Does anyone know of such a thing?

Thanks community!


I don’t have an answer to your problem but I can definitively say that mapping does work with strings.

What does your mapping file look like? Maybe it can’t handle the spaces… Have you tried escaping the spaces in addition to the : ?

Hi @rlkoshak

My mapping file is as follows:

> undefined=unknown
> -=No Data
> =Blank
> 0=Disarmed
> 1=Armed AWAY
> 2=Armed STAY
> 3=Armed AWAY - no delay
> 4=Armed STAY - no delay
> User Opening: 0001=Disarmed by xxxxx
> User Opening: 0002=Disarmed by xxxxx

I’ve tried escaping the whole string, including spaces etc. But no joy either.

I’m thinking the spaces are the problem. You tried URL type escapes, have you tried \ escapes?

Maybe you can use a transform or a rule to reduce the value of the item to just the number, eg “0001” , and do a transform on that. Though if you do it in a rule you may as well go all the way and avoid the transform entirely.

Yeah, I tried escaping the whole string too. Still didn’t work.

I’ll try rules next…!

You’ll need to escape the colon (:) in addition to the spaces, like this:

User\ Opening\:\ 0002=Disarmed by xxxxx

and then it’ll work. Both colon (:) and equals (=) are considered delimiters in MAP files.

Here’s my sample Rule-based testcase to validate the above:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import java.lang.Integer

rule "MAP Test"
    Time cron "0/10 * * * * ?"
    var String map = 'User Opening: 0001'
    var String mapped = transform("MAP", "", map)
    logInfo("map-test", "map=" + map)
    logInfo("map-test", "mapped=" + mapped)

which results in log output like:

11:48:40.010 INFO[:53]- map=User Opening: 0001
11:48:40.014 INFO[:53]- mapped=Disarmed by xxxxx

I have the same problem
OL=AC Power OB DISCHRG=Discharging OB&nbsp;DISCHRG=Discharging1 OBDISCHRG=Discharging2 OL CHRG=Charging OL&nbsp;CHRG=Charging1 OLCHRG=Charging2 OL&nbsp;CHRG=Charging2

and giveing me error “Cannot find mapping OB DISCHRG in”

Somebody can help me with MAP containicg spaces

&nbsp; is the HTTP way of escaping a space. Like I mentioned above, in this case you may need to use the Java/C/C++ style escaping with a backslash.

OB\ DISCHRG=Discharging

I don’t know if that will work either. You might need to adjust your transform or create a rule to eliminate the spaces.

1 Like

this works fine

and whats have to use in this case?

volume: 2

mute: 0

i try with \space but not work

In a map file you can either use an ‘=’ or a ‘:’ between the key and the value. If your key has one of these characters in it you need to escape it as well:

volume\:\ 2=VOLUME
mute\:\ 0=MUTE

I think that is what you are asking.

the item give me

volume: 2<br>
mute: 0<br>

and my transform have to be somethink like that

volume:\ 2<br>mute:\ 0<br>=2

but don’t work, i think the problem is in second roll or “<>”

You absolutely need to escape the ‘:’ and possibly the ‘<’ and ‘>’ too.

volume\:\ 2\<br\>mute\:\ 0\<br\>=2
volume\:\ 2\<br\>mute\:\ 0\<br\>=2 and 
volume\:\ 2<br>mute\:\ 0<br>=2

not works
i try with rule given up in this theme not works too.

this information is taken from HTTP binding REGEX will works too, i try to extract only digits with
REGEX((\d)) but this kill entire openhab

According to [this document](, you should only need to escape : = and whitespace, so your .map file should be

volume\:\ 2<br>mute\:\ 0<br>=2

but are you sure that your item’s value is exactly "volume: 2<br>mute: 0<br>"? The MAP transform does not search and replace a larger string with the values in the .map file.

Here is a tiny Java program you can compile with javac and run by typing java Test . It will read and print out what it mapped:

import java.util.Properties;

public class Test {
	public static void main(String [] args) {
		Properties props = new Properties();
		try {
			props.load(new FileReader(""));
		catch (Exception ex) {

The rules for map files (from the above java.util.Properties document):

The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped ‘=’, ‘:’, or white space character other than a line terminator. All of these key termination characters may be included in the key by escaping them with a preceding backslash character; for example,


would be the two-character key “:=”. Line terminator characters can be included using \r and \n escape sequences. Any white space after the key is skipped; if the first non-white space character after the key is ‘=’ or ‘:’, then it is ignored and any white space characters after it are also skipped. All remaining characters on the line become part of the associated element string; if there are no remaining characters, the element is the empty string “”. Once the raw character sequences constituting the key and element are identified, escape processing is performed as described above.

As an example, each of the following three lines specifies the key “Truth” and the associated element value “Beauty”:

Truth = Beauty
Truth :Beauty

As another example, the following three lines specify a single property:
fruits apple, banana, pear,
cantaloupe, watermelon,
kiwi, mango

The key is “fruits” and the associated element is:
“apple, banana, pear, cantaloupe, watermelon, kiwi, mango”
Note that a space appears before each \ so that a space will appear after each comma in the final result; the , line terminator, and leading white space on the continuation line are merely discarded and are not replaced by one or more other characters.
As a third example, the line:


specifies that the key is “cheeses” and the associated element is the empty string “”.
Characters in keys and elements can be represented in escape sequences similar to those used for character and string literals (see sections 3.3 and 3.10.6 of The Java™ Language Specification). The differences from the character escape sequences and Unicode escapes used for characters and strings are:

Octal escapes are not recognized.
The character sequence \b does not represent a backspace character.
The method does not treat a backslash character, , before a non-valid escape character as an error; the backslash is silently dropped. For example, in a Java string the sequence “\z” would cause a compile time error. In contrast, this method silently drops the backslash. Therefore, this method treats the two character sequence “\b” as equivalent to the single character ‘b’.
Escapes are not necessary for single and double quotes; however, by the rule above, single and double quote characters preceded by a backslash still yield single and double quote characters, respectively.
Only a single ‘u’ character is allowed in a Uniocde escape sequence.


the exact value of item is

volume: 2

mute: 0

i don’t understand how to compile and use java program who give me

Where does this item get its string state value? A binding? Could you provide the full item definition or script fragment that updates the item?

String dm6_vol “Volume level [MAP(]” {http="<[http://root:dreambox@*))]"}

I very strongly suspect that more than volume: 2<br>mute: 0<br> is being returned from that web page. You could go there in the browser and “view source” to see the entirety of the page returned. If there is more returned than that, you could either write a really long, complicated mapping, or much better a REGEX transform that captures the digits after volume: and before <br>.

More like:

Number dm6_vol "Volume level [%d]" { http="<[http://root:dreambox@*volume\:\s?([0-9]+).*)]" }

(not tested).

With this work fine


10x for your help