Page 1 of 1

Virtual device attempt to concatenate a nil value (field 'v')

Posted: Friday 25 October 2024 10:33
by hemant5400z
Hi All,

I have a virtual device which keeps track of my monthly total usage (general managed counter) idx 204.
All of a sudden my script stopped working with the following error:
2024-10-25 10:17:11.025 Error: dzVents: An error occurred when calling event handler MaandVerbruik
2024-10-25 10:17:11.025 Error: dzVents: ...data/scripts/dzVents/generated_scripts/MaandVerbruik.lua:36: attempt to concatenate a nil value (field 'v')

bleow the script:

local httpResponses = "monthTotalVerbruik"

return {
on = {
timer = { "every hour" },
--devices = {64},
httpResponses = { httpResponses .. "*" }
},



execute = function(dz, item)
-- ****************************** Your settings below this line ***************************************************
usageDevice = dz.devices(64) -- Replace xxxx with ID of energyDevice you want to track
monthTotal = dz.devices(204) -- Create as virtual managed counter (energy) and change yyyy to the ID of the new device
-- ****************************** No changes required below this line *********************************************

local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end

local function triggerJSON(id, period, delay)
local delay = delay or 0
local URLString = "http://192.168.1.7:8080/json.htm?type=g ... ter&range=" ..
period .. "&idx=" .. id
dz.openURL({ url = URLString,
method = "GET",
callback = httpResponses .. "_" .. period}).afterSec(delay)
end

local function calculateMonthTotal(rt)
local monthTotal = 0
local currentMonth = dz.time.rawDate:sub(1,7)
for id, result in ipairs(rt) do
if rt[id].d:sub(1,7) == currentMonth then
logWrite(rt[id].d .. " ==>> " .. rt[id].v)
monthTotal = monthTotal + rt[id].v + rt[id].v2
end
end
return monthTotal * 1000
end

if not item.isHTTPResponse then
triggerJSON(usageDevice.id, "month")
elseif item.ok then -- statusCode == 2xx
monthTotal.update(0,calculateMonthTotal(item.json.result))
else
logWrite("Could not get (good) data from domoticz. Error (" .. (item.statusCode or 999) .. ")" ,dz.LOG_ERROR)
logWrite(item.data)
end
end
}


I cannot determine what is wrong and why it all of a sudden keeps giving me this error as of Yesterday, all the help appreciated.

Thanks,

Hemant

Re: Virtual device attempt to concatenate a nil value (field 'v')  [Solved]

Posted: Friday 25 October 2024 10:48
by Kedi
I think that in an other thread it was mentioned that the '.v' should be '.v1' now.
Try that.

Re: Virtual device attempt to concatenate a nil value (field 'v')

Posted: Friday 25 October 2024 10:53
by hemant5400z
Hi,

i just changed:
logWrite(rt[id].d .. " ==>> " .. rt[id].v)
monthTotal = monthTotal + rt[id].v + rt[id].v2


into:
logWrite(rt[id].d .. " ==>> " .. rt[id].v1)
monthTotal = monthTotal + rt[id].v1 + rt[id].v2


Does anyone know when this was changed? looks like something recently.

Hemant

Re: Virtual device attempt to concatenate a nil value (field 'v')

Posted: Friday 25 October 2024 10:55
by hemant5400z
Hi,

however my docker version is from deceber 2023 (beta), so there was no update on the docker container.
Hemant

Re: Virtual device attempt to concatenate a nil value (field 'v')

Posted: Friday 25 October 2024 12:33
by Tukker
Hi
You can clarify the response with this code:

Code: Select all

    execute = function(domoticz, item)
        if (item.isTimer) then
            domoticz.openURL({
            -- url = "http://152.53.105.165/api/json whatever
            method = 'GET',
            callback = 'WeerLiveDataRetrieved'
            })
        elseif (item.isHTTPResponse) then
            if (item.ok) then -- statusCode == 2xx
                -- Display all data from weerlive with the domoticz.utils.dumpTable(item.json) statement
                -- domoticz.log(domoticz.utils.dumpTable(item.json),domoticz.LOG_DEBUG)
-- Display all data from weerlive with the domoticz.utils.dumpTable(item.json) statement
domoticz.log(domoticz.utils.dumpTable(item.json),domoticz.LOG_DEBUG)

Re: Virtual device attempt to concatenate a nil value (field 'v')

Posted: Friday 25 October 2024 17:51
by waltervl
hemant5400z wrote: Friday 25 October 2024 10:53 Hi,

i just changed:
logWrite(rt[id].d .. " ==>> " .. rt[id].v)
monthTotal = monthTotal + rt[id].v + rt[id].v2


into:
logWrite(rt[id].d .. " ==>> " .. rt[id].v1)
monthTotal = monthTotal + rt[id].v1 + rt[id].v2


Does anyone know when this was changed? looks like something recently.

Hemant
This was changed in one of the latest release for supporting cost calculation on P1 devices so it seems you have updated your docker system recently. Check menu setup - About what Domoticz version you are running

Re: Virtual device attempt to concatenate a nil value (field 'v')

Posted: Wednesday 06 November 2024 13:11
by hemant5400z
Thanks,

It is all working again so issue is solved