Page 1 of 1

EventHelpers.lua:454: attempt to concatenate a nil value (field 'hardwareName')

Posted: Tuesday 29 July 2025 10:17
by domja
Hi everyone,

Recently started using Domoticz (2025.1 on Docker) and I have been working on a plugin.
So far so good, but I ran into a situation and I am wondering what the problem is.
Tried to search the forum/internet, but to no avail.

I created a small proof of concept to highlight the problem:

Take the BaseTemplate.py from examples and add a device in onStart

Code: Select all

def onStart(self):
        Domoticz.Log("onStart called")
        if Parameters["Mode6"] != "0":
            Domoticz.Debugging(int(Parameters["Mode6"]))
            DumpConfigToLog()

        if (not "Dev1" in Devices):
            Domoticz.Unit(Name="Dev1", DeviceID="Dev1", Unit=1, Used=1, TypeName="Set Point", Options={'ValueStep':'1','ValueMin':'1','ValueMax':'100000','ValueUnit':'km'}).Create()
            Devices["Dev1"].Units[1].sValue = "4"
            Devices["Dev1"].Units[1].Update(Log=True)
The above runs with no problem. When I add the hardware, the device shows up and generates no error in the log.
Also no problem when setting a new value using the device via the user interface.

Next step.
Create an internal dzVents (device) script and only change the device name accordingly.

Code: Select all

return {
	on = {
		devices = {
			'Dev1'
		}
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'template',
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	end
}
Remove the device via the user interface and update hardware.

Now I get the following error.

Code: Select all

2025-07-29 08:55:59.326 Status: Test: Initialized version 1.0.0, author 'gizmocuz'
2025-07-29 08:55:59.327 Test: onStart called
2025-07-29 08:55:59.383 dzVents: Handling events for: "Dev1", value: "nil"
2025-07-29 08:55:59.383 Error: EventSystem: in /opt/domoticz/dzVents/runtime/dzVents.lua: /opt/domoticz/dzVents/runtime/EventHelpers.lua:454: attempt to concatenate a nil value (field 'hardwareName')
Another example, this time with a switch and some code to catch the onCommand when the switch button is pushed.

Code: Select all

def onStart(self):
        Domoticz.Log("onStart called")
        if Parameters["Mode6"] != "0":
            Domoticz.Debugging(int(Parameters["Mode6"]))
            DumpConfigToLog()

        if not "Dev2" in Devices:
            Domoticz.Unit(Name="Dev2", DeviceID="Dev2", Unit=1, TypeName="On/Off", Used=1).Create()
            
	def onCommand(self, DeviceID, Unit, Command, Level, Color):
        if DeviceID == "Dev2" and Command == "On":
            Devices["Dev2"].Units[Unit].nValue = 1
            Devices["Dev2"].Units[Unit].Update(Log=True)

        Domoticz.Log("onCommand called for Device " + str(DeviceID) + " Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
No problem running this when hardware is updated and the button is pushed.

Again create an internal dzVents (device) script and change the device name accordingly.

Code: Select all

return {
	on = {
		devices = {
			'Dev2'
		}
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'template',
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	end
}
Remove the device via the user interface and update hardware.

And voila, the same error.

Code: Select all

2025-07-29 08:51:09.053 Test: onCommand called for Device Dev2 Unit 1: Parameter 'On', Level: 0
2025-07-29 08:51:09.104 Test: onHeartbeat called
2025-07-29 08:51:09.193 dzVents: Handling events for: "Dev2", value: "nil"
2025-07-29 08:51:09.193 Error: EventSystem: in /opt/domoticz/dzVents/runtime/dzVents.lua: /opt/domoticz/dzVents/runtime/EventHelpers.lua:454: attempt to concatenate a nil value (field 'hardwareName') 
Current situation in Eventhelpers.lua (line 454)

Code: Select all

if (baseType == domoticz.BASETYPE_DEVICE) then
                moduleLabelInfo = ' Device: "' .. subject.name .. ' (' .. subject.hardwareName .. ')", Index: ' .. tostring(subject.id)
Which is easily enough patched to surpress the error. But are there any other consequences?

Code: Select all

if (baseType == domoticz.BASETYPE_DEVICE) then
                moduleLabelInfo = ' Device: "' .. subject.name .. ' (' .. tostring(subject.hardwareName) .. ')", Index: ' .. tostring(subject.id)
So finally my question: what is causing this error?
Am I doing something wrong, is it a bug in Domoticz?

Thanks for your help.

Re: EventHelpers.lua:454: attempt to concatenate a nil value (field 'hardwareName')

Posted: Tuesday 29 July 2025 10:51
by waltervl
I do not experience these errors in normal life working in Domoticz. What if you wait some time to get dzvents load the event system lua tables correctly?

Re: EventHelpers.lua:454: attempt to concatenate a nil value (field 'hardwareName')

Posted: Tuesday 29 July 2025 13:33
by domja
In the first example (Dev1), the values are set immediately after creation, so no waiting is possible there I think.

In de second example (Dev2), i have waited up to 5 minutes before pushing the button. but still the same error.

What I did notice however, after extending the onCommand code a bit more to able to toggle the switch:

Code: Select all

def onCommand(self, DeviceID, Unit, Command, Level, Color):
        if DeviceID == "Dev2":
            if Command == "On":
                __st = 1
            else:
                __st = 0
            Devices["Dev2"].Units[Unit].nValue = __st
            Devices["Dev2"].Units[Unit].Update(Log=True)

        Domoticz.Log("onCommand called for Device " + str(DeviceID) + " Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
Is that the FIRST toggle ON generates the error message, but toggle OFF and any FURTHER toggles produce no more errors.
This means that at least events can be processed; only not the first toggle.

Code: Select all

 2025-07-29 13:24:52.709 Test: onCommand called for Device Dev2 Unit 1: Parameter 'Off', Level: 0
2025-07-29 13:24:52.758 dzVents: Handling events for: "Dev2", value: "Off"
2025-07-29 13:24:52.758 dzVents: template: ------ Start internal script: Script #1: Device: "Dev2 (Test)", Index: 46
2025-07-29 13:24:52.758 dzVents: template: Device Dev2 was changed
2025-07-29 13:24:52.758 dzVents: template: ------ Finished Script #1

Code: Select all

 2025-07-29 13:27:40.276 Test: onCommand called for Device Dev2 Unit 1: Parameter 'On', Level: 0
2025-07-29 13:27:40.325 dzVents: Handling events for: "Dev2", value: "On"
2025-07-29 13:27:40.325 dzVents: template: ------ Start internal script: Script #1: Device: "Dev2 (Test)", Index: 46
2025-07-29 13:27:40.326 dzVents: template: Device Dev2 was changed
2025-07-29 13:27:40.326 dzVents: template: ------ Finished Script #1
So it seems that the error is given only after creation of the device.

Re: EventHelpers.lua:454: attempt to concatenate a nil value (field 'hardwareName')

Posted: Tuesday 29 July 2025 14:03
by domja
Oke, I did some more testing. This time after deleting the switch and updating the hardware and NOT pushing the button, I restarted the docker image.
And low and behold, after the first toggle ON, no more errors and the event is processed.

This however does not apply to the Dev1 example. Upon creation (restart or not), an error is given and no events will be processed.
For my particular use case however that is no problem; the device is initialised correctly. There is however a limitation.

My conclusion for now: there is a problem with processing events upon creation of (at least some) devices.
Whether or not the problem originates from my code or domoticz is not clear to me.