Page 1 of 1

Find idx from name

Posted: Wednesday 18 May 2016 3:03
by juankar
Some times we have to use idx instead of DeviceName in scripts. (commandArray['UpdateDevice']..)
But when you change a device the idx change, then you msut to check every script.... and that's no good for mental health :(

So I wonder if is there any way to get the IDX using the name of devices, in lua at least

(Now I'm tring to set the mode for a thermostat and the only way is UpdateDevice)

Thanks

Re: Find idx from name

Posted: Wednesday 18 May 2016 7:33
by Egregius
My php script works always with devicename. What a nightmare if you need idx's in scripts.

Re: Find idx from name

Posted: Wednesday 18 May 2016 8:04
by NietGiftig
Egregius wrote:What a nightmare if you need idx's in scripts.
What a nightmare if you cannot change your names, without checking and/or changing all your scripts.

Re: Find idx from name

Posted: Wednesday 18 May 2016 8:58
by bobkersten
Nightmares or not; there currently is a lua object/array available named "otherdevices_idx" which can be used to map device names to device ids. I'm not sure when this was added though, so it might only be available in beta for now.

Use it like this: otherdevices_idx["Bathroom Light"]

Re: Find idx from name

Posted: Thursday 19 May 2016 11:45
by juankar
I must be blind !!! :ugeek:
I read the wiki pages and I ddidn't see anything about this table passed to lua, but now (after reading this post) I've seen all info is in wiki Events page :oops:

Well but I've learned two things:
1. I must read all and every Word in wiki,
2. I've added a sqlite3 to lua and now I know how to acces domoticz database

We can learn from mistakes ! :D

Thanks

Re: Find idx from name

Posted: Thursday 19 May 2016 12:03
by simonrg
juankar wrote:Well but I've learned two things:
1. I must read all and every Word in wiki,
2. I've added a sqlite3 to lua and now I know how to acces domoticz database

We can learn from mistakes !
That's what's great about this forum, none of us are as smart as all of us.

Now you are smarter, it would great if could you add some guidance on using sqlite3 and accessing the database in Lua to the Wiki.

It's made me think that SQL is well documented and if the database structure is well documented, then this might be a way of getting very flexible access to the data that Domoticz holds from Lua, without having to construct another framework. The obvious catch is that writing to the database allows the possiblity of breaking it.

Thanks, Simon