Page 1 of 1
Node number
Posted: Thursday 05 November 2015 19:14
by juankar
Hello
Is it posible to renumber nodes?.
I excluded and include some devices and the node numbers are not consecutive (1,2,3,9,10...) and I would like to get succesive numbres for nodes (1,2,3,4,5...), is ther any way to get succesive numbres for nodes?
Thanks
Re: Node number
Posted: Thursday 05 November 2015 19:47
by gizmocuz
The only way is to exclude all your nodes, hard reset the controller, and include them again
but why care? it is just a number
Re: Node number
Posted: Thursday 05 November 2015 19:58
by juankar
Yes, it's justa anumber.... but an important number if you use it in scripts. Suppose you have several scripts working with a node number if this number change it's necessay to change it in all scripts...
Thanks
Re: Node number
Posted: Thursday 05 November 2015 20:09
by jvdz
You are talking about the device IDX, not the Zwave unit number ...right?
IDX numbers are indeed used by JSON calls unless you use the DeviceName like LUA does to find the proper device.
Not sure whether you can change the IDX easily as that is an index field in the Database so potentially links to data in other tables already.
Jos
Re: Node number
Posted: Saturday 07 November 2015 16:41
by Berek
If you're using LUA then it's not too difficult to convert a device name to either a Domoticz IDX or a Z-Wave node number using a json call such as below - this will return you all of the data for each device. You can then use the JSON library to convert this returned data to an LUA table and pull out the data you want by looking for the matching "Name" node. You can also use this technique for getting at lots of other data such as battery level.
Note: JSON library is available here:
http://regex.info/blog/lua/json
e.g. to get the Domoticz IDX
Code: Select all
-- Get the data
local html = http.request("http://<ip_address>:<port>/json.htm?type=devices&filter=all&used=true")
-- Decode the JSON formatted string to a Lua table
local tbl = JSON:decode(html)
-- Now process the table as you wish
or to get the Z-Wave node number, use the following where <nn> is the Domoticz IDX of your Z-Wave controller)
Code: Select all
http://<ip_address>:<port>/json.htm?type=openzwavenodes&idx=<nn>
The <nn> value itself can also be retrieved from the name of the Z-Wave controller in the same way if needed.
Re: Node number
Posted: Sunday 08 November 2015 11:39
by juankar
This is a very useful answer.
I suspect JSON is very useful, but I can't find too much info about how to use it in Domoticz

Re: Node number
Posted: Sunday 08 November 2015 13:50
by Berek
I'm still learning LUA myself, but this is an example of what I've come up with. It's a function that lets you return the value of any parameter from any device. I don't know if it's the most efficient way, but the only other code I've seen involves writing to a temporary file, which can cause problems with permissions and also does a lot of writing to your sd card which is generally held to be a bad thing.
Code: Select all
function getDeviceValue(sDeviceName, sDeviceParameter)
local html = http.request("http://" .. DomoticzIP .. ":" .. DomoticzPort .. "/json.htm?type=devices&filter=all&used=true")
-- Decode the JSON formatted string to a Lua table
local tbl = JSON:decode(html)
-- Loop through the device data looking for the device name
for _, value in pairs(tbl["result"]) do
if value["Name"] == sDeviceName then
return value[sDeviceParameter]
end
end
return nil
end
I have the two variables DomoticzIP and DomoticzPort set to the appropriate values as they are used all over the place in my code - you will need to set them correctly for your own system or just replace them with the correct values.
You may also need to include the http sockets library with "http = require('socket.http')" at the top. It's a while since I did this, but I think I found it in this post:
http://www.domoticz.com/forum/viewtopic ... 638#p22638
As an example of usage, to get the Domoticz IDX for a device named "Hall_PIR" do this:
Code: Select all
local idx = getDeviceValue('Hall_PIR', 'idx')
You can use the same principle to get info on your Z-Wave devices by using the other url I posted earlier.
I've found it very useful to actually see the data that these calls return. If you start a terminal/console session to your Raspberry PI and type the url using curl you'll get the data returned to the console. For example (change the ip address/port for your system):
Code: Select all
curl "http://192.168.1.12:8080/json.htm?type=devices&filter=all&used=true"
Hope that helps.