error in dzvents  [Solved]

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

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

error in dzvents

Post by pvklink »

Hi, can't find the cause off my error. It is on line 60 and i disabled it.
i changed the script from using device into item and then the error came up...

error

Code: Select all

2019-07-06 16:02:37.047 Error: dzVents: Error: (2.4.24) Watermeting: An error occurred when calling event handler DZ_regensensor
2019-07-06 16:02:37.047 Error: dzVents: Error: (2.4.24) Watermeting: ...icz/scripts/dzVents/generated_scripts/DZ_regensensor.lua:60: attempt to concatenate field 'name' (a nil value)
script

Code: Select all

-- meet het aantal keer dat de watersensor in een uur een on afgeeft. 
-- als aantal keer on klopt dan gaat schakelaar hetregent aan voor een periode. In die periode wordt er niet autom gesproeid
-- als de schakelaar al aanstaat en er sensor is opgedroogd en het regent weer in de periode dat de schakelaar aanstaat , wordt er een nieuwe timer gezet (queue leeg en nieuw off commando)

return {
    on      =    {devices = {'$tuinwatersensor'}},

    logging =   { 
                    level   = domoticz.LOG_ERROR ,                  -- Uncomment to override the dzVents global logging setting
                    marker  = "Watermeting" 
                },
              
    data    =   {
                    raintable = { history = true,  maxHours = 1 },
                },
        
    execute = function(dz, item, info)
        
        local norm          = 5             -- was 5 maar als bert de tuin sproeit duurt dat een half uur en 43 stuks
        local huidwaarde    = item.state 
        local now           = os.time(os.date('*t'))      
--      local DurTimer      = 800           -- default 800 wort niet gebruikt zie DZ_schakelaar

        local logcode = 3
        local messageTable = {}
        local add = 'add'
        local del = 'del'
        local chg = 'chg'
        
        local function globalMessage(action, message, logcode)
 
            if logcode == nil then logcode = 3 end
 
            if action == add and logcode > 0 then
                messageTable = dz.helpers.addMessage(dz, item, info, message, messageTable, logcode)
            elseif action == del then
                dz.globalData.mylogging = message
                dz.devices('timerlog').updateText(message)
            elseif action == chg then 
                dz.helpers.dumpMessages(dz, messageTable)
            end
 
        end

        if huidwaarde == nil then               -- onderstaande checks moeten na de locals omdat ze deze ook gebruiken!
            dz.log("01 Sensor info         = Geen waarde opgehaald")
        else
            dz.data.raintable.add(huidwaarde)
        end

        local aantal = 0
        for i = dz.data.raintable.size,1,-1 do 
            aantal = aantal +1
            item = dz.data.raintable.get(i)
            dz.log("00 History data van " .. item.time.rawDate .. " " .. item.time.rawTime .. 
                                    " = " .. item.data)
        end

        dz.log("Deviceinfo---------------------------------------")
        --dz.log("00 Sensor...........................= " .. item.name)   --geeft n fout
        dz.log("00 Switch-device....................= " .. dz.devices('hetregent').name)
        --dz.log("00 Uitzetten na(in.min).............= " .. DurTimer)
        dz.log("Sensor info-------------------------------------")
        dz.log("00 Aantal norm......................= " .. norm)
        dz.log("00 Aantal gemeten...................= " .. aantal)
        dz.log("00 Aantal huidige waarde............= " .. huidwaarde)
        dz.log("00 Laatste update...................= " .. tostring(dz.devices('hetregent').lastUpdate.rawTime)) -- deze is goed
        dz.log("-------------------------------------------------")

    if  aantal >= norm  then 
        -- .checkFirst() verwijderd bij dz.devices('hetregent') en dz.devices('regensensor') want de timer moet opnieuw worden gezet!
        dz.devices('hetregent').cancelQueuedCommands()
        dz.devices('hetregent').switchOn()
        dz.devices('regensensor').cancelQueuedCommands()
        dz.devices('regensensor').switchOn()
        --dz.devices('hetregent').switchOff().afterMin(DurTimer)

        globalMessage(add, ' SENSOR: Regendruppel signalen (' .. aantal .. ') is gelijk of boven de norm(' .. norm .. '), ' .. dz.devices('hetregent').name .. ' wordt geactiveerd...',logcode)
        globalMessage(chg) -- dump

    end

end
}

Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: error in dzvents

Post by waaren »

pvklink wrote: Sunday 07 July 2019 21:30 Hi, can't find the cause off my error. It is on line 60 and i disabled it.
i changed the script from using device into item and then the error came up...
In line 54

Code: Select all

item = dz.data.raintable.get(i)
you overwrite the table item

Best to use another name for that variable and always declare variables as local to limit the scope of them if you don't have a (very rare) absolute need to use them globally.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: error in dzvents  [Solved]

Post by pvklink »

thanks!
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest