Error: generic_device.lua:67: attempt to index a nil value  [Solved]

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

Moderator: leecollings

fvdp80
Posts: 69
Joined: Tuesday 14 August 2018 8:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10303
Contact:

Error: generic_device.lua:67: attempt to index a nil value

Post by fvdp80 »

Keep getting these error messages:

Code: Select all

2021-09-13 12:56:31.895 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
Does anybody know what the problem could be?
User avatar
waltervl
Posts: 5149
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by waltervl »

Looks to be linked to this piece of code (line 67 is the utils.log line). My Lua knowledge is too low yo see what is going on here that could trigger your error.
Edit: Do you have a camera or hardware (menu setup - hardware) with special characters in its name?

Code: Select all

		if (data.lastUpdate == '' or data.lastUpdate == nil) then
			if data.baseType ~= 'camera' and data.baseType ~= 'hardware' then
				utils.log('Discarding device. No last update info found: ' .. utils._.str(data), utils.LOG_DEBUG)
			end
			return nil
		end
Last edited by waltervl on Tuesday 14 September 2021 13:43, edited 1 time in total.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by rrozema »

My feeling is that this is a bug that is very rarely triggered. _ is a special case in lua: it's some sort of a library that provides special iterator and such basic functionality, but it doesn't seem tot be available from the utils module API (anymore?). This piece of code will however seldomly be called, as it requires very specific conditions.

One of your devices apparently doesn't have valid lastUpdate value. For my system the following script returns no rows. What does it do for yours?

Code: Select all

return {
	on = {
	    timer = {
	        'every minute'
	       }
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'test',
	},
	execute = function(domoticz, device)
	    domoticz.devices().forEach(
	        function(device)
	            if device.lastUpdate == '' or device.lastUpdate == nil then
	                if device.baseType ~= 'camera' and device.baseType ~= 'hardware' then
        	            domoticz.log('"' .. device.name .. '", deviceType = ' .. device.deviceType .. ', baseType = ' .. device.baseType .. ' has no valid lastUpdate.', domoticz.LOG_ERROR)
        	        end
	            end
	        end
	    )
	end
}
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by Xenomes »

waltervl wrote: Monday 13 September 2021 15:30 Looks to be linked to this piece of code (line 67 is the utils.log line). My Lua knowledge is too low yo see what is going on here that could trigger your error.
Do you have a camera or hardware (menu setup - hardware) with special characters in its name?
I got the same error in my log, I have a space in a camera name no special characters but also spaces in hardware names.

Code: Select all

2021-09-13 20:38:50.992 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-13 20:39:04.600 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-13 20:39:09.925 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-13 22:07:26.655 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_') 
running version: 2021.1 (build 13497)
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by rrozema »

Waltervl misread the code. It is not a camera nor a "hardware" that triggers the problem. So it is some other device that triggers the message. Please copy and paste the code I posted above into a dzvents script and watch your log file. This should then identify the device(s) that cause the message.
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by jannl »

Could be a virtual switch. In that case, did you switch the virtual switch manually some times? In 'normal' lua I always get strange behaviour when a virtual switch has never been switched. (May be because the lastupdate date is empty)
fvdp80
Posts: 69
Joined: Tuesday 14 August 2018 8:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10303
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by fvdp80 »

Ran the code and, fter a while, it got me this in domoticz log:

Code: Select all

2021-09-15 20:23:33.804 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-15 20:23:39.102 (Evohome) fetch data from server
2021-09-15 20:24:00.232 Status: dzVents: Info: test: ------ Start internal script: Script #1:, trigger: "every minute"
2021-09-15 20:24:00.327 Status: dzVents: Info: test: ------ Finished Script #1
No output.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by EddyG »

In my quest to find the solution for my zigbee problems I see this messages also frequently.
It would be nice to have some info about the script that creates this error messages.
I hope that someone can implement that in dzVents.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by rrozema »

generic_device.lua is in the folder /home/pi/domoticz/dzVents/runtime/device-adapters

You can try replacing in generic_device.lua the following code:

Code: Select all

			if data.baseType ~= 'camera' and data.baseType ~= 'hardware' then
				utils.log('Discarding device. No last update info found: ' .. domoticz.utils._.str(data), level)
			end
by:

Code: Select all

			if data.baseType ~= 'camera' and data.baseType ~= 'hardware' then
				local name
				if nil == device then
					name = '<unknown>'
				else
					name = device.name
				end
				utils.log('Discarding device ' .. tostring(name) ..'. No last update info found: ' .. domoticz.utils._.toStr(data), level)	-- 1st alternative
--				utils.log('Discarding device ' .. tostring(name) ..'. No last update info found: ' .. tostring(data), level)	-- 2nd alternative
--				utils.log('Discarding device. No last update info found: ' .. domoticz.utils._.str(data), level)
			end
I am not able to test it because I don't get the error message, but this should give you both the name of the device giving the problem, plus some information on the data that causes it.
If it doesn't work with the _.toStr() function, you can try the 2nd alternative instead.
Last edited by rrozema on Thursday 16 September 2021 14:16, edited 1 time in total.
fvdp80
Posts: 69
Joined: Tuesday 14 August 2018 8:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10303
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by fvdp80 »

