Use IDX instead of device name in LUA ?

Post Reply
sebitop
Posts: 161
Joined: Sunday 08 June 2014 20:31
Target OS: Raspberry Pi
Domoticz version:
Location: Toulouse France
Contact:

Use IDX instead of device name in LUA ?

Post by sebitop » Sunday 06 August 2017 15:26

Hi all

simple question as i'm struggling to find a clear info.

i would like to check a device using it's idx instead of it's name, is it possible in LUA ?

otherwise is it possible to assign the name of a device to a variable and use this variable in the script instead of repeating the device name ?

idea is just to avoid many changes when i change the name of a device.

thnaks !

seb
domoticz on Raspberry Pi + RFXcom LAN moded
RSL / Blyss / DI.O / Wemos / homemade

sebitop
Posts: 161
Joined: Sunday 08 June 2014 20:31
Target OS: Raspberry Pi
Domoticz version:
Location: Toulouse France
Contact:

Re: Use IDX instead of device name in LUA ?

Post by sebitop » Sunday 06 August 2017 15:52

I found part of the answer

one idea is to set a local var with your device name

local variable = "name of the device"

then you can use commandArray[variable]='On' for exmaple to whitch on your device
domoticz on Raspberry Pi + RFXcom LAN moded
RSL / Blyss / DI.O / Wemos / homemade

User avatar
sisaenkov
Posts: 73
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: Use IDX instead of device name in LUA ?

Post by sisaenkov » Sunday 06 August 2017 19:24

Try this:

Code: Select all

commandArray = {}

function getdevname4idx(deviceIDX)
   for i, v in pairs(otherdevices_idx) do
      if v == deviceIDX then
         return i
      end
   end
   return 0
end
commandArray[getdevname4idx(383)] = 'On'

return commandArray

User avatar
papoo
Posts: 97
Joined: Friday 22 January 2016 23:14
Target OS: Raspberry Pi
Domoticz version: 4.9
Location: France
Contact:

Re: Use IDX instead of device name in LUA ?

Post by papoo » Friday 29 December 2017 16:02

thanks sisaenkov

User avatar
McMelloW
Posts: 194
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Use IDX instead of device name in LUA ?

Post by McMelloW » Friday 29 December 2017 16:36

Try to use dzVents for Lua and idx for devices as well. See this wiki page http://www.domoticz.com/wiki/DzVents:_n ... _scripting.
Greetings McMelloW

Post Reply

Who is online

Users browsing this forum: atagesson and 3 guests