IDX in LUA (read)

Moderator: leecollings

Post Reply
pdjm43
Posts: 30
Joined: Friday 12 December 2014 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: UK
Contact:

IDX in LUA (read)

Post by pdjm43 »

Hi there,
I use zwave TRV valves for my heating and sometimes they fail and need excluding and re-adding. When I write to them I use their IDX, which I store in a variable. If a valve is removed then I put 999 in the variable which stops the code from executing for that valve.
So, i re-add the valve and put the new IDX in the variable.
But, when I look at the current setting of the valve at the moment I use the name. What I'd like to do is look at the IDX for this, then I don't have to add/name the device into the GUI.

At the moment I use valve=tonumber(otherdevices_svalues["Set_"..zoneName])

I'd like to use valve=tonumber(otherdevices_svalues[idx])

The IDX comes from idx=tostring(uservariables["valve_idx_"..zoneName])

I can't work out how to do this.
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: IDX in LUA (read)

Post by jvdz »

There is an otherdevices_idx[] table available to return the IDX for a DeviceName.
The other way around be accomplished by something like this:

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'
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest