Page 1 of 1

use IDX with devicechanged and/or otherdevices

Posted: Tuesday 12 September 2017 8:40
by tillo
Is it possible to get the device status (On, Off, Open, Closed and so on) from just the IDX value? Insted of using the name of the device?

I have searched the forum and google, and have not found any answer. I know how to to update a device status using 'IDX|X|State' eg. '52|0|Off'
But not how to get te current device status using only the IDX number.

Re: use IDX with devicechanged and/or otherdevices

Posted: Tuesday 12 September 2017 18:40
by lonebaggie
I cannot claim any credit for this function, I found it somewhere on this site, but it returns the switch name from IDX number

function idxname(deviceIDX)
local idx = tonumber(deviceIDX)
for i, v in pairs(otherdevices_idx) do
if v == idx then
return i
end
end
return 0
end

Re: use IDX with devicechanged and/or otherdevices

Posted: Wednesday 13 September 2017 9:12
by tillo
i did stumble on this approach aswell in the forum, it would be nice to see a more efficient way of doing it.

Dose dzVents offer some better solution to this?

Code: Select all

function idxname(deviceIDX)
local idx = tonumber(deviceIDX)
for i, v in pairs(otherdevices_idx) do
	if v == idx then
		return i
	end
end
return 0
end

Re: use IDX with devicechanged and/or otherdevices

Posted: Wednesday 13 September 2017 19:55
by dannybloe
Of course it does! It's trivial with dzVents!