Send Z-Wave command in script?

Moderator: leecollings

Post Reply
User avatar
Ben0it
Posts: 17
Joined: Sunday 31 January 2016 21:22
Target OS: Linux
Domoticz version: 3.6745
Location: France
Contact:

Send Z-Wave command in script?

Post by Ben0it »

Hello,

Is it possible to send a Z-Wave command to a device in LUA?

For instance, I would like to change the ring color of a Fibaro wall plug (FGWPE). Using the OpenZWave control panel (as shown in the picture below) I can do this, but using a LUA script, is it possible also?
fgwperingcolor.jpg
fgwperingcolor.jpg (182.16 KiB) Viewed 7585 times
Best Regards,
Last edited by Ben0it on Thursday 11 February 2016 20:49, edited 1 time in total.
-
Benoît.
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Send Z-Wave command in script?

Post by Egregius »

Don't know about lua, but possible in PHP:

Code: Select all

<?php 
$domoticzurl='http://127.0.0.1:8080/';
$zwaveidx=7;
file_get_contents($domoticzurl.'json.htm?type=openzwavenodes&idx='.$zwaveidx);

function ValuePost($command) {
	global $domoticzurl;
	$zwaveurl=$domoticzurl.'ozwcp/valuepost.html';
	$zwaveoptions = array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>$command,),);
	$zwavecontext=stream_context_create($zwaveoptions);
	$result=file_get_contents($zwaveurl,false,$zwavecontext);
	return $result;
}

echo ValuePost('85-CONFIGURATION-config-list-1-62=Green illumination');
What to post can be looked up in developer view of your browser. The example above sets the illumination to green of node 85.
The first file_get_contents is just for authentication.
User avatar
Ben0it
Posts: 17
Joined: Sunday 31 January 2016 21:22
Target OS: Linux
Domoticz version: 3.6745
Location: France
Contact:

Re: Send Z-Wave command in script?

Post by Ben0it »

Thanks for the code, I will try it and report about the result here.
-
Benoît.
User avatar
Ben0it
Posts: 17
Joined: Sunday 31 January 2016 21:22
Target OS: Linux
Domoticz version: 3.6745
Location: France
Contact:

Re: Send Z-Wave command in script?

Post by Ben0it »

Good evening,

Finally, I could find some spare time to play with these commands...it works!

Thanks a lot for the hint.

Best Regards,
-
Benoît.
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Send Z-Wave command in script?

Post by Egregius »

You're sure the 3th line is still in the code?

Code: Select all

file_get_contents($domoticzurl.'json.htm?type=openzwavenodes&idx='.$zwaveidx);
Without that line the second url fails after some time.
User avatar
Ben0it
Posts: 17
Joined: Sunday 31 January 2016 21:22
Target OS: Linux
Domoticz version: 3.6745
Location: France
Contact:

Re: Send Z-Wave command in script?

Post by Ben0it »

Hi,

Here is my code, I invoque from BASH interpreter with arguments:

Code: Select all

$domoticzURL = 'http://127.0.0.1:8080/';

if (count($argv) != 4)
{
    $command = basename($argv[0]);
    echo "Usage: {$command} node function value\n";
    exit(0);
}

$zwaveNodeID = $argv[1];
$nodeFunction = $argv[2];
$nodeFunctionValue = $argv[3];

function Authenticate($domoticzURL, $zwaveIDX)
{
   $result = json_decode(file_get_contents($domoticzURL.'json.htm?type=openzwavenodes&idx='.$zwaveIDX, false, NULL), true);
   
   if (strtoupper($result['status']) == "OK") 
   {
       return true;
   }
   return $result;
}

function SetNodeValue($domoticzURL, $zwaveNodeID, $functionNumber, $functionValue)
{
    $zwaveURL = $domoticzURL.'ozwcp/valuepost.html';
    $zwaveCommand = "{$zwaveNodeID}-CONFIGURATION-config-list-1-{$functionNumber}={$functionValue}";
    $zwaveOptions = array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>$zwaveCommand,),);
    $zwaveContext = stream_context_create($zwaveOptions);

    $result = file_get_contents($zwaveURL, false, $zwaveContext);

    if (strtoupper($result) == "OK")
    {
       return true;
    }
    return $result;
}

$result = Authenticate($domoticzURL, $zwaveNodeID);
if ($result != true)
{
    echo "Failed to authenticate: {$result}";
    return 1;
}

$result = SetNodeValue($domoticzURL, $zwaveNodeID, $nodeFunction, "{$nodeFunctionValue}");
if ($result != true)
{
    echo "Failed to set parameter: {$result}";
    return 2;
}

return 0;
Invocation from shell is performed as follows:

Code: Select all

php -f bin/ozwcmd.php 3 62 "Red illumination"
2016-03-28 - Actually, it seems to fail after a while. Once it fails, if I manually change a parameter from Domoticz' web interface in the OZW control panel, my script works again.

Best Regards,
-
Benoît.
leoncornelissen
Posts: 24
Joined: Monday 27 April 2015 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8258
Location: Netherlands
Contact:

Re: Send Z-Wave command in script?

Post by leoncornelissen »

If I look at the PHP code, I would say that one should be able to convert this to a curl command.
I don't know how I should use the PHP code. I don't have the file: 'ozwcp/valuepost.html';

I want to have a simple curl command to switch the alarm sound of the zwave aeotec siren dependend of the situation.
juankar
Posts: 221
Joined: Saturday 30 August 2014 20:20
Target OS: Linux
Domoticz version: 4.
Location: Spain
Contact:

Re: Send Z-Wave command in script?

Post by juankar »

Curl command equivalent:
curl --data "85-CONFIGURATION-config-list-1-62=Green illumination" http://127.0.0.1:8080/ozwcp/valuepost.html

valuepost.html does not exist as webpage, it's a page "inside http Domoticz server"
rgvandenbosch
Posts: 8
Joined: Tuesday 13 October 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Send Z-Wave command in script?

Post by rgvandenbosch »

Hi there,

I was wondering. When invoking the script with nodeID, Function and Value, how does one know the id of the function and the possible values. In the examples the function '62' is called. What is function 62 and what are the other functions?

Hope someone can help.

Thanx in advance.
sundansx
Posts: 10
Joined: Tuesday 30 May 2017 8:16
Target OS: Windows
Domoticz version:
Contact:

Re: Send Z-Wave command in script?

Post by sundansx »

I have the same question. How did you come up with the "85-CONFIGURATION-config-list-1-62=Green illumination" string? Thanks.
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Send Z-Wave command in script?

Post by Egregius »

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests