Find idx from name

Moderator: leecollings

Post Reply
juankar
Posts: 221
Joined: Saturday 30 August 2014 20:20
Target OS: Linux
Domoticz version: 4.
Location: Spain
Contact:

Find idx from name

Post 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
Last edited by juankar on Thursday 19 May 2016 11:33, edited 1 time in total.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Find idx from name

Post by Egregius »

My php script works always with devicename. What a nightmare if you need idx's in scripts.
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Find idx from name

Post 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.
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
User avatar
bobkersten
Posts: 34
Joined: Tuesday 06 October 2015 9:17
Target OS: Linux
Domoticz version: beta
Location: Venray
Contact:

Re: Find idx from name

Post 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"]
Mac mini w/ ESXi running Ubuntu w/ Domoticz custombuild, SolarEdge 3500Wp, S0 Meter, P1 Smart Meter, RFXtrx433e, Aeotec Z-Stick Gen5
juankar
Posts: 221
Joined: Saturday 30 August 2014 20:20
Target OS: Linux
Domoticz version: 4.
Location: Spain
Contact:

Re: Find idx from name

Post 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
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Find idx from name

Post 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
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest