dzVents says device does not exist Topic is solved

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
Kedi
Posts: 625
Joined: Monday 20 March 2023 14:41
Target OS: Linux
Domoticz version: latest
Location: Somewhere in NL
Contact:

dzVents says device does not exist

Post by Kedi »

I have a some 30 devices that start with the name 'Zolder' and 1 group called 'Zolder'
All devices work fine and some are controlled by dzVents.
I have 1 device (switch) called 'Zolder Airco' which dzVents does not know about.
sName = dz.devices('Zolder Airco') give nil for sName
Half of the devices have a space in the name after 'Zolder' the other half not.
If I change the name to 'Zolder_Airco' (notice the underscore) then the dzVents scripts works fine.
There are no duplicate names that start with 'Zolder'
I deleted the device and let Domoticz create it again, but the problem is still present.

Has anyone a solution or knows what the problem is?
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
habahabahaba
Posts: 290
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: dzVents says device does not exist

Post by habahabahaba »

The solution is to use idx of device
Kedi
Posts: 625
Joined: Monday 20 March 2023 14:41
Target OS: Linux
Domoticz version: latest
Location: Somewhere in NL
Contact:

Re: dzVents says device does not exist

Post by Kedi »

That's not a solution, but a workaround.
I don't use idx in my scripts, it is meaningless.
From a name you can follow the flow of a script.
I have scripts that use more then 3 devices, and then it hard to follow the flow when idxes are used.
Some of those script sizes are greater then 10 Kb (including comments and comments may be 60%)
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
habahabahaba
Posts: 290
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: dzVents says device does not exist

Post by habahabahaba »

Meaningless??!! This is the only correct solution IMHO to avoid getting confused by device names if you have quite a lot of them.
What if you suddenly decide to rename a device? Will you look for all the scripts in which it is involved?

And if you know the device’s ID, there’s no problem with logging its name.
User avatar
imautohuttraeger
Posts: 486
Joined: Saturday 14 March 2020 13:40
Target OS: Raspberry Pi / ODroid
Domoticz version: lat.beta
Location: Germany
Contact:

Re: dzVents says device does not exist

Post by imautohuttraeger »

I also use IDX in scripts in order to avoid problems when a device is renamed. For better "readability", I simply put the name of the device in a comment in the same line.
Stop, look and listen.
User avatar
waltervl
Posts: 7047
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: dzVents says device does not exist

Post by waltervl »

Using IDX is NOT the solution.

Dzvents is developed on top of the Domoticz Lua integration and the Lua integration can only select devices based on name.
So if you use IDX in a dzvents script dzvents asks Lua which device could be the given IDX. It will return the first device name.

But why it cannot find device 'Zolder Airco' while it could find something like 'Zolder Light' is indeed a little bit strange.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
imautohuttraeger
Posts: 486
Joined: Saturday 14 March 2020 13:40
Target OS: Raspberry Pi / ODroid
Domoticz version: lat.beta
Location: Germany
Contact:

Re: dzVents says device does not exist

Post by imautohuttraeger »

waltervl wrote: Wednesday 25 November 2026 18:58 So if you use IDX in a dzvents script dzvents asks Lua which device could be the given IDX. It will return the first device name.
It seems that I am too dull-witted and missing something. Why do I have to care that in the background it searches for the match of the idx to it's name? It works (never had problems) and I can rename a device whenever I want ...
Last edited by imautohuttraeger on Wednesday 25 November 2026 22:31, edited 1 time in total.
Stop, look and listen.
User avatar
habahabahaba
Posts: 290
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: dzVents says device does not exist

Post by habahabahaba »

Try this code
Spoiler: show

Code: Select all

-- hexdump.lua 
local function hex(s)
	return (s:gsub('.', function(c) return string.format('%02X ', c:byte()) end))
end

local function byteAt(s, i)
	local b = s:byte(i)
	return b and string.format('0x%02X', b) or '(нет)'
end

