Seite 1 von 1

String-Item zeigt Zeilenumbrüche nicht an

Verfasst: 22. Apr 2026 16:03
von lenschith
Hallo zusammen,

ich versuche in einer Rule (Blockly) eine Liste von Tankstellenpreisen zu sortieren und diese formatiert in einem String-Item zu speichern. Jeder Eintrag soll dabei in einer eigenen Zeile stehen.

Das sortieren funktioniert soweit wie ich das brauche aber obwohl ich im Skript Zeilenumbrüche verwende (CRLF - '\r\n'), werden die Daten im String-Item in einer Sitemap einfach hintereinander weggeschrieben.
Screenshot 2026-04-22 154942.png
Ausschnitt vom Code:

Code: Alles auswählen

items.getItem('PreiseTankstelle').sendCommand(('⛽ ' + String((preisListeSorted.join('\r\n' + '⛽ ')).replaceAll('Diesel','').replaceAll(',','€ '))));
Code:

Code: Alles auswählen

configuration: {}
triggers:
  - id: "1"
    configuration:
      groupName: Treibstoffpreise
    type: core.GroupStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      blockSource: '<xml
        xmlns="https://developers.google.com/blockly/xml"><variables><variable
        id="O|@26=ylARRtEUm}jT77">preisListe</variable><variable
        id="M,b9Dc|;`5AiV}L~=7v,">nameListe</variable><variable
        id="B`/h,@oMEYpa~-IZYEg#">i</variable><variable
        id=",d#`NQzJsQQhwQ]KdEl=">preisListeSorted</variable></variables><block
        type="variables_set" id="sgRq]yBc_$!]ON2Mfsua" x="206" y="47"><field
        name="VAR" id="O|@26=ylARRtEUm}jT77">preisListe</field><value
        name="VALUE"><block type="lists_create_with"
        id="*2K?7zKwN7SBnz/^)R*o"><mutation
        items="0"></mutation></block></value><next><block type="variables_set"
        id="B[qE5A4%i{BzB3r@N98b"><field name="VAR"
        id="M,b9Dc|;`5AiV}L~=7v,">nameListe</field><value name="VALUE"><block
        type="lists_create_with" id="x_yA@:i3J,#vSxlL]4q8"><mutation
        items="0"></mutation></block></value><next><block
        type="controls_forEach" id="BSX*J#W%S^NsP=Z5D;2#"><field name="VAR"
        id="B`/h,@oMEYpa~-IZYEg#">i</field><value name="LIST"><block
        type="oh_groupmembers" id="0r0usP1:so5po;rAO:/Q"><value
        name="groupName"><shadow type="oh_item"
        id="NuIgBWo87DV=uzofQ6C|"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id=":m~60aL/jK6zrm(LEh)g"><mutation itemName="Treibstoffpreise"
        itemLabel="Treibstoffpreise"></mutation><field
        name="itemName">Treibstoffpreise</field></block></value></block></value><statement
        name="DO"><block type="controls_if" id="LAgT{mNBTAW2Lgz~gDNb"><value
        name="IF0"><block type="logic_compare" id="Zq7jjKEvQr,{iD,s^gts"><field
        name="OP">EQ</field><value name="A"><block type="oh_getitem_attribute"
        id="Hhi,wJp_0PJSaBFqgoHy"><mutation
        attributeName="NumericState"></mutation><field
        name="attributeName">NumericState</field><value name="item"><shadow
        type="oh_getitem" id="znS.jZ|@[F(Wbt|{yvv#"><value
        name="itemName"><shadow type="oh_item"
        id="=p[kgE_It#a+B4@J~e(7"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="variables_get" id="P:9mmzi1BC9{U=rOGF(D"><field name="VAR"
        id="B`/h,@oMEYpa~-IZYEg#">i</field></block></value></block></value><value
        name="B"><block type="oh_getitem_attribute"
        id="e8i=HQa_|[!;}ktHBI}H"><mutation
        attributeName="NumericState"></mutation><field
        name="attributeName">NumericState</field><value name="item"><shadow
        type="oh_getitem" id="M4u,MIQpd9/TWvTj]=RE"><value
        name="itemName"><shadow type="oh_item"
        id="wr}$D9OzL.WS13Wf6ODG"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="oh_item" id="h?L:0!q`x.f]V9zR7-4J"><mutation
        itemName="Treibstoffpreise"
        itemLabel="Treibstoffpreise"></mutation><field
        name="itemName">Treibstoffpreise</field></block></value></block></value></block></value><statement
        name="DO0"><block type="lists_setIndex"
        id="+I+vh}NR221L]`YoP_I]"><mutation at="false"></mutation><field
        name="MODE">INSERT</field><field name="WHERE">LAST</field><value
        name="LIST"><block type="variables_get" id="LZ*B+adH32t[8XlD%%rr"><field
        name="VAR"
        id="M,b9Dc|;`5AiV}L~=7v,">nameListe</field></block></value><value
        name="TO"><block type="oh_getitem_attribute"
        id="cM:,1Z@@@=(hXjt+=9jT"><mutation
        attributeName="Label"></mutation><field
        name="attributeName">Label</field><value name="item"><shadow
        type="oh_getitem" id="Ic=0?s5KGL~Y?{5]:q@y"><value
        name="itemName"><shadow type="oh_item"
        id="kR_|42Wz7.KIh%@vnl/w"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="variables_get" id="iUUgrb(%!heT~RPM$N)c"><field name="VAR"
        id="B`/h,@oMEYpa~-IZYEg#">i</field></block></value></block></value></block></statement><next><block
        type="lists_setIndex" id="s{a7WtK@^dXWP:?BxdZV"><mutation
        at="false"></mutation><field name="MODE">INSERT</field><field
        name="WHERE">LAST</field><value name="LIST"><block type="variables_get"
        id="5p4-B%a7GMoAE9n4JR}L"><field name="VAR"
        id="O|@26=ylARRtEUm}jT77">preisListe</field></block></value><value
        name="TO"><block type="lists_create_with"
        id="LdG;;WYWPe_;n1}K=Y]c"><mutation items="2"></mutation><value
        name="ADD0"><block type="oh_getitem_attribute"
        id="X|h3^eF@ZgWM%W|Qz`hi"><mutation
        attributeName="NumericState"></mutation><field
        name="attributeName">NumericState</field><value name="item"><shadow
        type="oh_getitem" id="uDDj#oM3aD`,0[QxI|xf"><value
        name="itemName"><shadow type="oh_item"
        id="{/-N8!(dyq+$P/;,UeSI"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="variables_get" id=";{Jb~LMbc)sP$/1n,_rC"><field name="VAR"
        id="B`/h,@oMEYpa~-IZYEg#">i</field></block></value></block></value><value
        name="ADD1"><block type="oh_getitem_attribute"
        id="RcSfd%YlRGCa:GC$7Q}#"><mutation
        attributeName="Label"></mutation><field
        name="attributeName">Label</field><value name="item"><shadow
        type="oh_getitem" id="uDDj#oM3aD`,0[QxI|xf"><value
        name="itemName"><shadow type="oh_item"
        id="{/-N8!(dyq+$P/;,UeSI"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="variables_get" id="|KNA[L$@?GGpyr39L65m"><field name="VAR"
        id="B`/h,@oMEYpa~-IZYEg#">i</field></block></value></block></value></block></value></block></next></block></statement><next><block
        type="oh_event" id="ujrKbo(Xr+Z*FNna7Zx-"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="bc4_BV]VEJcLH!GX%g4H"><field
        name="TEXT">value</field></shadow><block type="text_join"
        id="#jWE+rQ)_q%:A]CWHxSn"><mutation items="3"></mutation><value
        name="ADD0"><block type="oh_getitem_attribute"
        id="4gS0`cG`Ovu25X5R8dk$"><mutation
        attributeName="NumericState"></mutation><field
        name="attributeName">NumericState</field><value name="item"><shadow
        type="oh_getitem" id="M4u,MIQpd9/TWvTj]=RE"><value
        name="itemName"><shadow type="oh_item"
        id="wr}$D9OzL.WS13Wf6ODG"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="oh_item" id="]zw{0=gZ_3v#p^UgR4CM"><mutation
        itemName="Treibstoffpreise"
        itemLabel="Treibstoffpreise"></mutation><field
        name="itemName">Treibstoffpreise</field></block></value></block></value><value
        name="ADD1"><block type="text" id="veG.oe{NMhM)6gN5$%t2"><field
        name="TEXT">€: </field></block></value><value name="ADD2"><block
        type="text_join" id="JUK-viO*Q:7;XTlO]4|q"><mutation
        items="1"></mutation><value name="ADD0"><block type="oh_text_replace"
        id="+E0nGctJAIS`JZv-_SPv"><value name="pattern"><shadow type="text"
        id="%r~P`F?#V_2]v8}-r3Y+"><field
        name="TEXT">pattern</field></shadow><block type="text"
        id="[B;td}nKN6G1~h9dk].X"><field name="TEXT">
        Diesel</field></block></value><value name="replacement"><shadow
        type="text" id="hKssW~K%Gr~f4U:B,!6,"><field
        name="TEXT">replacement</field></shadow><block type="text"
        id="IL~L@Gl7_e9}#q3/^gj."><field
        name="TEXT"></field></block></value><value name="origin"><shadow
        type="text" id="74)uT?Q`0L=PN~861Pvl"><field
        name="TEXT">origin</field></shadow><block type="lists_split"
        id=")KIk|Sapo:.IA!J3w5Ju"><mutation mode="JOIN"></mutation><field
        name="MODE">JOIN</field><value name="INPUT"><block type="variables_get"
        id="c)cEz~Jv!47:8JBQGF)`"><field name="VAR"
        id="M,b9Dc|;`5AiV}L~=7v,">nameListe</field></block></value><value
        name="DELIM"><shadow type="text" id="4]cVdVFbSepVR}[[085;"><field
        name="TEXT">,</field></shadow><block type="text"
        id="J@;uhVJ,ig+VMl-H~Uv1"><field name="TEXT">,
        </field></block></value></block></value></block></value></block></value></block></value><value
        name="itemName"><shadow type="oh_item"
        id="twXvexUE!VCpKZ-`C3gK"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="(W@h/e;*YtM+uwNeS%)~"><mutation itemName="GuenstigsteTankstelle"
        itemLabel="Günstigste Tankstelle"></mutation><field
        name="itemName">GuenstigsteTankstelle</field></block></value><next><block
        type="variables_set" id="^Lw#Kn*Y^Lp{iYg*7~7-"><field name="VAR"
        id=",d#`NQzJsQQhwQ]KdEl=">preisListeSorted</field><value
        name="VALUE"><block type="lists_sort" id="dq)47+B;ass$dq@k(=4o"><field
        name="TYPE">TEXT</field><field name="DIRECTION">1</field><value
        name="LIST"><block type="variables_get" id=";6/P9FUXbC[gB61FFwxu"><field
        name="VAR"
        id="O|@26=ylARRtEUm}jT77">preisListe</field></block></value></block></value><next><block
        type="oh_event" id="rTo=KgMHeY$1is=n?M9Y"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="bc4_BV]VEJcLH!GX%g4H"><field
        name="TEXT">value</field></shadow><block type="text_join"
        id="eQ_#Tj5~^9$x2Gw2!K/X"><mutation items="2"></mutation><value
        name="ADD0"><block type="text" id="=on%c!7PJ]2*MDr7?Ck9"><field
        name="TEXT">⛽ </field></block></value><value name="ADD1"><block
        type="oh_text_replace" id="=uoBmQ$`-Og$5w6d?b3+"><value
        name="pattern"><shadow type="text" id="q-zzzy5ZWA7R4.QFapAt"><field
        name="TEXT">pattern</field></shadow><block type="text"
        id="fOna@b-olH$PRPCadkd$"><field
        name="TEXT">,</field></block></value><value name="replacement"><shadow
        type="text" id=")5tY(@1_WbEWTb?sAwv$"><field
        name="TEXT">replacement</field></shadow><block type="text"
        id="qm_}9PWN{5j@w)MQ|WZt"><field name="TEXT">€
        </field></block></value><value name="origin"><shadow type="text"
        id="X)Zv]xom;2?YYjm^~ZKe"><field
        name="TEXT">origin</field></shadow><block type="oh_text_replace"
        id="fEVP5EUUQZ,/PrF9Sjn4"><value name="pattern"><shadow type="text"
        id="q-zzzy5ZWA7R4.QFapAt"><field
        name="TEXT">pattern</field></shadow><block type="text"
        id="0fgc*j4_^1I*l;Mm[Hl["><field
        name="TEXT">Diesel</field></block></value><value
        name="replacement"><shadow type="text" id=")5tY(@1_WbEWTb?sAwv$"><field
        name="TEXT">replacement</field></shadow><block type="text"
        id="/^pC?]Kd(noRVyshQdbb"><field
        name="TEXT"></field></block></value><value name="origin"><shadow
        type="text" id="S+kN*[koJdh:%8]2pV;x"><field
        name="TEXT">origin</field></shadow><block type="lists_split"
        id="y8_2+,vZ/i%]XRTsWWCF"><mutation mode="JOIN"></mutation><field
        name="MODE">JOIN</field><value name="INPUT"><block type="variables_get"
        id="gQT:2ih=Q:l}pc^wa_r/"><field name="VAR"
        id=",d#`NQzJsQQhwQ]KdEl=">preisListeSorted</field></block></value><value
        name="DELIM"><shadow type="text" id="4]cVdVFbSepVR}[[085;"><field
        name="TEXT">,</field></shadow><block type="text_join"
        id="E^4/AlB){?16J.Lr,H,D"><mutation items="2"></mutation><value
        name="ADD0"><block type="oh_text_crlf"
        id=":k2]H+Ai`4pC3x@n}Co]"></block></value><value name="ADD1"><block
        type="text" id="H}A~@ccwqo]D?(.M7`lK"><field name="TEXT">⛽
        </field></block></value></block></value></block></value></block></value></block></value></block></value><value
        name="itemName"><shadow type="oh_item"
        id="twXvexUE!VCpKZ-`C3gK"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id=",-CdX=7b;gkvQw/ssY78"><mutation itemName="PreiseTankstelle"
        itemLabel="Preise Tankstellen"></mutation><field
        name="itemName">PreiseTankstelle</field></block></value><next><block
        type="oh_log" id="_#vPLsDg0dp1{H`Em9^Z"
        disabled-reasons="MANUALLY_DISABLED"><field
        name="severity">error</field><value name="message"><shadow type="text"
        id="K5-(gt@y2j!3@B;+BPN1"><field name="TEXT">abc</field></shadow><block
        type="text_join" id="{_rIsy:qAFZ(}77lFRQk"><mutation
        items="6"></mutation><value name="ADD0"><block type="text"
        id="7Pn=E0=Kit6^*E^d*FjO"><field name="TEXT">Tanken:
        </field></block></value><value name="ADD1"><block
        type="oh_getitem_attribute" id="saNJ=jH,}|[G=$Md{{U}"><mutation
        attributeName="NumericState"></mutation><field
        name="attributeName">NumericState</field><value name="item"><shadow
        type="oh_getitem" id="M4u,MIQpd9/TWvTj]=RE"><value
        name="itemName"><shadow type="oh_item"
        id="wr}$D9OzL.WS13Wf6ODG"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="oh_item" id="j*yt`OtI^;qXuKhEp6pz"><mutation
        itemName="Treibstoffpreise"
        itemLabel="Treibstoffpreise"></mutation><field
        name="itemName">Treibstoffpreise</field></block></value></block></value><value
        name="ADD2"><block type="text" id="-~N/NOOwU.r6bYezg?|y"><field
        name="TEXT">€ </field></block></value><value name="ADD3"><block
        type="lists_split" id="e=V9KP*ys,U2uae@(VBs"><mutation
        mode="JOIN"></mutation><field name="MODE">JOIN</field><value
        name="INPUT"><block type="variables_get"
        id="C)l}%}ahi{/4.~RH047R"><field name="VAR"
        id="M,b9Dc|;`5AiV}L~=7v,">nameListe</field></block></value><value
        name="DELIM"><shadow type="text" id="4]cVdVFbSepVR}[[085;"><field
        name="TEXT">,</field></shadow><block type="text"
        id="4:Rt7E:_QNONkvi!y_S-"><field name="TEXT">,
        </field></block></value></block></value><value name="ADD4"><block
        type="oh_text_crlf" id="4dMNO51q`}:on30*P?jj"
        disabled-reasons="MANUALLY_DISABLED"></block></value><value
        name="ADD5"><block type="text_join" id="6:}{r|?zXgkg~{MrmgI2"><mutation
        items="2"></mutation><value name="ADD0"><block type="text"
        id="o)+!(xWawz;A$6q3l*oK"><field name="TEXT">⛽
        </field></block></value><value name="ADD1"><block type="oh_text_replace"
        id="n`k[}*}1gRd6|^/t63u@"><value name="pattern"><shadow type="text"
        id="q-zzzy5ZWA7R4.QFapAt"><field
        name="TEXT">pattern</field></shadow><block type="text"
        id="yE]/O=@2^hhI8k3EJ]kj"><field
        name="TEXT">,</field></block></value><value name="replacement"><shadow
        type="text" id=")5tY(@1_WbEWTb?sAwv$"><field
        name="TEXT">replacement</field></shadow><block type="text"
        id="?/hM95#bY9XeT~FH+IVW"><field name="TEXT">€
        </field></block></value><value name="origin"><shadow type="text"
        id="X)Zv]xom;2?YYjm^~ZKe"><field
        name="TEXT">origin</field></shadow><block type="oh_text_replace"
        id="m/XLB|L}%9$@_9NN[0r`"><value name="pattern"><shadow type="text"
        id="q-zzzy5ZWA7R4.QFapAt"><field
        name="TEXT">pattern</field></shadow><block type="text"
        id="%V%-Stkt]gl.H.*0~feR"><field
        name="TEXT">Diesel</field></block></value><value
        name="replacement"><shadow type="text" id=")5tY(@1_WbEWTb?sAwv$"><field
        name="TEXT">replacement</field></shadow><block type="text"
        id="1Hy5pJUdC}~K/SsA?qlN"><field
        name="TEXT"></field></block></value><value name="origin"><shadow
        type="text" id="S+kN*[koJdh:%8]2pV;x"><field
        name="TEXT">origin</field></shadow><block type="lists_split"
        id="c;fMZS77:wyHHSt+VNMb"><mutation mode="JOIN"></mutation><field
        name="MODE">JOIN</field><value name="INPUT"><block type="variables_get"
        id="F+DwItNsqzJ`:PMGc^dA"><field name="VAR"
        id=",d#`NQzJsQQhwQ]KdEl=">preisListeSorted</field></block></value><value
        name="DELIM"><shadow type="text" id="4]cVdVFbSepVR}[[085;"><field
        name="TEXT">,</field></shadow><block type="text"
        id="3pMTsjAD@;CHfEU6MYK/"><field name="TEXT">⛽
        </field></block></value></block></value></block></value></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></xml>'
      type: application/javascript
      script: |
        var preisListe, nameListe, i, preisListeSorted;

        function listsGetSortCompare(type, direction) {
          var compareFuncs = {
            'NUMERIC': function(a, b) {
                return Number(a) - Number(b); },
            'TEXT': function(a, b) {
                return String(a) > String(b) ? 1 : -1; },
            'IGNORE_CASE': function(a, b) {
                return String(a).toLowerCase() > String(b).toLowerCase() ? 1 : -1; },
          };
          var compare = compareFuncs[type];
          return function(a, b) { return compare(a, b) * direction; };
        }


        preisListe = [];
        nameListe = [];
        var i_list = items.getItem('Treibstoffpreise').members;
        for (var i_index in i_list) {
          i = i_list[i_index];
          if (i.numericState == items.getItem('Treibstoffpreise').numericState) {
            nameListe.push(i.label);
          }
          preisListe.push([i.numericState, i.label]);
        }
        items.getItem('GuenstigsteTankstelle').sendCommand(([items.getItem('Treibstoffpreise').numericState,'€: ',String((nameListe.join(', ')).replaceAll(' Diesel',''))].join('')));
        preisListeSorted = preisListe.slice().sort(listsGetSortCompare("TEXT", 1));
        items.getItem('PreiseTankstelle').sendCommand(('⛽ ' + String((preisListeSorted.join('\r\n' + '⛽ ')).replaceAll('Diesel','').replaceAll(',','€ '))));
    type: script.ScriptAction
