Page 1 of 1

IDX in LUA (read)

Posted: Thursday 04 January 2018 11:25
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.

Re: IDX in LUA (read)

Posted: Thursday 04 January 2018 11:46
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