Use IDX instead of device name in LUA ?

Post Reply
sebitop
Posts: 155
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
RSL/ blyss blind / DI.O switches / FOSCAM / + homemade

sebitop
Posts: 155
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
RSL/ blyss blind / DI.O switches / FOSCAM / + homemade

User avatar
sisaenkov
Posts: 69
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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests