struggle with text in textdevice

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
BartSr
Posts: 347
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.3
Location: Netherlands
Contact:

struggle with text in textdevice

Post by BartSr »

I'm struggling with a textdevice which I want to show information on two (2) lines.

command in dzVents

Code: Select all

dz.devices(1642).updateText('line 1'..'\n line 2')
this results in:

Code: Select all

line1 line2

but I expected

Code: Select all

line1
line2
what's wrong?
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: struggle with text in textdevice

Post by HvdW »

Change it to:

Code: Select all

dz.devices(1642).updateText('line 1\n line 2')
or

Code: Select all

local textSensor = dz.devices(1642)
            if textSensor then
                local text = 'line1'..
                '\n\n line2'  
                textSensor.updateText(text)
             end
Bugs bug me.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: struggle with text in textdevice

Post by waltervl »

According Dummy wiki for text sensors: you get multiple lines when adding \r\n to the string

https://www.domoticz.com/wiki/Dummy_for ... ext_sensor
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
BartSr
Posts: 347
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.3
Location: Netherlands
Contact:

Re: struggle with text in textdevice

Post by BartSr »

The problem is weird.
It apprears that the text-device itself had no problem but it occurs once the same textdevice is placed on floorplan.
textdevice.jpg
textdevice.jpg (16.31 KiB) Viewed 783 times
Attachments
text-floorplan.jpg
text-floorplan.jpg (2.31 KiB) Viewed 783 times
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
User avatar
RonkA
Posts: 95
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2023.2
Location: Harlingen
Contact:

Re: struggle with text in textdevice

Post by RonkA »

Don't use floorplan (not yet..) but try maybe:

Code: Select all

dz.devices(1642).updateText('line 1<br>line 2')
SolarEdge ModbusTCP - Open Weather Map - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
BartSr
Posts: 347
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.3
Location: Netherlands
Contact:

Re: struggle with text in textdevice

Post by BartSr »

@Ronka
thanks for suggestion.
your solution works fine for textdevice but if it's on a floorplan it shows up as:
bug.jpg
bug.jpg (2.35 KiB) Viewed 752 times
feels like being a bug
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: struggle with text in textdevice

Post by waltervl »

Bug or perhaps intended to not have too much data on the floorplan.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
BartSr
Posts: 347
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.3
Location: Netherlands
Contact:

Re: struggle with text in textdevice

Post by BartSr »

Walter, I expect 1st: bug. I will report abot it.
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: struggle with text in textdevice

Post by waltervl »

Looking at this part of code in the floorplan it looks like it should work with line breaks.
https://github.com/domoticz/domoticz/bl ... s.js#L1891

Code: Select all

        this.data = item.Data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
        if (this.data.indexOf("<br />") != -1) {
            this.hasNewLine = true;

Perhaps look with source code option in a browser if you see the <br /> in html
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: struggle with text in textdevice

Post by waltervl »

waltervl wrote: Thursday 07 November 2024 23:23 Looking at this part of code in the floorplan it looks like it should work with line breaks.
https://github.com/domoticz/domoticz/bl ... s.js#L1891

Code: Select all

        this.data = item.Data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
I asked AI what this should do and it came up with the following description:
This JavaScript line uses a regular expression to replace newline characters in a string with HTML line break tags (<br />).
Here’s a breakdown of how it works:

Regular Expression: /([^>\r\n]?)(\r\n|\n\r|\r|\n)/g
- ([^>\r\n]?): This captures any character that is not > or a newline character, zero or one time.
- (\r\n|\n\r|\r|\n): This captures any of the newline sequences (\r\n, \n\r, \r, or \n).
The g flag at the end indicates a global search, meaning it will replace all occurrences in the string.

Replacement String: '$1<br />$2'
- $1: Refers to the first captured group (any character not > or a newline).
- <br />: Inserts an HTML line break.
- $2: Refers to the second captured group (the newline sequence).

In essence, this line of code ensures that every newline in the string is replaced with an HTML line break, preserving the newline characters themselves. This is useful for displaying text with line breaks in HTML.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
RonkA
Posts: 95
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2023.2
Location: Harlingen
Contact:

Re: struggle with text in textdevice

Post by RonkA »

Man.. this is quickly turning in to a rabbit hole..
In HTML (up to HTML 4): use <br>

In HTML 5: <br> is preferred, but <br/> and <br /> is also acceptable

In XHTML: <br /> is preferred. Can also use <br/> or <br></br>

Notes:

<br></br> is not valid in HTML 5, it will be thought of as two line breaks.
XHTML is case sensitive, HTML is not case sensitive.
For backward compatibility, some old browsers would parse XHTML as HTML and fail on <br/> but not <br />
So.. <br /> is the way?!?
SolarEdge ModbusTCP - Open Weather Map - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
BartSr
Posts: 347
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.3
Location: Netherlands
Contact:

Re: struggle with text in textdevice

Post by BartSr »

sorry, no same result as on yr previous proposel....
commenting using mobile so can't drop screenshot
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest