multiple textlines in textdevice
Moderator: leecollings
-
- Posts: 587
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2022.2
- Location: Netherlands
- Contact:
multiple textlines in textdevice
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
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
Hi,
I'm using this:
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
I'm using this:
Code: Select all
departimestext = departimestext .. ' '..departime ..';\r\n'
Status: 08:21:24
08:23:30
08:29:00
You get check in my GIT:
https://github.com/zygios/Domoticz_scri ... nsport.lua
-
- Posts: 587
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2022.2
- Location: Netherlands
- Contact:
Re: multiple textlines in textdevice
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
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)
Re: multiple textlines in textdevice
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)
-
- Posts: 587
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2022.2
- Location: Netherlands
- Contact:
Re: multiple textlines in textdevice
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
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
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)
-
- Posts: 587
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2022.2
- Location: Netherlands
- Contact:
Re: multiple textlines in textdevice
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
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: multiple textlines in textdevice
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 587
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2022.2
- Location: Netherlands
- Contact:
Re: multiple textlines in textdevice
Hi waaren.
that code works very nice
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
that code works very nice
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
Last edited by Gravityz on Saturday 13 April 2019 19:05, edited 1 time in total.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: multiple textlines in textdevice
Have a look here where exactly that is described in detail
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 587
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2022.2
- Location: Netherlands
- Contact:
Re: multiple textlines in textdevice
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
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
Who is online
Users browsing this forum: No registered users and 1 guest