Page 1 of 1
multiple textlines in textdevice
Posted: Thursday 11 April 2019 8:40
by Gravityz
Hello,
i have a textdevice which i use to display the last status.
is there a way to display multiple lines so i can use it as a log.
e.g. i use this comand at the moment
domoticz.devices('Status').updateText('Woonkamer lampen ingeschakeld')
which displays Woonkamer lampen ingeschakeld
now when i issue a second command like
domoticz.devices('Status').updateText('Alarm ingeschakeld')
i want to see the most actual one on top and the other one below
Alarm ingeschakeld
Woonkamer lampen ingeschakeld
i know this can be done in lua(but i do not know how) butdoes this work in dzvents
Re: multiple textlines in textdevice
Posted: Thursday 11 April 2019 8:50
by zygios
Hi,
I'm using this:
Code: Select all
departimestext = departimestext .. ' '..departime ..';\r\n'
and result for text device is next:
Status: 08:21:24
08:23:30
08:29:00
You get check in my GIT:
https://github.com/zygios/Domoticz_scri ... nsport.lua
Re: multiple textlines in textdevice
Posted: Thursday 11 April 2019 10:46
by Gravityz
Thanks,
got is working(sort of)
the problem i have now i need to limit the amount of lines to max 5 i think
is there an easy way to do this
this is my code
currentstatus = domoticz.devices('Status').state ..'\r\n'
newstatus = 'Woonkamer lampen sfeervol ingeschakeld'
currentstatus = newstatus .. ';\r\n'..currentstatus ..'\r\n'
domoticz.devices('Status').updateText(currentstatus)

- Knipsel.JPG (42.38 KiB) Viewed 1379 times
Re: multiple textlines in textdevice
Posted: Thursday 11 April 2019 11:41
by zygios
try this code:
Code: Select all
limit_max = 5
for m = 1, limit_max do
currentstatus = domoticz.devices('Status').state ..'\r\n'
newstatus = 'Woonkamer lampen sfeervol ingeschakeld'
currentstatus = newstatus .. ';\r\n'..currentstatus ..'\r\n'
m = m + 1
end
domoticz.devices('Status').updateText(currentstatus)
Re: multiple textlines in textdevice
Posted: Thursday 11 April 2019 11:52
by Gravityz
hm. wonder if this works
this script is called everytime somebody comes/leaves or when a schedule kicks in.
m is not a global variable so i think every time the script is called m=1
in case it does remember after 5 times it will not refresh anymore
Re: multiple textlines in textdevice
Posted: Thursday 11 April 2019 12:01
by zygios
Try this:
Code: Select all
limit_max = 4
temp_stastus = ''
m = 1
currentstatus = domoticz.devices('Status').state
--removing 5-th status
for i in string.gmatch(currentstatus, "[^\r\n]+") do
print(i)
if m <=4 then
temp_stastus = temp_stastus .. i.. "\r\n";
m = m + 1
end
end
newstatus = 'Woonkamer lampen sfeervol ingeschakeld'
currentstatus = newstatus .. ';\r\n'..temp_stastus
domoticz.devices('Status').updateText(currentstatus)
Re: multiple textlines in textdevice
Posted: Thursday 11 April 2019 13:41
by Gravityz
this indeed works with limiting the messages
however as far as i can see the top line is changing but the others are not.
the idea is that when things change the old messages shift down.
eg
a
b
c
d
e
new message f
f
a
b
c
d
new message h
h
f
a
b
c
i think i need to combine things from the old code and your new code but this is looking promising
Re: multiple textlines in textdevice
Posted: Friday 12 April 2019 8:52
by waaren
Gravityz wrote: ↑Thursday 11 April 2019 13:41
this indeed works with limiting the messages
however as far as i can see the top line is changing but the others are not.
the idea is that when things change the old messages shift down.
If I understand your requirement correct, the function addRollingTextLine in below script should do it.
Code: Select all
return {
on = {
timer = { 'every minute' },
},
logging = { level = domoticz.LOG_DEBUG ,
marker = "multiLine text function"},
execute = function(dz, item)
local function addRollingTextLine(textDevice, line, maxLines)
local function stringSplit(str)
local lines = {}
for s in str:gmatch("[^\r\n]+") do
table.insert(lines, s)
end
return lines
end
local function checkParms()
if not textDevice or ( type(textDevice) ~= "string" and type(textDevice) ~= "table" ) then
dz.log("textDevice should be of type table or string; now: " .. (tostring(textDevice) or type(textDevice)),dz.LOG_ERROR)
return false
elseif type(textDevice) == "string" then
textDevice = dz.devices(textDevice)
end
if not line then
dz.log("No text supplied",dz.LOG_ERROR)
return false
end
if not maxLines then maxLines = 5 end -- default
return true
end
if checkParms() then
local lines = textDevice.text or ""
lines = stringSplit(lines)
lines[0] = line
local newText = ""
for i = 0, ( maxLines - 1) do
newText = newText .. ( lines[i] or "" ) .. "\r\n"
end
textDevice.updateText(newText)
else
return false
end
end
-- Test call
addRollingTextLine("multiLine", dz.time.raw, 3)
end
}
Re: multiple textlines in textdevice
Posted: Saturday 13 April 2019 17:04
by Gravityz
Hi waaren.
that code works very nice

- Knipsel2.JPG (21.46 KiB) Viewed 1289 times
the only downfall is that i need to add it to every script that is updating the status device.
is it possible to put this into some kind of module or helper function.
eg declare it once and then call it from every script you like
Re: multiple textlines in textdevice
Posted: Saturday 13 April 2019 18:54
by waaren
Gravityz wrote: ↑Saturday 13 April 2019 17:04
the only downfall is that i need to add it to every script that is updating the status device.
is it possible to put this into some kind of module or helper function.
eg declare it once and then call it from every script you like
Have a look
here where exactly that is described in detail
Re: multiple textlines in textdevice
Posted: Saturday 13 April 2019 19:45
by Gravityz
Thanks waaren, you made my day.
i have read that myhelper part multiple times over and over again and could not figur out how it was working, until now.
after reading MORE CAREFULLY i noticed what i was doing wrong
working perfectly now
i now can use the Status textdevice as a logging device lights on/of alarm on/off sunscreen in/out. al the things i normally wrote to the log are now visible