Hat jemand einen Tipp wie ich das schaffe?

Gruß Lenschi

Re: String-Item zeigt Zeilenumbrüche nicht an

Verfasst: 22. Apr 2026 17:33
von Harka
Moin,
wir hatte was ähnliches erst. Möglicherweise hilft es Dir.
Harka hat geschrieben: 29. Mär 2026 21:02
hermann59 hat geschrieben: 28. Mär 2026 18:10 Was mir aber absolut unklar ist, wie ich ein Item in der UI anzeige, dessen Wert eine Liste von Strings ist.
Moin,
habe gerade auf Grundlage von https://community.openhab.org/t/multili ... -ui/161544 eine mögliche Lösung gefunden

Code: Alles auswählen

component: oh-list-card
config: {}
slots:
  default:
    - component: Label
      config:
        text: =@'StringZumTesten'
        style:
          height: 10em
          white-space: pre-wrap
          word-break: break-word
          overflow-y: scroll
Als Zeilentrennung dient mir '\r\n' aber '\n' sollte auch reichen.

Re: String-Item zeigt Zeilenumbrüche nicht an

Verfasst: 22. Apr 2026 19:46
von lenschith
Das \n habe ich schon im Textblock versucht, aber das Blockly maskiert das automatisch mit \\n und wird dann als Text angezeigt. Wenn ich den Block CRLF verwende wird im String item nur ein größerer Abstand gemacht aber keine neue Zeile.

Und ich will das im item für die klassische Sitemap und nicht für ein widget

Re: String-Item zeigt Zeilenumbrüche nicht an

Verfasst: 22. Apr 2026 20:24
von Harka
CRLF hatte ich doch auch genutzt :)
Bei der die klassische Sitemap bin ich raus.

Re: String-Item zeigt Zeilenumbrüche nicht an

Verfasst: 23. Apr 2026 13:02
von udo1toni
Sitemaps sollten mehrzeiligen Text eigentlich gar nicht unterstützen.

Re: String-Item zeigt Zeilenumbrüche nicht an

Verfasst: 23. Apr 2026 13:09
von lenschith
Also mehrzeilig wird mir das schon angezeigt. Das ist nicht das Problem. Also zumindest am Mobilen Gerät mit der openHAB App.
Im Browser geht das nicht, Stimmt. Aber bei mir geht's um die Mobile App für Android. Aber hier wird das CRLF nicht interpretiert. im Browser wird es mir so angezeigt.

Test String 2
Zeile 1��Zeile 2��Zeile 3