Mapping of item values not correctly shown in HABpanel

Hello,

I have a question regarding the representation of mapped values in HABpanel:

In my items file I have defined the following items:

Contact Wohnzimmer_Fenster1_OpenClosed  "Wohnzimmerfenster 1 [MAP(de.map):%s]" (Wohnzimmer, Wohnung_Fenster) { channel="max:shuttercontact:NEQ0897054:LEQ0791036:contact_state" }
Contact Wohnzimmer_Fenster2_OpenClosed  "Wohnzimmerfenster 2 [MAP(de.map):%s]" (Wohnzimmer, Wohnung_Fenster) { channel="max:shuttercontact:NEQ0897054:LEQ0790888:contact_state" }

To map the results to german I have defined in de.map the following translation, which works fine in BasicUI:

CLOSED=zu
OPEN=offen

In a HABPanel template I defined (the both items above are in the group “Wohnung_Fenster”):

<div class="row" ng-repeat="item in itemsInGroup('Wohnung_Fenster')">
  <div class="col-xs-8 text-right">{{item.label}}</div>
  <div class="col-xs-4 text-left" ng-style="{ color: itemValue(item.name)=='offen' ? 'red':'green' }">
    {{itemValue(item.name)}}
  </div>
</div>

When I start now HABpanel I get the following result - what seems to be ok:

Now I open a window which leads to:

this is strange because after a page refresh I get:

When looking into the debug log in the browser after opening the window I see indeed, that the state changes form “zu” to OPEN (and than again from OPEN to OPEN ?) but not to the expected translated value “offen”:

Is this “works as designed” or did I made a mistake?

Many thanks in advance for your support.

1 Like

That’s probably because ESH applies the map transformation in the /items REST API response (the initial value) but not when pushing SSE events (subsequent updates), I believe this was raised before, not sure what to do at HABPanel’s level, you can however look for a similar bug report in ESH and ‘+1’ it.

That’s apparently a new bug :slight_smile: , should be benign but will be fixed.

Thanks for your feedback!

So I analyzed the REST Api a little bit, and got the following understanding:

When I make a REST-Api call as follows

http://homenuc:8080/rest/items/Wohnzimmer_Fenster1_OpenClosed/state

it always returns the unmapped value:

CLOSED

respectively

OPEN

When you are not calling the state directly but the item itself

http://homenuc:8080/rest/items/Wohnzimmer_Fenster1_OpenClosed

you always get the mapped value beside “state”:

{
  "link": "http://homenuc:8080/rest/items/Wohnzimmer_Fenster1_OpenClosed",
  "state": "zu",
  "stateDescription": {
    "pattern": "",
    "readOnly": false,
    "options": []
  },
  "type": "Contact",
  "name": "Wohnzimmer_Fenster1_OpenClosed",
  "label": "Wohnzimmerfenster 1",
  "tags": [],
  "groupNames": [
    "Wohnzimmer",
    "Wohnung_Fenster"
  ]
}

respectively

{
  "link": "http://homenuc:8080/rest/items/Wohnzimmer_Fenster1_OpenClosed",
  "state": "offen",
  "stateDescription": {
    "pattern": "",
    "readOnly": false,
    "options": []
  },
  "type": "Contact",
  "name": "Wohnzimmer_Fenster1_OpenClosed",
  "label": "Wohnzimmerfenster 1",
  "tags": [],
  "groupNames": [
    "Wohnzimmer",
    "Wohnung_Fenster"
  ]
}

I couldn’t find any documentation which describes if this is “works as designed” or a bug.
Of course on the event channel you always get the original, unmapped value. As far as I know, the Android application also works with the REST-Api and there the values are always shown in their mapped version. So I would assume, that the make an additional call to the item and get the mapped value besides the “state” key which is then visualized.

Maybe someone of the REST-Api experts can support here?

Thanks in advance.

1 Like

No, I was wrong with my assumption regarding the android app. They are using the sitemap rest call

http://homenuc:8080/rest/sitemaps/zuHause?jsoncallback=callback

which leads to

