Include node trough json?
Moderator: leecollings
-
- Posts: 9
- Joined: Sunday 01 May 2016 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Include node trough json?
Hi,
Is it possible to start node inclusion trough a json call?
Is it possible to start node inclusion trough a json call?
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Include node trough json?
Ofcourse. Everything you can do in the web interface is done by json calls.
Start inclusion (idx is the idx of your zwave controller):
Check if node is included:
Cancel the inclusion:
Tip: All this is found using the developer view of a good browser.
Start inclusion (idx is the idx of your zwave controller):
Code: Select all
json.htm?type=command¶m=zwaveinclude&idx=3&secure=false
Code: Select all
json.htm?type=command¶m=zwaveisnodeincluded&idx=3
Code: Select all
json.htm?type=command¶m=zwavecancel&idx=3
-
- Posts: 9
- Joined: Sunday 01 May 2016 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Include node trough json?
Many thanks for your reply Egregius.
Seems though as if domoticz hangs when i try it, which browser would you recommend to be able to view from developer view?
Seems though as if domoticz hangs when i try it, which browser would you recommend to be able to view from developer view?
-
- Posts: 71
- Joined: Saturday 13 July 2013 2:45
- Target OS: Linux
- Domoticz version: 3.5877
- Location: Scotland
- Contact:
Re: Include node trough json?
They all pretty much offer this now - I use Chrome, but basically anything that lets you see the actual network requests being made.johos wrote:Many thanks for your reply Egregius.
Seems though as if domoticz hangs when i try it, which browser would you recommend to be able to view from developer view?
So you load Domoticz web page, open developer tools, and then click on the stuff you want to control and monitor what network requests are made. In this case you would navigate to the hardware tab, choose the ZWave hardware, and then start include mode - and check what network request that generates, and then while the dialog is open saying it is waiting for you to include a node - the network requests will continuously be made to the URL the web interface uses to check if the node was included. You can verify what data Domoticz returns when a node is successfully included.
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
-
- Posts: 9
- Joined: Sunday 01 May 2016 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Include node trough json?
Thank you for your reply asjmcguire!
i'll try it out.
when i try using the json command "json.htm?type=command¶m=zwaveinclude&idx=1&secure=false" my domoticz becomes unresponsive, is there something i'm missing?
i'll try it out.
when i try using the json command "json.htm?type=command¶m=zwaveinclude&idx=1&secure=false" my domoticz becomes unresponsive, is there something i'm missing?
-
- Posts: 71
- Joined: Saturday 13 July 2013 2:45
- Target OS: Linux
- Domoticz version: 3.5877
- Location: Scotland
- Contact:
Re: Include node trough json?
Well the first question to ask - is - is your ZWave stick actually listed as idx 1 in the list of hardware?johos wrote:Thank you for your reply asjmcguire!
i'll try it out.
when i try using the json command "json.htm?type=command¶m=zwaveinclude&idx=1&secure=false" my domoticz becomes unresponsive, is there something i'm missing?
The second question is - when you say it is unresponsive - does it still respond to (for example) :
json.htm?type=devices&filter=all
I notice when I do certain ZWave tasks - like heal the network, that my CPU use jumps to 100%
You should check if json.htm?type=command¶m=zwaveisnodeincluded&idx=1 returns anything after you have started the include process. Domoticz seems to call this every second once it starts the include.
json.htm?type=command¶m=zwavecancel&idx=1 is called when you abort the process.
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
-
- Posts: 9
- Joined: Sunday 01 May 2016 19:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Include node trough json?
asjmcguire,
I was so certain that the controller was idx1 but actually it was idx2
so problem solved, thank you for excellent support!!
BTW, you wouldn't happen to know if it's possible to auto assign devices after node inclusion?
I was so certain that the controller was idx1 but actually it was idx2
so problem solved, thank you for excellent support!!
BTW, you wouldn't happen to know if it's possible to auto assign devices after node inclusion?
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Include node trough json?
What do you mean with auto assign?
-
- Posts: 71
- Joined: Saturday 13 July 2013 2:45
- Target OS: Linux
- Domoticz version: 3.5877
- Location: Scotland
- Contact:
Re: Include node trough json?
I expect he means that after you add a node through inclusion in ZWave, it's still not actually available to Domoticz until you have go to settings, clicked on Allow new hardware for 5 minutes, and then gone back to the ZWave screen, into the OZW Control Panel and actually changed the status of the device - at which point it will show up as a device in the Unused devices in Domoticz.Egregius wrote:What do you mean with auto assign?
It's a pain with stuff that monitors energy because quite often the Allow new hardware setting has past the 5 minute timer and shut off and so you miss the ZWave message with the data about energy use.
In answer to the question - yes I expect it is possible.
Here is how I would do it:
After the node has been included (ie - json.htm?type=command¶m=zwaveisnodeincluded&idx=2 says True instead of false.)
I would then query
Code: Select all
json.htm?type=devices&filter=all&used=false&order=id
Code: Select all
json.htm?type=command¶m=allownewhardware&timeout=5
You then query
Code: Select all
json.htm?type=devices&filter=all&used=false&order=id
I'd probably store a variable ($count = 1) at this point and every time a new IDX appears in the list over the next 5 minutes I would request:
Code: Select all
json.htm?type=setused&idx=<NEWIDX>&name=AutoAdd_{$count}&used=true
You'd need to keep checking on
Code: Select all
/json.htm?type=settings
So this is the flow (untested and possibly containing parsing errors or infinite loops):
Code: Select all
<?php
$domBase = "192.168.1.6:8080"; //IP and Port
// This is roughly how to add new nodes:
$result = domZWaveInclude(2); //your ZWave Hardware IDX, default 120 second timeout
if ($result) {
$devs = domZWaveAddNode(); //default 300 second timeout, 1 device limit
print_r($devs);
}
function domURLHelper($url) {
global $domBase;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://{$domBase}{$url}/json.htm?");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$ret = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] == 200) {
if (stripos($info['content_type'],"application/json") !== false) {
return json_decode($ret,true);
}
return $ret;
}
}
function domZWaveInclude($zwaveIDX,$timeout = 120) {
$included = 0;
$count = 0;
domURLHelper("command¶m=zwaveinclude&idx={$zwaveIDX}&secure=false");
sleep(1);
while (!$included) {
$ret = null;
$ret = domURLHelper("command¶m=zwaveisnodeincluded&idx={$zwaveIDX}");
if ($ret['result']) {
// a node was included
$included = 1;
break;
}
$count++;
if ($count >= $timeout) { break; }
sleep(1);
}
if (!$included) { return 0; }
return 1;
}
function domZWaveAddNode($timeout = 300, $numdevs = 1) {
$devcount = 0;
$timecount = 0;
$devs = array();
$ret = domURLHelper("type=devices&filter=all&used=false&order=id");
$last = array_reverse($ret['result']);
$last_idx = $last['idx'];
domAllowHardware();
while($timecount < $timeout) {
$ret = null;
$ret = domURLHelper("type=settings");
if (!$ret['AcceptNewHardware']) { break; }
$ret = null;
$ret = domURLHelper("type=devices&filter=all&used=false&order=id");
$last = null;
$last = array_reverse($ret['result']);
$t = $last['idx'];
if ($t !== $last_idx) {
$devcount++;
domURLHelper("type=setused&idx={$t}&name=AutoAdd_{$devcount}&used=true");
$devs[] = $t;
if ($devcount == $numdevs || $timecount >= $timeout) {
break;
}
}
$timecount++;
sleep(1);
}
return $devs;
}
function domAllowHardware($timeout = 5) {
domURLHelper("type=command¶m=allownewhardware&timeout={$timeout}");
}
?>
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
-
- Posts: 71
- Joined: Saturday 13 July 2013 2:45
- Target OS: Linux
- Domoticz version: 3.5877
- Location: Scotland
- Contact:
Re: Include node trough json?
By the way - it's just occurred to me -
Hitting the acceptnewhardware URL mentioned above and putting something like 15 in the timeout, BEFORE going through the ZWave include process, would probably mean Domoticz would automatically add any nodes you include until the timer runs out.
Hitting the acceptnewhardware URL mentioned above and putting something like 15 in the timeout, BEFORE going through the ZWave include process, would probably mean Domoticz would automatically add any nodes you include until the timer runs out.
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
Who is online
Users browsing this forum: No registered users and 1 guest