I thought I've read this earlier in the forum, but can't find it, so forgive me if this have been answered before:
My problem is:
In LUA the actual names of devices have to be used for for commands, like commandArray['MySwitchName'] = 'Off'
Problem is, if you change the name of your device, this will break all LUA-scripts.
So question is: is there a way to use the IDX-value instead of the names in your LUA-scripts? This is also how BLockly works.
IDX instead of switchnames in LUA?
Moderator: leecollings
-
- Posts: 331
- Joined: Sunday 22 February 2015 12:19
- Target OS: Linux
- Domoticz version: 2020.x
- Location: Netherlands
- Contact:
Re: IDX instead of switchnames in LUA?
This would think this is a common "problem", has anybody found a solution to make your scripts resilient against changing device names?
-
- Posts: 135
- Joined: Friday 02 January 2015 9:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: Netherlands
- Contact:
Re: IDX instead of switchnames in LUA?
not really that I know of.... except for creating local variables at the top of your script and use them instead of the full switch names. In this way you'll only have to change that the name of the switch once at each script
Re: IDX instead of switchnames in LUA?
I like the fact that I can use the names instead of the IDX. One of my contacts didn't work properly anymore. I had a spare, placed it at the door, used the name of the old one (after renaming the old one first) and started to use it. I don't need to go through all the scripts, it just works. So I wouldn't vote for IDX instead of names, I could live with IDX AND names.
-
- Posts: 331
- Joined: Sunday 22 February 2015 12:19
- Target OS: Linux
- Domoticz version: 2020.x
- Location: Netherlands
- Contact:
Re: IDX instead of switchnames in LUA?
Yeah, that is how I do this now as well. Would even be better if you could have 1 place to maintain al those assignments for all scripts. I'm just starting with LUA, but I imagine that you could use something like an include file?tozzke wrote:not really that I know of.... except for creating local variables at the top of your script and use them instead of the full switch names. In this way you'll only have to change that the name of the switch once at each script
-
- Posts: 192
- Joined: Monday 12 January 2015 23:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: FRANCE
- Contact:
Re: IDX instead of switchnames in LUA?
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: IDX instead of switchnames in LUA?
Something like this should also work using the new otherdevices_idx[] table in LUA to get the current devicename for an IDX.
untested code example:
Jos
untested code example:
Code: Select all
function getdevname4idx(deviceIDX)
for i, v in pairs(otherdevices_idx) do
if v == deviceIDX then
return i
end
end
return 0
end
commandArray[getdevname4idx(123)] = 'Off'
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 14
- Joined: Thursday 07 April 2016 18:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: IDX instead of switchnames in LUA?
jvdz wrote:Something like this should also work using the new otherdevices_idx[] table in LUA to get the current devicename for an IDX.
untested code example:JosCode: Select all
function getdevname4idx(deviceIDX) for i, v in pairs(otherdevices_idx) do if v == deviceIDX then return i end end return 0 end commandArray[getdevname4idx(123)] = 'Off'
Thank you JVDZ this is what I am searching.
-
- Posts: 6
- Joined: Friday 12 May 2017 20:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: IDX instead of switchnames in LUA?
I was also searching for this; Now using name for my scripts, instead of IDX.
You can just use: otherdevices_idx["Bathroom Light"]
Source: http://www.domoticz.com/forum/viewtopic.php?t=12010
You can just use: otherdevices_idx["Bathroom Light"]
Source: http://www.domoticz.com/forum/viewtopic.php?t=12010
I build the latest armv6 here https://github.com/SjoerdNLD/Domoticz-Armv6/releases
Who is online
Users browsing this forum: No registered users and 1 guest