Template with value mapping (transformation)

Hey there
I have troubles figuring out how to properly create a template with value mapping (transformation). My item is a modbus channel which I can write to. I tried using String to map the numbers but I cannot write then (probably error 30).

Unfortunately the dummy widget doesn’t allow mappings either (if they don’t come from the item itself) so I guess the only way to do it is using a template-widget. Since I want it to look like the original, I used a guide from here. Googled and tried things for the last few hours to no avail. I hope you guys can help me out.

HABPanel

<style>.myVersionOfWidget {padding: 0;  margin: 0; border: none;}</style>
<div class="myVersionOfWidget" ng-init='myWidget={
                "name": ngModel.name,
                "item": "FiltrationState",
                "type": "dummy",
                "font_size": "20",
                "backdrop_iconset": "smarthome-set",
                "backdrop_icon": "power-button",
                "backdrop_center": true,
                "hidelabel": false,
                "hideonoff": false
                }'>
    <widget-dummy ng-model="myWidget">
    </widget-dummy>
</div>

I also tried adding the following here and there but it doesn’t work

<div ng-if=\"itemState(config.dummy_item) == '0'\">Aus</div>
<div ng-if=\"itemState(config.dummy_item) == '1'\">Ein</div>

Item
Number FiltrationState "Pumpe ist [%s]" { channel="modbus:data:oxilifepool:register1057:FiltrationState:number" }

Sitemap
Text item=FiltrationState label="Pumpe ist [MAP(simpleonoff.map):%s]" icon="pump"

simpleonoff.map

0=Aus
1=An
=default
-=undefined
NULL=NULL

This works plain but is missing the style and such :wink:
{{itemValue('FiltrationState') == 0 ? 'Aus' : 1 ? 'An' : 'Unbekannt'}}

So does your simple MAP work in BasicUI? Why would you not apply that to the Item definition, so that you can use it in HABpanel?

Yes, it works in Basic UI.
I tried using it in .items but I cannot get it to work properly. Especially if I want a switch. I tried it with the following but I am not able to use mappings anymore / switch the thing.

Item
String FiltrationMode2 "Pumpenmodus ist [%s]" { channel="modbus:data:oxilifepool:register1041:FiltrationMode:number"[profile="transform:MAP", function="filtrationmode.map"] }

Map

0=Manuell
1=Automatisch
2=Heizen
3=Smart
4=Intelligent
13=Rückspülen
=default
-=undefined
NULL=NULL

This works fine for me
Item
Number FiltrationMode "Pumpenmodus ist" { channel="modbus:data:oxilifepool:register1041:FiltrationMode:number", autoupdate="false" }

Sitemap
Switch item=FiltrationMode label="Modus[]" mappings=[0="Manuell",1="Automatisch",3="Smart"]

Not that way. Don’t you want to transform the value for UI display only, but not interfere with the actual Item state? This is what the [state presentation] part of the label is for, same way as you used it in your sitemap.

Number FiltrationMode "Pumpenmodus ist [MAP(simpleonoff.map):%s]" { ...

Right, I want to transform the value for UI display only. But it doesn’t work. In PaperUI I get Pumpenmodus ist MAP(filtrationmode.. I thought it doesn’t work. Oh man. Should have tried BasicUI / HABPanel, too. My bad.

But I think it would be good to know whether or not this can be achieved in a template, too.

I don’t know anything about HABpanel, but the default widget includes a little checkbox for “use server format” or something like.