Use IDX instead of device name in LUA ?

Moderator: leecollings

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

Use IDX instead of device name in LUA ?

Post by sebitop »

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 + wifi
Blyss / DI.O / homemade / ESP / wemos
sebitop
Posts: 69
Joined: Sunday 08 June 2014 20:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Toulouse France
Contact:

Re: Use IDX instead of device name in LUA ?

Post by sebitop »

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 + wifi
Blyss / DI.O / homemade / ESP / wemos
User avatar
sisaenkov
Posts: 50
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: Use IDX instead of device name in LUA ?

Post by sisaenkov »

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: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: Use IDX instead of device name in LUA ?

Post by papoo »

thanks sisaenkov
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Use IDX instead of device name in LUA ?

Post by McMelloW »

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: No registered users and 1 guest