Break Line in String

Hi,
I would like to write in an item (String) this text:

“i’m alfa
u’re beta”

i tryed several things but nothing works, a few of them are:

myItem.sendCommand(“i’m alfa \\n\\r u’re beta”)
myItem.sendCommand(“i’m alfa \\r\\n u’re beta”)
myItem.sendCommand(“i’m alfa \n\r u’re beta”)
myItem.sendCommand(“i’m alfa \\n u’re beta”)
myItem.sendCommand(“i’m alfa \\r\\r u’re beta”)
myItem.sendCommand(“i’m alfa \\r u’re beta”)
myItem.sendCommand(“i’m alfa \n u’re beta”)

in all this cases i received in a dummy pannel the output: “i’m alfa u’re beta”

Thanks for your help,
Andrea

What do you see in your events.log ?

Basic UI and Classic UI will not display multiple lines of text, so if that is what you are after, it’s not going to happen. However, you’d see the multiple lines if you logged the state of the Item.

1 Like

Even if it does not work in the output: the characters for linefeed and return need to be escaped with backslashes instead of forward slashes.

1 Like

myItem changed from NULL to i’m alfa

ah, i understand.
mmm what do you mean with “However, you’d see the multiple lines if you logged the state of the Item.”
do you mean in the logs file (event.log) ?

yeah i used that in my program, i’ve had a mistake above sorry

You would see it there, but I was meaning logging the state in your rule.

in event.log i see this:
“2020-11-12 19:20:24.197 [ome.event.ItemCommandEvent] - Item ‘myItem’ received command i’m alfa \n\n u’re beta”

Escape the escapes

Correction… single escapes work fine…

from core.log import logging, LOG_PREFIX#, log_traceback
LOG = logging.getLogger("{}.TEST_3".format(LOG_PREFIX))

events.sendCommand("Virtual_String_1", "i’m alfa\n u’re beta")
#events.postUpdate("Virtual_String_1", "i’m alfa\n u’re beta")
from time import sleep
sleep(1)

LOG.warn(items["Virtual_String_1"])

events.sendCommand("Virtual_String_1", "")
2020-11-12 13:49:08.238 [INFO ] [smarthome.event.ItemCommandEvent] - Item 'Virtual_String_1' received command i’m alfa
 u’re beta
2020-11-12 13:49:08.239 [INFO ] [smarthome.event.ItemStateEvent] - Virtual_String_1 updated to i’m alfa
 u’re beta
2020-11-12 13:49:08.239 [INFO ] [smarthome.event.ItemStateChangedEvent] - Virtual_String_1 changed from  to i’m alfa
 u’re beta

Now look at the next line … you did put a linebreak in there.

yes, in event.log file work, but in the dummy pannel on localhost:8080/habpanel didn’t

there wasn’t nothing in the next line, i guess because i tried some variants of \n

but the problem is not in log file, the problem is in my //localhost:8080/habpanel (in a widget) , even if in log file it show me the right way, in habpanel don’t

1 Like

Okay, so your Item is absolutely fine, and you have a problem configuring your HABpanel.
Tag your post ‘HABpanel’ instead of ‘rules’ for better attention.
None of the sitemap based UIs support multiline Item content, so this is not used often.

I’ve not seen any multiline custom HABpanel widgets, but I would have thought you could make one.

ok!
thank you for your help :slight_smile:

What happens if you use html code ( foo<br>bar or <p>bla</><p>foo</p><p>bar</p> ) to break the lines ? Will html code be escaped by HABpanel and thus not work either ?

i tried that but it didn’t works
i also tried to create a template in habpanel with eval( {{itemValue(‘myItem’) }} ) but without any succes.

I make a solution:

i use a string as item:
item.sendCommand ("i’m alfa \n u’re beta")

meanwhile in habpannel i create a model windget, and there i’ve written:

<div style="white-space: pre-line">{{itemValue('Item')}} </div>