Page 1 of 1

Why is dzvents device lookup using name instead of idx

Posted: Friday 14 February 2025 17:31
by Ragdag
If I do a script like this, it fails

Code: Select all

local TEST_SWITCH = 565
local myTestIDX = 3081

return {
	on = {
		devices = {
			TEST_SWITCH
		}
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'TEST SCRIPT',
	},
	execute = function(domoticz, item)
	    domoticz.devices(myTestIDX).switchOff()
	end
}
with

Code: Select all

2025-02-14 17:22:24.045 Error: ZwaveJS2MQTT: sending switch commands for switch type 'sensor' is not supported (yet...) (zwavejs2mqtt_0xc15d8aa6_73-50-0-value-66049/Slaapkamer Luuk - Nachtlampje)
the reason for this is that dzvents is using name as the lookup and not the idx

Image

I can work around that by renaming device, but for some devices I like them having the same name without the need to overextend teh name to something like Slaapkamer Luuk - Nachtlampje - kWh and Slaapkamer Luuk - Nachtlampje - Switch

Why does Domoticz/dzVents prioritize name-based lookup instead of the more reliable IDX? Wouldn't IDX be a better unique identifier for device action

Re: Why is dzvents device lookup using name instead of idx

Posted: Friday 14 February 2025 18:38
by HvdW
Be carefull when using identical names.
Anyway 'Slaapkamer Luuk - Nachtlampje'for two devices, one usage and the other switch is deadly, that's for shure.

Name it Luuk central, Luuk lampje, Luuk whatever, keep the name short.
I had some trouble updating a textSensor which had the same name as somthing else, maybe even the name of the script.
It updated 9 lines. After renaming it it updated all 12 lines.

So domoticz.devices(3080).switchOff() does not react?
and domoticz.devices('Slaapkamer Luuk - Nachtlampje').switchOff() does not react either?

Re: Why is dzvents device lookup using name instead of idx

Posted: Friday 14 February 2025 18:42
by Ragdag
That is not the actual switch but one of the other switches that the wallplug creates, the actual switching device is 3081
The reason seems to be that idx 3080 has the same name and is picked up in dzvents and passed to the command which triggers the sensor error

Re: Why is dzvents device lookup using name instead of idx

Posted: Friday 14 February 2025 18:46
by HvdW
Same name for 2 different entities will alway render problems, in any programming language.
You could use Slaapkamer Luuk - Nachtlampje en Slaapkamer Luuk _ Nachtlampje

Re: Why is dzvents device lookup using name instead of idx

Posted: Friday 14 February 2025 19:00
by Ragdag
I know, but generally speaking any application that has ID and Name labels uses the ID as primary look ups not the names

Re: Why is dzvents device lookup using name instead of idx

Posted: Friday 14 February 2025 19:21
by waltervl
I believe it is due to the original Lua integration (dzvents is an addon on the Lua integration). Lua is looking at names, not IDX.

Re: Why is dzvents device lookup using name instead of idx

Posted: Sunday 16 February 2025 12:52
by Ragdag
Okay, I understand.

In the end created a script that processed the nodes.json output from Zwave JS and did a rename based on the naming scheme there (%loc - %n - %l) so that all are unique.

if anybody is interested, here is the script I build
https://github.com/Rouzax/Rename-Domoti ... -ZwaveJSON

Use at own risk and MAKE A BACKUP BEFORE!!

Re: Why is dzvents device lookup using name instead of idx

Posted: Tuesday 18 February 2025 15:02
by Kedi
Ragdag wrote: Friday 14 February 2025 19:00 I know, but generally speaking any application that has ID and Name labels uses the ID as primary look ups not the names
I do not agree. Numbers are for computers and Names are for humans. The numbers are unique, so should the names be.
If you use Google (dzga) You can call your lights, switches or whatever by Name and it works.
Try memorizing all those numbers for Google to switch lights etc. on/off

Re: Why is dzvents device lookup using name instead of idx

Posted: Tuesday 18 February 2025 16:16
by waltervl
If you look at other applications with objects in a database (I am an application manager with some database applications in management) they do work with Unique ID's (UID), the name is then irrelevant. Problem in Domoticz database is also that it is not a Unique ID. There are multiple objects with IDX:1 (a hardware gateway, a device, a camera, a scene/group, a timer a floorplan etc). But hey, this is what we have to live with here in Domoticz.

It would be an improvement for now if Domoticz would not allow double names for objects in the database to prevent issues.

Re: Why is dzvents device lookup using name instead of idx

Posted: Tuesday 18 February 2025 16:31
by manjh
waltervl wrote: Tuesday 18 February 2025 16:16 But hey, this is what we have to live with here in Domoticz.
I fully agree. Once you get to work with Domoticz in a bit lower and technical detail, you will find peculiarities.
It shows that Domoticz was developed in an organic way, as a hobby project; not as a professionally designed software development project.
But to be honest: that is also the charm of Domoticz!
A while back I had a look at HA, and decided to stick with Domoticz... :)

Re: Why is dzvents device lookup using name instead of idx

Posted: Tuesday 18 February 2025 16:43
by Ragdag
manjh wrote: Tuesday 18 February 2025 16:31
waltervl wrote: Tuesday 18 February 2025 16:16 But hey, this is what we have to live with here in Domoticz.
I fully agree. Once you get to work with Domoticz in a bit lower and technical detail, you will find peculiarities.
It shows that Domoticz was developed in an organic way, as a hobby project; not as a professionally designed software development project.
But to be honest: that is also the charm of Domoticz!
A while back I had a look at HA, and decided to stick with Domoticz... :)
Agree with this, have looked at HA a few times, but I have so much scripting and customization in Domoticz that it will be hard to replace :)

Re: Why is dzvents device lookup using name instead of idx

Posted: Tuesday 18 February 2025 17:45
by gizmocuz
waltervl wrote: Tuesday 18 February 2025 16:16 If you look at other applications with objects in a database (I am an application manager with some database applications in management) they do work with Unique ID's (UID), the name is then irrelevant. Problem in Domoticz database is also that it is not a Unique ID. There are multiple objects with IDX:1 (a hardware gateway, a device, a camera, a scene/group, a timer a floorplan etc). But hey, this is what we have to live with here in Domoticz.

It would be an improvement for now if Domoticz would not allow double names for objects in the database to prevent issues.
That's not correct. Each table have a unique ID.

A device table is something different then a scene table

This is normal database development (SQL)

Re: Why is dzvents device lookup using name instead of idx

Posted: Tuesday 18 February 2025 17:47
by gizmocuz
manjh wrote: Tuesday 18 February 2025 16:31
waltervl wrote: Tuesday 18 February 2025 16:16 But hey, this is what we have to live with here in Domoticz.
I fully agree. Once you get to work with Domoticz in a bit lower and technical detail, you will find peculiarities.
It shows that Domoticz was developed in an organic way, as a hobby project; not as a professionally designed software development project.
But to be honest: that is also the charm of Domoticz!
A while back I had a look at HA, and decided to stick with Domoticz... :)
Gee thanks! :mrgreen:

So, as you have probably looked at the code, what's not professional about this? Do you think that an application that can work with 50+ different type of hardware, can control various devices with schedules/scripts and API is not professional?
This is not an application that does one trick (like pushing one type of hardware to MQTT)

And you are more than welcome to help with development as this is an open source project

Re: Why is dzvents device lookup using name instead of idx

Posted: Tuesday 18 February 2025 18:27
by waltervl
gizmocuz wrote: Tuesday 18 February 2025 17:45
waltervl wrote: Tuesday 18 February 2025 16:16 If you look at other applications with objects in a database (I am an application manager with some database applications in management) they do work with Unique ID's (UID), the name is then irrelevant. Problem in Domoticz database is also that it is not a Unique ID. There are multiple objects with IDX:1 (a hardware gateway, a device, a camera, a scene/group, a timer a floorplan etc). But hey, this is what we have to live with here in Domoticz.

It would be an improvement for now if Domoticz would not allow double names for objects in the database to prevent issues.
That's not correct. Each table have a unique ID.

A device table is something different then a scene table

This is normal database development (SQL)
In the 2 big applications I use professionally each object has an unique ID even if they are separated by tables or object sort. So when I query for an ID over the complete database (with millions of objects) I only get one result. So your conclusion that the way Domoticz is setup is normal database development is not true, but my conclusion one can do it differently is also true.

Re: Why is dzvents device lookup using name instead of idx

Posted: Wednesday 19 February 2025 8:57
by Ragdag
@gizmocuz It was not my intention to disrespect your work. I truly love Domoticz and hope that it has a long life ahead of it, and value all the hard work that people put into it.

Unfortunately, I'm no developer, otherwise I would have contributed.

Re: Why is dzvents device lookup using name instead of idx

Posted: Monday 24 February 2025 14:53
by lost
manjh wrote: Tuesday 18 February 2025 16:31 Domoticz was developed in an organic way...
Organic: This reminds me another "little hobby project"...

https://wptavern.com/linus-torvalds-sha ... ation-hype
“If you want to do something new, something that is really pushing the envelope, nobody can really say ‘This is the way to do it,’” Torvalds said. “What you need to do is a lot of trial and error. I often compare software development to biological processes where really it is evolution. It is not intelligent design.
:)