Include node trough json?
Posted: Sunday 07 May 2017 23:17
Hi,
Is it possible to start node inclusion trough a json call?
Is it possible to start node inclusion trough a json call?
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
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?
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?
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?
Code: Select all
json.htm?type=devices&filter=all&used=false&order=id
Code: Select all
json.htm?type=command¶m=allownewhardware&timeout=5
Code: Select all
json.htm?type=devices&filter=all&used=false&order=id
Code: Select all
json.htm?type=setused&idx=<NEWIDX>&name=AutoAdd_{$count}&used=true
Code: Select all
/json.htm?type=settings
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}");
}
?>