Page 1 of 2

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

Posted: Monday 13 September 2021 12:59
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?

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

Posted: Monday 13 September 2021 15:30
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

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

Posted: Monday 13 September 2021 21:56
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
}

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

Posted: Monday 13 September 2021 22:35
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)

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

Posted: Tuesday 14 September 2021 11:13
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.

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

Posted: Tuesday 14 September 2021 12:34
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)

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

Posted: Wednesday 15 September 2021 20:27
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.

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

Posted: Wednesday 15 September 2021 22:38
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.

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

Posted: Thursday 16 September 2021 10:35
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.

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

Posted: Thursday 16 September 2021 14:13
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')

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

Posted: Thursday 16 September 2021 14:17
by rrozema
Excuse me (as I said: untested code) the

Code: Select all

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

Code: Select all

.. tostring(name) ..

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

Posted: Thursday 16 September 2021 14:22
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....

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

Posted: Thursday 16 September 2021 14:34
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')

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

Posted: Thursday 16 September 2021 14:42
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.

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

Posted: Thursday 16 September 2021 16:11
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.

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

Posted: Thursday 16 September 2021 16:37
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.

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

Posted: Thursday 16 September 2021 16:45
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.

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

Posted: Thursday 16 September 2021 17:07
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.

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

Posted: Friday 17 September 2021 8:00
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 '_') 

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

Posted: Friday 17 September 2021 13:02
by fvdp80
Thanks all, especially rrozema.
For now this will do, but i'm also curious what is causing the error.