local function firstDiff(a, b)
	for i = 1, math.max(#a, #b) do
		if a:byte(i) ~= b:byte(i) then return i end
	end
	return nil
end

return {
	on = { timer = { 'every minute' } },
	execute = function(dz, _)
		-- IMPORTANT: COPY problem device name byte to byte from script
		local target = 'Zolder Airco'
		dz.log(('LITERAL: [%s] len=%d hex=%s'):format(target, #target, hex(target)), dz.LOG_FORCE)

		local found = false
		dz.devices().forEach(function(dev)
			if dev.name:find('Zolder', 1, true) or dev.name:find('Airco', 1, true) then
				local eq = (dev.name == target)
				if eq then found = true end
				dz.log(('idx=%d [%s] len=%d hex=%s%s'):format(
					dev.id, dev.name, #dev.name, hex(dev.name),
					eq and '  <== direct entry' or ''), dz.LOG_FORCE)

				if not eq and dev.name:find('Airco', 1, true) then
					local d = firstDiff(dev.name, target)
					if d then
						dz.log(('  the first discrepancy in the byte %d: device=%s, literal=%s'):format(
							d, byteAt(dev.name, d), byteAt(target, d)), dz.LOG_FORCE)
					end
				end
			end
		end)

		if not found then
			dz.log('No direct entry in dzVents (Used / hardware).', dz.LOG_FORCE)
		end
	end
}
May be there are hidden simbols in the name
User avatar
waltervl
Posts: 7047
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: dzVents says device does not exist

Post by waltervl »

imautohuttraeger wrote: Wednesday 25 November 2026 21:02
waltervl wrote: Wednesday 25 November 2026 18:58 So if you use IDX in a dzvents script dzvents asks Lua which device could be the given IDX. It will return the first device name.
It seems that I am too dull-witted and missing something. Why do I have to care that in the background it searches for the match of the idx to it's name? It works (never had problems) and I can rename a device whenever I want ...
As long as you have unique names there is no issue. But when you have the same names for devices you can have issues with using either IDX or names in dzvents. It could go right but it also can go wrong and select the incorrect device (in both cases).
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
habahabahaba
Posts: 290
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: dzVents says device does not exist

Post by habahabahaba »

waltervl wrote: Wednesday 25 November 2026 18:58 Using IDX is NOT the solution.

Dzvents is developed on top of the Domoticz Lua integration and the Lua integration can only select devices based on name.
So if you use IDX in a dzvents script dzvents asks Lua which device could be the given IDX. It will return the first device name.

But why it cannot find device 'Zolder Airco' while it could find something like 'Zolder Light' is indeed a little bit strange.
Waltervl, i think you are wrong.

In dzVents/runtime/Domoticz.lua - link there is the function

Code: Select all

function self._getItemFromData(baseType, id)

		local res

		for index, item in pairs(_G.domoticzData) do
			if (item.baseType == baseType) then
				if (item.id == id or item.name == id) then
					if (res == nil) then
						res = item
					else
						utils.log('Multiple items found for ' .. tostring(id) .. ' (' .. tostring(baseType) .. '). Please make sure your names are unique or use ids instead.', utils.LOG_ERROR)
					end
				end
			end
		end

		return res
	end
And the first condition "if (item.id == id or item.name == id) then" is a search by ID.
User avatar
waltervl
Posts: 7047
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: dzVents says device does not exist

Post by waltervl »

Yes, it is somewhat more complicated, see issue: https://github.com/domoticz/domoticz/issues/7143
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
imautohuttraeger
Posts: 486
Joined: Saturday 14 March 2020 13:40
Target OS: Raspberry Pi / ODroid
Domoticz version: lat.beta
Location: Germany
Contact:

Re: dzVents says device does not exist

Post by imautohuttraeger »

waltervl wrote: Wednesday 25 November 2026 23:37
imautohuttraeger wrote: Wednesday 25 November 2026 21:02
waltervl wrote: Wednesday 25 November 2026 18:58 So if you use IDX in a dzvents script dzvents asks Lua which device could be the given IDX. It will return the first device name.
It seems that I am too dull-witted and missing something. Why do I have to care that in the background it searches for the match of the idx to it's name? It works (never had problems) and I can rename a device whenever I want ...
As long as you have unique names there is no issue. But when you have the same names for devices you can have issues with using either IDX or names in dzvents. It could go right but it also can go wrong and select the incorrect device (in both cases).
Ah - thank you for the explanation. Now I've got you. This is indeed a problem. But if you use a device name and two devices have identical names, it can also go wrong, if the first match is not the intended one, right?
Stop, look and listen.
User avatar
waltervl
Posts: 7047
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: dzVents says device does not exist

Post by waltervl »

imautohuttraeger wrote: Thursday 26 November 2026 12:21
waltervl wrote: Wednesday 25 November 2026 23:37 As long as you have unique names there is no issue. But when you have the same names for devices you can have issues with using either IDX or names in dzvents. It could go right but it also can go wrong and select the incorrect device (in both cases).
Ah - thank you for the explanation. Now I've got you. This is indeed a problem. But if you use a device name and two devices have identical names, it can also go wrong, if the first match is not the intended one, right?
Yes, that was what I am trying to tell ;-)
For identical names in Domoticz beta, dzvents will warn about it in the log file when you try to find a device that has a twin device (see the github issue I mentioned before)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Kedi
Posts: 625
Joined: Monday 20 March 2023 14:41
Target OS: Linux
Domoticz version: latest
Location: Somewhere in NL
Contact:

Re: dzVents says device does not exist

Post by Kedi »

habahabahaba wrote: Wednesday 25 November 2026 21:13 Try this code
Spoiler: show

Code: Select all

-- hexdump.lua 
local function hex(s)
	return (s:gsub('.', function(c) return string.format('%02X ', c:byte()) end))
end

local function byteAt(s, i)
	local b = s:byte(i)
	return b and string.format('0x%02X', b) or '(нет)'
end

local function firstDiff(a, b)
	for i = 1, math.max(#a, #b) do
		if a:byte(i) ~= b:byte(i) then return i end
	end
	return nil
end

return {
	on = { timer = { 'every minute' } },
	execute = function(dz, _)
		-- IMPORTANT: COPY problem device name byte to byte from script
		local target = 'Zolder Airco'
		dz.log(('LITERAL: [%s] len=%d hex=%s'):format(target, #target, hex(target)), dz.LOG_FORCE)

		local found = false
		dz.devices().forEach(function(dev)
			if dev.name:find('Zolder', 1, true) or dev.name:find('Airco', 1, true) then
				local eq = (dev.name == target)
				if eq then found = true end
				dz.log(('idx=%d [%s] len=%d hex=%s%s'):format(
					dev.id, dev.name, #dev.name, hex(dev.name),
					eq and '  <== direct entry' or ''), dz.LOG_FORCE)

				if not eq and dev.name:find('Airco', 1, true) then
					local d = firstDiff(dev.name, target)
					if d then
						dz.log(('  the first discrepancy in the byte %d: device=%s, literal=%s'):format(
							d, byteAt(dev.name, d), byteAt(target, d)), dz.LOG_FORCE)
					end
				end
			end
		end)

		if not found then
			dz.log('No direct entry in dzVents (Used / hardware).', dz.LOG_FORCE)
		end
	end
}
May be there are hidden simbols in the name
Found it, and its quite stupid. :oops: :oops: :oops:
In Zigbee I never user names with spaces. So in Domotics it gets no space when the device is created
So I change the name in Domoticz after the device was created. (it looks / reads better.)
Now I have tested, and I am sure that is the way it went wrong.
By typing I accedently typed a <shift> space, and that looks like a normal space, so you cannot see it.
Again sorry for the fuss.... :oops: :oops: :oops:
Lesson learned.
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply