Egregius wrote:Oh, forgot to mention:
My way is better than ON FOR X
On for X WILL switch off the switch after that time, no mather what.
My way has the possibility to check multiple stuff before switching of.
Nice , started with it today.
Code: Select all
sudo apt-get install php5
sudo apt-get install php5-cli
I already had JSON.lua (VERSION = 20160916.19) and ee5_baste64.lua in my directory.
within /domoticz/scripts/lua created file script_device_pass2php.lua
Code: Select all
JSON=loadfile('/home/linaro/domoticz/scripts/lua/JSON.lua')()
base64=loadfile('/home/linaro/domoticz/scripts/lua/ee5_base64.lua')()
changed=base64.encode(JSON:encode(devicechanged))
devices=base64.encode(JSON:encode(otherdevices))
idx=base64.encode(JSON:encode(otherdevices_idx))
lastupdate=base64.encode(JSON:encode(otherdevices_lastupdate))
os.execute( '/home/linaro/domoticz/scripts/php/pass2php.php "'..changed..'" "'..devices..'" "'..idx..'" "'..lastupdate..'" &')
commandArray = {}
return commandArray
If I put an error in this one... domoticz log will go crazy so it is reading this file correctly.
Within my domoticz/scripts I created a directory php
Within that directory I created the file: pass2php.php based upon:
https://egregius.be/2016/lua-pass2php-v ... al-script/
Code: Select all
#!/usr/bin/php
<?php
$c=json_decode(base64_decode($_REQUEST['c']),true);
$s=json_decode(base64_decode($_REQUEST['s']),true);
$i=json_decode(base64_decode($_REQUEST['i']),true);
$t=json_decode(base64_decode($_REQUEST['t']),true);
$a=$s[key($c)];$devidx=$i[key($c)];
$events=array(
226=>'motion_keuken',
672=>'motion_trap_boven',
524=>'motion_trap',
366=>'motion_kastenkamer'
);
if(isset($events[$devidx]))$events[$devidx]();
//START USERFUNCTIONS
function motion_kastenkamer(){
global $a,$s,$i,$t;
if($a=="On"){
// sw($i['Lamp (Kastenkamer)'],'On');
sw(62,'On'); // 62 = Lamp Kastenkamer
}
}
//END USERFUNCTIONS. Only change IP:PORT and ios,sms account details below
function sw($idx,$action="",$info="",$Usleep=600000){lg("SWITCH ".$action." ".$info);if(empty($action))curl("http://192.168.2.10:8080/json.htm?type=command¶m=switchlight&idx=".$idx."&switchcmd=Toggle");else curl("http://192.168.2.10:8080/json.htm?type=command¶m=switchlight&idx=".$idx."&switchcmd=".$action);usleep($Usleep);}
function sl($idx,$level,$info="",$Usleep=600000){lg("SETLEVEL ".$level." ".$info);curl("http://192.168.2.10:8080/json.htm?type=command¶m=switchlight&idx=".$idx."&switchcmd=Set%20Level&level=".$level);usleep($Usleep);}
function ud($idx,$nvalue,$svalue,$info="",$Usleep=600000){if(!in_array($idx, array(395,532,534)))lg("UPDATE ".$nvalue." ".$svalue." ".$info);curl('http://192.168.2.10:8080/json.htm?type=command¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);usleep($Usleep);}
function double($idx,$action,$comment='',$wait=4000000){sw($idx,$action,$comment,$wait);sw($idx,$action,$comment.' repeat',0);}
function lg($msg){curl('http://192.168.2.10:8080/json.htm?type=command¶m=addlogmessage&message='.urlencode('=> '.$msg));}
function curl($url){$headers=array('Content-Type: application/json');$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_FRESH_CONNECT,TRUE);curl_setopt($ch,CURLOPT_TIMEOUT,5);$data=curl_exec($ch);curl_close($ch);return $data;}
All functions are in the script on 1 line (no carrier returns)
It seems I was not allowed to use 127.0.0.1 (not authorized)... So changed it to actual IP of Domoticz machine.
Tested that by manually executing curl ,,, and the switch command as described in domoticz json event wiki.
The idea... if 366=>'motion_kastenkamer' is triggered... it should switch on the light idx=62
Code: Select all
sw(62,'On'); // 62 = Lamp Kastenkamer
However for some reason that does not happen. I don't see anything in the log.
Did not see where this went wrong. Unfortunately.