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

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

Moderator: leecollings

Post Reply
hemant5400z
Posts: 80
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

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

Post 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
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

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

Post by Kedi »

I think that in an other thread it was mentioned that the '.v' should be '.v1' now.
Try that.
Logic will get you from A to B. Imagination will take you everywhere.
hemant5400z
Posts: 80
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

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

Post 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
hemant5400z
Posts: 80
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

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

Post by hemant5400z »

Hi,

however my docker version is from deceber 2023 (beta), so there was no update on the docker container.
Hemant
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

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

Post by HvdW »

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

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

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hemant5400z
Posts: 80
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

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

Post by hemant5400z »

Thanks,

It is all working again so issue is solved
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest