Re: Pass2PHP
Posted: Sunday 07 October 2018 10:44
Thanks for your very detailed answer. From reading this I understand that you are as enthusiastic about Pass2PHP as I am about dzVents
Thanks for your very detailed answer. From reading this I understand that you are as enthusiastic about Pass2PHP as I am about dzVents
Indeed, When I started with Pass2PHP there was no dzVents. I had everything in LUA and was experiencing delays.
Good question indeed. But don't worry. It will all work just fine.poudenes wrote: ↑Monday 08 October 2018 9:43 Thanks for explanation!!! One little question : changing light status will be stored in cache variables. But will they also change in Domoticz? If system crash the cache is gone... Actual change in Domoticz is stored in dB.
Verzonden vanaf mijn iPhone met Tapatalk Pro
With the following code a log line will be written to my domoticz.log Indicating the motion1 was causing the lamp to switch on.Be aware starting with Pass2PHP is like heroin, quite addictive.
As stated by sincze before, for PHP there are millions of users and code examples on the net. So the only limit for using it is your learning curve and your imagination.
Actually, php has never been loaded from Domoticz in my case. There's only one lua script that does a curl to the php page.waaren wrote: ↑Sunday 07 October 2018 9:51 Please correct if I am wrong but what I read in the post with the speed comparison is that the difference from >1000 ms to < 100 ms is the result of loading the PHP with a Lua script (which is described there as being much faster) compared to loading PHP from domoticz. I don't read anything about comparing pure PHP speed with pure Lua speed.
Yes, all values will be in Domoticz also, that is as soon as you sent a switch command (or any other command) back to domoticz.
Code: Select all
function sl($name,$level,$check=false){
global $user;
$idx=idx($name);
lg(' (SETLEVEL) | '.$user.' => '.$name.' '.$level);
if($idx>0){
if($check==false)file_get_contents('http://[::1]:8080/json.htm?type=command¶m=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
else{
if(apcu_fetch($name)!=$level)file_get_contents('http://[::1]:8080/json.htm?type=command¶m=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
}
}else{
apcu_store($name,$level);
apcu_store('T'.$name,time());
}
}
Code: Select all
if(apcu_fetch($name)!=$level)file_get_contents('http://[::1]:8080/json.htm?type=command¶m=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
Code: Select all
function sla($name,$requestedlevel) {
$idx=idx($name);
$json_string=curl(domoticz.'json.htm?type=devices&rid='.$idx); // retrieve current level
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0];
$currentlevel = $parsed_json['Level'];
$currentstatus = $parsed_json['Status'];
$switchtype = $parsed_json['SwitchType'];
if ($currentstatus=='Off') $currentlevel=0;
if( $switchtype=='Dimmer' && $requestedlevel >= 0 && $requestedlevel <= 100 && $idx>0 ) {
if ($requestedlevel >= $currentlevel) {
while ($currentlevel-1 != $requestedlevel) {
sl($name,$currentlevel);
$currentlevel++;
sleep(0.5);
}
}
elseif ($requestedlevel <= $currentlevel) {
while ($currentlevel+1 != $requestedlevel) {
sl($name,$currentlevel);
$currentlevel--;
sleep(0.5);
}
}
}
}
Code: Select all
function nvalue($name,$nvalue)
{
$idx=idx($name);
$json_string=curl(domoticz.'json.htm?type=devices&rid='.$idx); // retrieve current information
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0]; // We are only interested in the results bit.
switch ($nvalue) // Determening the IP Address of KODI Machine.
{
case 'Level':
$value=$parsed_json['Level']; // THis data I can use to find out what is the current DIM value of a dimmer
break;
case 'Status':
$value=$parsed_json['Status']; // Well just an example
break;
case 'SwitchType':
$value=$parsed_json['SwitchType']; // Another example I used this to determine if a device is a Dimmer option
break;
case 'Data':
$value=$parsed_json['Data']; // "Data" : "The Big Bang Theory [S1E1], Pilot (2007)",
break;
default:
$value='NA';
break;
}
return $value;
}
Code: Select all
function nvalue($name,$nvalue)
{
$idx=idx($name);
$json_string=curl(domoticz.'json.htm?type=devices&rid='.$idx); // retrieve current information
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['result'][0]; // We are only interested in the results bit.
if(array_key_exists($nvalue, $parsed_json)) {
$value=$parsed_json[$nvalue];
}
else $value='NA';
return $value;
}
Code: Select all
elseif(in_array($device,array('eettafel','zithoek','kamer','tobi','alex','Xvol','Rliving','Rbureel','RkeukenL','RkeukenR','RkamerL','RkamerR','Rtobi','Ralex','luifel'))){
if($status=='Off'||$status=='Open'){
apcu_store($device,0);
}elseif($status=='On'||$status=='Closed'){
apcu_store($device,100);
}else{
$status=filter_var($status,FILTER_SANITIZE_NUMBER_INT);
apcu_store($device,$status);
}
}
Did you add the name of the dimmer to the array in the pass2php file?Egregius wrote: ↑Tuesday 06 November 2018 12:15 apcu_fetch($name) should return a number.
Can you check the Current State in domoticz (in the events window)?
Did you add the name of the dimmer to the array in the pass2php file?Code: Select all
elseif(in_array($device,array('eettafel','zithoek','kamer','tobi','alex','Xvol','Rliving','Rbureel','RkeukenL','RkeukenR','RkamerL','RkamerR','Rtobi','Ralex','luifel'))){ if($status=='Off'||$status=='Open'){ apcu_store($device,0); }elseif($status=='On'||$status=='Closed'){ apcu_store($device,100); }else{ $status=filter_var($status,FILTER_SANITIZE_NUMBER_INT); apcu_store($device,$status); } }
Code: Select all
2019/02/02 17:28:11 [error] 707#707: *15171 FastCGI sent in stderr: "PHP message: PHP Warning: apcu_fetch(): apc_fetch() expects a string or array of strings. in /var/www/html/secure2/pass2php_include/functions_pass2php.php on line 315" while reading response header from upstream, client: 127.0.0.1, server: pc-domoticz, request: "POST /secure2/pass2php.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "127.0.0.1"
2019/02/02 17:28:26 [error] 706#706: *15439 FastCGI sent in stderr: "PHP message: PHP Warning: apcu_fetch(): apc_fetch() expects a string or array of strings. in /var/www/html/secure2/pass2php_include/functions_pass2php.php on line 315" while reading response header from upstream, client: 127.0.0.1, server: pc-domoticz, request: "POST /secure2/pass2php.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "127.0.0.1"
2019/02/02 17:29:26 [error] 702#702: *16795 FastCGI sent in stderr: "PHP message: PHP Warning: apcu_fetch(): apc_fetch() expects a string or array of strings. in /var/www/html/secure2/pass2php_include/functions_pass2php.php on line 315" while reading response header from upstream, client: 127.0.0.1, server: pc-domoticz, request: "POST /secure2/pass2php.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "127.0.0.1"
Code: Select all
function status($name)
{
if (strpos($name, " ") !== false) $name=str_replace(" ","_",$name);
return apcu_fetch($name); # This is line 315!
}
Yes Domoticz device names and files sometimes have spaces Indeed. But normally the famous string space to _ replacement function would solve the issue.
Code: Select all
$items=array('LGTV - Status','tvled','kristal','denon');
foreach($items as $i)${$i}=apcu_fetch($i);
Code: Select all
${'LGTV - Status'}...
$tvled...
$kristal...
$denon...
Code: Select all
if(${'LGTV - Status'}=='On')sw('LGTV - Status','Off');
ok check.
Code: Select all
if ( $scheme=="night" || status('Manual Override')=='On' )
Egregius wrote: ↑Wednesday 20 June 2018 14:56 That's the one
https://github.com/Egregius/LUA-Pass2PH ... re/cron.sh
You can adjust the sleeps in it and remove lines as needed.
Add it to cron with sudo crontab -e
* * * * * /path/to/script/cron.sh
The script will also check if domoticz is still online and reboot if needed.
ropske wrote: ↑Wednesday 13 March 2019 23:09Egregius wrote: ↑Wednesday 20 June 2018 14:56 That's the one
https://github.com/Egregius/LUA-Pass2PH ... re/cron.sh
You can adjust the sleeps in it and remove lines as needed.
Add it to cron with sudo crontab -e
* * * * * /path/to/script/cron.sh
The script will also check if domoticz is still online and reboot if needed.
when running this cron.sh i receive this error:
cron.sh: 61: cron.sh: Syntax error: end of file unexpected (expecting "then")
you know why?
Thanks