Tried your code in generic_device.lua and got this output:

Code: Select all

2021-09-16 14:12:51.868 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:73: attempt to call a table value (global 'string')
With the 2nd alternative i got this output:

Code: Select all

2021-09-16 14:06:52.319 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:74: attempt to call a table value (global 'string')
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by rrozema »

Excuse me (as I said: untested code) the

Code: Select all

.. string(name) ..
should be changed into

Code: Select all

.. tostring(name) ..
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by rrozema »

fvdp80 wrote: Wednesday 15 September 2021 20:27 Ran the code and, fter a while, it got me this in domoticz log:

Code: Select all

2021-09-15 20:23:33.804 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-15 20:23:39.102 (Evohome) fetch data from server
2021-09-15 20:24:00.232 Status: dzVents: Info: test: ------ Start internal script: Script #1:, trigger: "every minute"
2021-09-15 20:24:00.327 Status: dzVents: Info: test: ------ Finished Script #1
No output.
That's disappointing....
fvdp80
Posts: 69
Joined: Tuesday 14 August 2018 8:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10303
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by fvdp80 »

I hate to say it, but still got errors:

Code: Select all

2021-09-16 14:32:52.047 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:73: attempt to call a nil value (field 'toStr')
fvdp80
Posts: 69
Joined: Tuesday 14 August 2018 8:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10303
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by fvdp80 »

For the 2nd alternative i'm getting some output:

Code: Select all

2021-09-16 14:38:27.765 Status: dzVents: Info: Discarding device Blitzwolf 1 (Power). No last update info found: table: 0x72267b80
2021-09-16 14:38:27.875 Status: dzVents: Info: Discarding device Blitzwolf 1 (Voltage). No last update info found: table: 0x7221e1d0
2021-09-16 14:38:27.890 Status: dzVents: Info: Discarding device Blitzwolf 1 (Current). No last update info found: table: 0x7221e8d8
2021-09-16 14:38:52.089 Status: dzVents: Info: Discarding device Blitzwolf 2 (Voltage). No last update info found: table: 0x7225c4a0
2021-09-16 14:39:52.118 Status: dzVents: Info: Discarding device Blitzwolf 2 (Current). No last update info found: table: 0x7225c8a8
Blitzwolf Zigbee Plugs, it seems.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by rrozema »

fvdp80 wrote: Thursday 16 September 2021 14:34 I hate to say it, but still got errors:

Code: Select all

2021-09-16 14:32:52.047 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:73: attempt to call a nil value (field 'toStr')
Yeah, that one was a bit 'experimental'. (read: Me trying to guess the actual workings of the ._. construction) And it apparantly doesn't work the way I guessed it did. ;)

But from the 2nd alternative you now know which devices trigger that message, plus: now that this bug no longer stops you, your scripts should work more reliably. Even if these particular devices may not work perfectly yet. Maybe @dannybloe can fix the problem in the generic_device.lua correctly.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by EddyG »

Nice solution. :) I have put the second logging line (and the rest) in place.
Should not be a problem to log the content of the table too.
Wonder what is in the table. :?: Probably to complete device table.
Last edited by EddyG on Thursday 16 September 2021 17:01, edited 1 time in total.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by rrozema »

EddyG wrote: Thursday 16 September 2021 16:37 Nice solution. :) I have put the second logging line (and the rest) in place.
Should not be a problem to log the content of the table too.
Wonder what is in the table. :?:
That's what the toStr() function in Utils.lua does: it prints the table and it's contents in a tree-like way. I was hoping to fix the call into that function by the 1st alternative, but apparantly it wasn't just a simple rename of that function from str() into toStr() that broke this call. Hopefully @dannybloe or @waaren are reading here still, as they for sure know how to really fix this small bug.

Oh no!. I was missing waaren's responses for a long time already and looked for his last log on date, and only now I see that he passed away in July this year. That is a great loss! He was a great man.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by EddyG »

I think that in that table there is a nil value and the processing of the table in Utils does not take the nil value into account.
And probably it is the lastUpdate it self that is the nil value.
eddieb
Posts: 279
Joined: Wednesday 04 July 2018 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by eddieb »

hmm, I am seeing similar errors ... (even in 13499)

Code: Select all

2021-09-17 07:47:31.381 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-17 07:47:33.957 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-17 07:47:34.096 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-17 07:47:35.222 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-17 07:47:59.700 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-17 07:47:59.830 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_')
2021-09-17 07:47:59.951 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: ...oticz/dzVents/runtime/device-adapters/generic_device.lua:67: attempt to index a nil value (field '_') 
RPI4 Beta / Tasmota / ZigBee2MQTT / P1meter / Haier AC with Node-Red and MQTT / SolarEdge SE3500H modbus_tcp / Opentherm gateway / Plugwise Anna/Smile / ObserverIP weatherstation thru WuDirect
Feeding ADSB https://adsb.im/home
fvdp80
Posts: 69
Joined: Tuesday 14 August 2018 8:22
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10303
Contact:

Re: Error: generic_device.lua:67: attempt to index a nil value

Post by fvdp80 »

Thanks all, especially rrozema.
For now this will do, but i'm also curious what is causing the error.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest