Why is dzvents device lookup using name instead of idx

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

Moderator: leecollings

Post Reply
User avatar
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Why is dzvents device lookup using name instead of idx

Post 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
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

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

Post 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?
Last edited by HvdW on Friday 14 February 2025 18:44, edited 2 times in total.
Bugs bug me.
User avatar
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

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

Post 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
Bugs bug me.
User avatar
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
User avatar
waltervl
Posts: 5844
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
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
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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!!
Kedi
Posts: 575
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

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

Post 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
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
waltervl
Posts: 5844
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

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

Post 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... :)
Hans
User avatar
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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 :)
User avatar
gizmocuz
Posts: 2537
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

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

Post 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)
Quality outlives Quantity!
User avatar
gizmocuz
Posts: 2537
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

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

Post 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
Quality outlives Quantity!
User avatar
waltervl
Posts: 5844
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
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
Ragdag
Posts: 152
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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.
lost
Posts: 660
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
:)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest