Attempt to concatenate a table value  [SOLVED]

Moderator: leecollings

Post Reply
AYAMY
Posts: 21
Joined: Sunday 27 May 2018 11:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Attempt to concatenate a table value

Post by AYAMY »

Hi,
I have several Tplink hs110 ( meters ) in my house.
Each meter tracks this kind of data

Code: Select all

{
	"ActTime" : 1619516296,
	"AstrTwilightEnd" : "21:46",
	"AstrTwilightStart" : "04:16",
	"CivTwilightEnd" : "20:29",
	"CivTwilightStart" : "05:33",
	"DayLength" : "13:55",
	"NautTwilightEnd" : "21:06",
	"NautTwilightStart" : "04:56",
	"ServerTime" : "2021-04-27 11:38:16",
	"SunAtSouth" : "13:01",
	"Sunrise" : "06:03",
	"Sunset" : "19:58",
	"app_version" : "2021.1",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CounterToday" : "0.002 kWh",
			"CustomImage" : 0,
			"Data" : "8.884 kWh",
			"Description" : "",
			"EnergyMeterMode" : "",
			"Favorite" : 1,
			"HardwareDisabled" : false,
			"HardwareID" : 15,
			"HardwareName" : "Lavastoviglie",
			"HardwareType" : "TP-Link Wi-Fi Smart Plug HS100/HS110",
			"HardwareTypeVal" : 94,
			"HaveTimeout" : false,
			"ID" : "000F0004",
			"LastUpdate" : "2021-04-27 11:37:41",
			"Name" : "Lavastoviglie -  kWh",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "kWh",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "General",
			"TypeImg" : "current",
			"Unit" : 4,
			"Usage" : "0.3 Watt",
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "133"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}
I want to sum the value of Power of each meters and update a dummy device (custom type) with this code

Code: Select all

return {

	on = {
	    timer = { 'every 1 minutes' }
	},
	
	execute = function(domoticz, item)
	    
	    local APower = domoticz.devices(129)       -- Acquario Ciano luce frontale  -  kWh -- IDX 129
	    local BPower = domoticz.devices(133)       -- Lavastoviglie -  kWh -- IDX 133
	    local CPower = domoticz.devices(137)       -- Forno -  kWh -- IDX 137
	    local DPower = domoticz.devices(141)       -- Acquario Fluval Amtra Orion -  kWh -- IDX 141	    
	    local EPower = domoticz.devices(146)       -- Acquario Fluval Fitostimolante - kWh -- IDX 146
	    local FPower = domoticz.devices(150)       -- Acquario Ciano Luce Bianca -  kWh -- IDX 150
	    local GPower = domoticz.devices(154)       -- Servizio - kWh -- IDX 154 usato per l'acquario Caridine
	    local HPower = domoticz.devices(158)       -- Acquario Ciano Flusso - kWh IDX 158
	    local IPower = domoticz.devices(890)       -- Daiking Living Heat kWh -- IDX 890 
	    local LPower = domoticz.devices(891)       -- Daiking Living Cool kWh -- IDX 891 
	    local MPower = domoticz.devices(892)       -- Daiking Bedroom Heat kWh -- IDX 892 
	    local NPower = domoticz.devices(892)       -- Daiking Bedroom Cool kWh -- IDX 893 
	    local totalUsage = domoticz.devices(909)  -- total of All IDX DEVICES  power meter
	    
	    print ('######################################################')
	    print ('Device value:' .. APower.WhActual + BPower.WhActual + CPower.WhActual + DPower.WhActual + EPower.WhActual + FPower.WhActual + GPower.WhActual + HPower.WhActual + IPower.WhActual + LPower.WhActual + MPower.WhActual + NPower.WhActual)
	    totalUsage.updateCustomSensor(	APower.WhActual + BPower.WhActual + CPower.WhActual + DPower.WhActual + EPower.WhActual + FPower.WhActual + GPower.WhActual + HPower.WhActual + IPower.WhActual + LPower.WhActual + MPower.WhActual + NPower.WhActual)
	    print ('######################################################')
        print ('Device value:' .. totalUsage)
        print ('######################################################')
	end
	
}

but in the log i see

Code: Select all

2021-04-27 11:47:00.288 Error: dzVents: Error: (3.1.7) An error occurred when calling event handler CalcoloUsagePerCustom
2021-04-27 11:47:00.288 Error: dzVents: Error: (3.1.7) ...ipts/dzVents/generated_scripts/CalcoloUsagePerCustom.lua:27: attempt to concatenate a table value (local 'totalUsage')
attempt to concatenate a table value (local 'totalUsage') what's the problem ? :?:
AYAMY
Posts: 21
Joined: Sunday 27 May 2018 11:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Attempt to concatenate a table value  [SOLVED]

Post by AYAMY »

sorry....
solved...

Code: Select all

 print ('Device value:' .. totalUsage)
remove this
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Attempt to concatenate a table value

Post by waaren »

AYAMY wrote: Tuesday 27 April 2021 12:02

Code: Select all

 print ('Device value:' .. totalUsage)
remove this
There is one device used twice in your example. (local NPower = domoticz.devices(892) -- Daiking Bedroom Cool kWh -- IDX 893)

You could also try

Code: Select all

return {

    on = {
        timer = { 'every 1 minutes' }
    },

    execute = function(domoticz, item)

        local myDevices =
        {
            129, 133, 137, 141, 146, 150, 154, 158, 890, 891, 892, 893
        }

        local totalUsage = domoticz.devices(909)  -- total of All IDX DEVICES  power meter

        local sumWhActual = 0
        for _,idx in ipairs(myDevices) do
            sumWhActual = sumWhActual + domoticz.devices(idx).WhActual
        end

        totalUsage.updateCustomSensor( sumWhActual)
        print ('######################################################')
        print ('New device value for ' .. totalUsage.name .. ': ' .. sumWhActual)
        print ('######################################################')
    end

}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
AYAMY
Posts: 21
Joined: Sunday 27 May 2018 11:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Attempt to concatenate a table value

Post by AYAMY »

thanks it works !!! ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest