Page 1 of 1
Dzvents script, help appreciated
Posted: Thursday 22 August 2024 22:58
by HvdW
Code: Select all
local devicesToCheck =
{
'Inv 122315002511', 'Inv 122315025460', 'Inv 122315031819', 'Inv 122315032050', 'Inv 122315032284', 'Inv 122315037624', 'Inv 122315042557', 'Inv 122315042561', 'Inv 122315043359', 'Inv 122315043462', 'Inv 122315045441', 'Inv 122315045526', 'Inv 122315045527', 'Inv 122315045546', 'Inv 122315045550', 'Inv 122315045550', 'Inv 122315045888',
}
return
{
on =
{
devices = devicesToCheck,
timer =
{
'every 1 minutes',
},
},
data =
{
notified = { initial = {} },
},
logging =
{
level = domoticz.LOG_DEBUG, -- change from LOG_DEBUG to LOG_ERROR when script executes without problems
marker = 'Enphase weergeven ',
},
execute = function(dz, item)
if item.isTimer then
for index, deviceName in ipairs(devicesToCheck) do
local device = dz.devices(deviceName)
dz.log('device name ' .. device.name, dz.LOG_DEBUG)
-- dz.log('device state ' .. device.state, dz.LOG_DEBUG)
-- dz.log('device lastUpdate ' .. device.lastUpdate.minutesAgo, dz.LOG_DEBUG)
dz.log('device nValue ' .. device.nValue, dz.LOG_DEBUG)
dz.devices('Enphase totaal').updateText('Inverter ' .. device.name ..' '.. tostring(device.nValue).. ' Watt ' ..'\n\n')
end
-- dz.devices(38).dump()
end
end
}
--end
I know this script updates the text 17 times on one line.
Can you give me a hint how to display 17 lines with information for every inverter?
To display many lines I'm using this construct:
Code: Select all
domoticz.devices('Heating').updateText('Room temperature   ' .. math.floor(domoticz.devices('Tado Kamer Temp').temperature*10)/10 .. ' °C'..
'\n Room temp. setpoint  ' .. domoticz.devices('Tado Kamer Setpoint').setPoint .. ' °C'..
'\n Room heating       ' .. tostring(math.floor(domoticz.devices('Tado Kamer Heating').percentage)) .. '%'..
'\n \n Kitchen temperature   ' .. tostring(math.floor(domoticz.devices('Tado Keuken Temp').temperature*10)/10) .. ' °C'..
'\n      Kitchen temp. setpoint  ' .. domoticz.devices('Tado Keuken Setpoint').setPoint .. ' °C'..
'\n      Kitchen heating     ' .. tostring(math.floor(domoticz.devices('Tado Keuken Heating').percentage)) .. '%'..
'\n \n      Outside temperature   ' .. tostring(math.floor(domoticz.devices('Buitentemperatuur').temperature*10)/10) .. ' °C'..
'\n ')
I guess I should use an array and extract data from the array to display the results.
Just don't know how to do it.
Re: Dzvents script, help appreciated
Posted: Thursday 22 August 2024 23:12
by waltervl
Just make a Domoticz room with the 17 inverters and you have all the data in one view when selecting that room....
Be sure you have your switch log settings correct because you are making a lot of useless database entries now.
Also the every minute trigger is probably not needed as you text device will be updated on every change on one of the inverter devices ...
For filling the text device it is just fine as you do it now. Making an array out of it won't do anything better.
Re: Dzvents script, help appreciated
Posted: Friday 23 August 2024 0:37
by HvdW
waltervl wrote: ↑Thursday 22 August 2024 23:12
Just make a Domoticz room with the 17 inverters and you have all the data in one view when selecting that room....
That is the option I don't want.
waltervl wrote: ↑Thursday 22 August 2024 23:12
Be sure you have your switch log settings correct because you are making a lot of useless database entries now.
Also the every minute trigger is probably not needed as you text device will be updated on every change on one of the inverter devices ...
Indeed, thanks.
waltervl wrote: ↑Thursday 22 August 2024 23:12
For filling the text device it is just fine as you do it now. Making an array out of it won't do anything better.
No that's not correct. It fills 1 line 17 times over the prior line and ends up displaying # 17.
I'd like to have 17 lines below each other.
Re: Dzvents script, help appreciated
Posted: Friday 23 August 2024 7:28
by gizmocuz
I know this is not a solution for inside Domoticz/dzVents, but you could also use grafana (easy to install with docker-compose and the domoticz mqtt-pusher), and have a graph that looks like this:

- Inverters.jpg (42.72 KiB) Viewed 1221 times
You could also let this displayed as a grid/table
Re: Dzvents script, help appreciated
Posted: Friday 23 August 2024 9:03
by waltervl
Your text update command seems to make one string out of it so it is strange you only see the last part.
Perhaps test it with a dummy text or only one or 2 device values.
Re: Dzvents script, help appreciated
Posted: Friday 23 August 2024 10:20
by HvdW
Thanks @gizmocus
Maybe I'll try the Grafana later on.
@waltervl
Because it is in the loop it rewrites the line 17 times. Just 2 rewrites the line 2 times, so the visual effect is just the last line that is displayed.
It's more the challenge of writing a script and not being smart in handling arrays that made me ask the question.
I'll have a look at @janpep scripts. As far as I remember he uses arrays for handling data.
Re: Dzvents script, help appreciated
Posted: Friday 23 August 2024 11:28
by madpatrick
Maybe this is an example you can use.
It shows the activated devices in a textblock.
This textblock is visible in Domoticz and on my Tablet with Dashticz
Code: Select all
local scriptVar = "-=# Deursensors #=-"
local textblock = 477
local doorDevices = {
['Deur Erker'] = 182, -- 'Sensor - Erkerdeur',
['Deur Achter'] = 188, -- 'Sensor - Achterdeur',
['Deur Garage'] = 471, -- 'Sensor - Garagedeur',
['Deur Balkon'] = 474, -- 'Sensor - Balkondeur',
['Raam Thomas'] = 758, -- 'Sensor - Raam Thomas',
}
return {
on = { devices = {182,188,471,474,537},
},
logging = {
level = domoticz.LOG_STATUS, -- change to domoticz.LOG_ERROR when all OK
marker = scriptVar
},
data = {
lastState = { initial = "" }
},
execute = function(dz, item)
if item.state ~= dz.data.lastState then
dz.log("Script triggered : " .. item.name .. " has changed state to " .. item.state, dz.LOG_FORCE)
dz.data.lastState = item.state
else
dz.log("Script triggered : " .. item.name .. " has kept state " .. item.state, dz.LOG_FORCE)
end
local need = {}
for name,idx in pairs(doorDevices) do
if dz.devices(idx).state == 'Open' then
table.insert(need, name)
end
end
local doorText
local count = #need
if count > 0 then
doorText = 'Deur'
for i, name in pairs (need) do
if i == 1 then
doorText = '<i class="fa-solid fa-door-open fa-lg" style="color: #FFD43B;"></i> ' ..name..' is Open'
--print(doorText)
else
doorText = doorText..'<br><i class="fa-solid fa-door-open fa-lg" style="color: #FFD43B;"></i> ' ..name..' is Open'
--print(doorText)
end
end
else
doorText = ' '
end
local textblock = dz.devices(textblock)
textblock.updateText(doorText)
end
}
Re: Dzvents script, help appreciated
Posted: Friday 23 August 2024 13:38
by HvdW
I'll go try this tonight. Seems like a good idea for many applications.