"widgets": [
                      {
                        "widgetId": "Wohnzimmer_0",
                        "type": "Text",
                        "label": "Wohnzimmerfenster 1 [zu]",
                        "icon": "contact",
                        "mappings": [],
                        "item": {
                          "link": "http://homenuc:8080/rest/items/Wohnzimmer_Fenster1_OpenClosed",
                          "state": "zu",
                          "stateDescription": {
                            "pattern": "",
                            "readOnly": false,
                            "options": []
                          },
                          "type": "Contact",
                          "name": "Wohnzimmer_Fenster1_OpenClosed",
                          "label": "Wohnzimmerfenster 1",
                          "tags": [],
                          "groupNames": [
                            "Wohnzimmer",
                            "Wohnung_Fenster"
                          ]
                        },
                        "widgets": []

1 Like

Thank you for your extensive research. I also think this is very important. IMHO if there are mappings used, we should receive only the mapped value.

This should be worth an issue for openhab2. Can you open one?

So I opened an issue in github:

https://github.com/eclipse/smarthome/issues/2788

Let’s see what the developer think about that topic


Regards

EDIT: Change link to new issue at Eclipse Smart Home

1 Like

Since there are from time to time new questions coming up to this topic in this forum:

The devs are working very actively on this issue :thumbsup:

So keep fingers crossed we can expect a solution in the dev branch soon :wink:

Regards,

André

The devs have now implemented a new state called “transformedState”, which shows beside the “state” the mapped value - eg:

{
  "link": "http://homenuc:8080/rest/items/Wohnzimmer_Fenster1_OpenClosed",
  "state": "CLOSED",
  "transformedState": "zu",
  "stateDescription": {
    "pattern": "",
    "readOnly": false,
    "options": []
  },
  "type": "Contact",
  "name": "Wohnzimmer_Fenster1_OpenClosed",
  "label": "Wohnzimmerfenster 1",
  "tags": [],
  "groupNames": [
    "Wohnzimmer",
    "Wohnung_Fenster"
  ]
}

Many thanks for that!

@ysc: It would be great if this would be used as the default state to be visualized in HABPanel ! :wink:

1 Like

Note that transformedState is only provided when different from the raw state.
The change is available since snapshot 849.

Great! I am in holidays right now, will take care of it when I am back home.

Will the standard widgets change so it display transformedState but control icons with raw state?

/Mike

Yes, that’s the idea. The transformed value will also be available by default in templates (itemState()), with an option to get the raw value instead.

When will this be released?

/Mike

Finally had a look at this
 and I had the wrong assumptions; the bad news is, since the transformedState is not part of the ItemStateChangedEvent payload, it can’t be used by HABPanel which only relies on these events to update the UI after the initial load. Making a separate REST API call just to get the transformed state seems like overkill.

The good news is, the raw state is now reported consistently - this means icons etc. will be displayed reliably. If you wish to display a different label you should do so in your HABPanel template.

The transformed value is probably in ItemStateChangedEvent when the transformed value us different from the raw value.

Unfortunately not. The SSE event is:

{"topic":"smarthome/items/Test_Map/statechanged","payload":"{\"type\":\"StringType\",\"value\":\"CLOSED\",\"oldType\":\"StringType\",\"oldValue\":\"OPEN\"}","type":"ItemStateChangedEvent"}	

while an explicit API call (GET /rest/items) returns:

    "link": "http://localhost:8081/rest/items/Test_Map",
    "state": "CLOSED",
    "transformedState": "zu",
    "stateDescription": {
      "pattern": "",
      "readOnly": false,
      "options": []
    },
    "type": "String",
    "name": "Test_Map",
    "label": "",
    "category": "door",
    "tags": [],
    "groupNames": []
  }

Maybe we can think about adding the transformed state value in this event?

If it doesn’t break things and doesn’t lead to performance issues, I guess? (I’m no expert in this area)

Quickly browsing around it would be probably go around there, after adding the fields to the event class itself - but no idea if it’s possible at all to apply the transformation here:

1 Like

Hi

I’m having the same problem with my maped items not updating,

I have a doormagnet that showing Open when it is closed and open when it is open, so I transformed the state to the correct.

Is there a solution now, or do we need to wait until there is a habpanel update that solves this problem?