Dzvents script, help appreciated

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

Moderator: leecollings

Post Reply
HvdW
Posts: 617
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Dzvents script, help appreciated

Post 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 ..'&nbsp'.. 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.
Bugs bug me.
User avatar
waltervl
Posts: 5902
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Dzvents script, help appreciated

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 617
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Dzvents script, help appreciated

Post 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.
Bugs bug me.
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Dzvents script, help appreciated

Post 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
Inverters.jpg (42.72 KiB) Viewed 1218 times
You could also let this displayed as a grid/table
Quality outlives Quantity!
User avatar
waltervl
Posts: 5902
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Dzvents script, help appreciated

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 617
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Dzvents script, help appreciated

Post 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.
Bugs bug me.
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Dzvents script, help appreciated

Post 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
}
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
HvdW
Posts: 617
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Dzvents script, help appreciated

Post by HvdW »

I'll go try this tonight. Seems like a good idea for many applications.
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest