Pass2PHP

Moderator: leecollings

User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

Could it be that you have different versions of the lua and pass2php file?
In the lua file the 4 tables (c,s,i,t) are sent but your php only captures one ($c).
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Post by Egregius »

@Moderators: can you move this topic to the PHP board please?
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: LUA Pass2php

Post by dutchdevil83 »

Egregius wrote:Could it be that you have different versions of the lua and pass2php file?
In the lua file the 4 tables (c,s,i,t) are sent but your php only captures one ($c).
Nope, only have one pass2php version. Pull this from your github and copied this. This is the whole pass2php.php file (in /var/www/html/secure/):

Code: Select all

<?php error_reporting(E_ALL);ini_set("display_errors","on");date_default_timezone_set('Europe/Amsterdam');
define('time',$_SERVER['REQUEST_TIME']);$actions=0;
$c=ex($_REQUEST['c']);
//lg('4. Egregius Start of Pass2PHP');
foreach($c as $device=>$status){
 // lg($device.' = '.$status);
	if(@include '/var/www/html/secure/pass2php/'.$device.'.php'){
		//Filter the 'set level' stuff away for dimmers
		if(in_array($device,array('Verlichting Slaapkamer'))){
			if($status=='Off')apcu_store('s'.$device,'Off');
			else apcu_store('s'.$device,filter_var($status,FILTER_SANITIZE_NUMBER_INT));
		}else apcu_store('s'.$device,$status);
		apcu_store('t'.$device,time);
		$dev=$device;
		}
}
if(!isset($dev))die();
include '/var/www/html/secure/pass2php/__CRON.php';
function sw($idx,$action='',$info=''){
	lg('SWITCH '.$idx.' '.$action.' '.$info);
	if(empty($action))file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd=Toggle');
	else file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd='.$action);
	global $actions;$actions=$actions+1;
}
function double($idx,$action,$comment='',$wait=2000000){
	sw($idx,$action,$comment);
	usleep($wait);
	sw($idx,$action,$comment.' repeat',0);
	global $actions;$actions=$actions+2;
}
function sl($idx,$level,$info=''){
	lg('SETLEVEL '.$idx.' '.$level.' '.$info);
	file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd=Set%20Level&level='.$level);
}
function ud($idx,$nvalue,$svalue,$info=""){
	if(!in_array($idx, array(395,532,534)))lg("UPDATE ".$idx." ".$nvalue." ".$svalue." ".$info);
	file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
	global $actions;$actions=$actions+1;
}
function telegram($msg,$silent=true,$to=1){
	$telegrambot='123456789:ABCD-xCRhO-RBfUqICiJs8q9A_3YIr9irxI';
	$telegramchatid=123456789;
	$telegramchatid2=234567890;
	for($x=1;$x<=100;$x++){
		$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid.'&text='.urlencode($msg).'&disable_notification='.$silent));
		if(isset($result->ok))
			if($result->ok===true){lg('telegram sent to 1: '.$msg);break;}
			else lg('telegram sent failed');sleep($x*3);
		global $actions;$actions=$actions+1;
	}
	if($to>=2)
		for($x=1;$x<=100;$x++){
			$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid2.'&text='.urlencode($msg).'&disable_notification='.$silent));
			if(isset($result->ok))
				if($result->ok===true){lg('telegram sent to 2: '.$msg);break;}
				else lg('telegram sent failed');sleep($x*3);
			global $actions;$actions=$actions+1;
		}
	elseif($to==3){ios($msg);global $actions;$actions=$actions+1;}

}
function lg($msg){file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=addlogmessage&message='.urlencode('=> '.$msg));}
function ios($msg){
	$appledevice='1234567890/ZHxYptWlD4zoKvGC1VYH805kSRqROHYVNSUzmWV';
	$appleid='[email protected]';
	$applepass='applepass';
	require_once('findmyiphone.php');
	$fmi=new FindMyiPhone(appleid,applepass);
	$fmi->playSound(appledevice,$msg);
	sms($msg);
}
function sms($msg){
	exit;
	$smsuser='clickatelluser';
	$smspassword='clickatellpass';
	$smsapi=1234567;
	$smstofrom=32123456789;
	file_get_contents('http://api.clickatell.com/http/sendmsg?user='.$smsuser.'&password='.$smspassword.'&api_id='.$smsapi.'&to='.$smstofrom.'&text='.urlencode($msg).'&from='.$smstofrom.'');
}
function RefreshZwave($node){
	$last=apcu_fetch('refresh'.$node);
	apcu_store('refresh'.$node,time);
	if($last<time-3600){
		$devices=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=openzwavenodes&idx=3',false),true);
		foreach($devices['result'] as $devozw)
			if($devozw['NodeID']==$node){
				$device=$devozw['Description'].' '.$devozw['Name'];
				break;
			}
		lg(' > Refreshing node '.$node.' '.$device);
		for($k=1;$k<=5;$k++){
			$result=file_get_contents('http://127.0.0.1:8080/ozwcp/refreshpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>'racp','node'=>$node)),),)));
			if($result==='OK')break;
			sleep(1);
		}
		/*if(apcu_fetch('timedeadnodes')<time-298){apcu_store('timedeadnodes',time);foreach($devices as $node=>$data){if($node=="result"){foreach($data as $index=>$eltsNode){if($eltsNode["State"]=="Dead"&&!in_array($eltsNode['NodeID'],array(57))){telegram('Node '.$eltsNode['NodeID'].' '.$eltsNode['Description'].' ('.$eltsNode['Name'].') marked as dead, reviving '.ZwaveCommand($eltsNode['NodeID'],'HasNodeFailed'));ControllerBusy(10);ZwaveCommand(1,'Cancel');}}}}}*/
	}
}
function Zwavecancelaction(){file_get_contents('http://127.0.0.1:8080/ozwcp/admpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>'cancel')),),)));}
function ZwaveCommand($node,$command){$cm=array('AssignReturnRoute'=>'assrr','DeleteAllReturnRoutes'=>'delarr','NodeNeighbourUpdate'=>'reqnnu','RefreshNodeInformation'=>'refreshnode','RequestNetworkUpdate'=>'reqnu','HasNodeFailed'=>'hnf','Cancel'=>'cancel');$cm=$cm[$command];for($k=1;$k<=5;$k++){$result=file_get_contents('http://127.0.0.1:8080/ozwcp/admpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>$cm,'node'=>'node'.$node)),),)));if($result=='OK')break;sleep(1);}return $result;}
function ControllerBusy($retries){for($k=1;$k<=$retries;$k++){$result=file_get_contents('http://127.0.0.1:8080/ozwcp/poll.xml');$p=xml_parser_create();xml_parse_into_struct($p,$result,$vals,$index);xml_parser_free($p);foreach($vals as $val){if($val['tag']=='ADMIN'){$result=$val['attributes']['ACTIVE'];break;}}if($result=='false')break;if($k==$retries){ZwaveCommand(1,'Cancel');break;}sleep(1);}}
function convertToHours($time){if($time<600)return substr(strftime('%M:%S',$time),1);elseif($time>=600&&$time<3600)return strftime('%M:%S',$time);else return strftime('%k:%M:%S',$time);}
function ex($x){
	$return=array();
	$pieces=explode('#',$x);
	foreach($pieces as $piece){
		$keyval=explode('|',$piece);
		if(count($keyval)>1)$return[$keyval[0]]=$keyval[1];
		else $return[$keyval[0]]='';
	}
	return $return;
}
Do i have to change anything in APCU.php ? Or is there some way to print the contents of the device table that is stored away?
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Oh, I see... I didn't update all files...
Github updated now, that's the version I'm using right now. Totally based on using apcu.

in __CRON.PHP the cron604800 part grabs all used devices from domoticz and stores their current state, timestamp and idx in cache.
Those can be retrieved with apcu_fetch('Xnameofdevice') where X is s for state, t for timestamp or i for idx.
The sw function is simplified and only requires the name of the device, the function itself grabs the idx then. Also new in this sw function is that virtual devices will be used in cache if the idx is unknown. This way I managed to remove my dummy hardware from domoticz.
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: Pass2PHP

Post by dutchdevil83 »

Egregius wrote:Oh, I see... I didn't update all files...
Github updated now, that's the version I'm using right now. Totally based on using apcu.

in __CRON.PHP the cron604800 part grabs all used devices from domoticz and stores their current state, timestamp and idx in cache.
Those can be retrieved with apcu_fetch('Xnameofdevice') where X is s for state, t for timestamp or i for idx.
The sw function is simplified and only requires the name of the device, the function itself grabs the idx then. Also new in this sw function is that virtual devices will be used in cache if the idx is unknown. This way I managed to remove my dummy hardware from domoticz.
OK thanx, will update the files and report back!
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Could be that there are changes later today, installing on a friends domoticz at the moment. Maybe I'll find other issues.
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: Pass2PHP

Post by dutchdevil83 »

Egregius wrote:Could be that there are changes later today, installing on a friends domoticz at the moment. Maybe I'll find other issues.
I`m trying everything to get it working but it looks like it`s not storing in cache with apcu ? How can i debug this to look where it`s going wrong?
(I`m assuming i don`t have to change any other files to get apcu working??)

I have these files now;

TEST.php:

Code: Select all

<?php
lg($device.' = '.$status);

if ($status=="On"&&apcu_fetch('sVerlichting Dressoir')=='Off') {
	//lg("IDX : "$i['Verlichting_Dressoir']);
	lg('Hij staat aan'); 
   sw('Verlichting Dressoir','On');
} 
if ($status=="Off"&&apcu_fetch('sVerlichting Dressoir')=='On'){
	lg ('Hij staat niet aan');
    sw('Verlichting Dressoir','Off');
}
pass2php.php:

Code: Select all

<?php error_reporting(E_ALL);ini_set("display_errors","on");date_default_timezone_set('Europe/Amsterdam');define('time',$_SERVER['REQUEST_TIME']);$c=ex($_REQUEST['c']);
//lg('4. Egregius Start of Pass2PHP');
foreach($c as $device=>$status){
	// lg($device.' = '.$status);
	if(@include '/var/www/html/secure/pass2php/'.$device.'.php'){
		if($device=='brander'){
			if($status!=apcu_fetch('sbrander'))apcu_store('t'.$device,time);
		}else{
			if(apcu_fetch('t'.$device)<time)apcu_store('t'.$device,time);
		}
		//Filter the 'set level' stuff away for dimmers
		if(in_array($device,array('Verlichting Slaapkamer'))){
			if($status=='Off')apcu_store('s'.$device,'Off');
			else apcu_store('s'.$device,filter_var($status,FILTER_SANITIZE_NUMBER_INT));
		}else apcu_store('s'.$device,$status);
		$dev=$device;
		if($device=='miniliving1s'&&$status=='Off')print strftime("%Y-%m-%d %H:%M:%S",time()).'   => CRON Forced'.PHP_EOL;
		else print strftime("%Y-%m-%d %H:%M:%S",time()).'   -> '.$device.' -> '.$status.PHP_EOL;
	}
	else{if(!empty($device)&&!endswith($device,'_Utility')&&!endswith($device,'_Temperature'))print strftime("%Y-%m-%d %H:%M:%S",time()).'      '.$device.' -> '.$status.PHP_EOL;}
}
if(!isset($dev))die();
include '/var/www/html/secure/pass2php/__CRON.php';
function sw($name,$action='Toggle',$comment=''){
	$msg = strftime("%Y-%m-%d %H:%M:%S",time()).'   => SWITCH '.$name.' => '.$action;
	if(!empty($comment)) $msg.=' => '.$comment;
	print $msg.PHP_EOL;
	if(apcu_exists('i'.$name)){
		file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx='.apcu_fetch('i'.$name).'&switchcmd='.$action);
		//sleep(2);
	}else{
		apcu_store('s'.$name,$action);apcu_store('t'.$name,time);
	}
}
function double($name,$action,$comment='',$wait=2000000){sw($name,$action,$comment);usleep($wait);sw($name,$action,$comment.' repeat');}
function sl($name,$level,$info=''){
	$msg=strftime("%Y-%m-%d %H:%M:%S",time()).'   => SETLEVEL '.$name.' => '.$level;
	if(!empty($comment)) $msg.=' => '.$comment;
	print $msg.PHP_EOL;
	if(apcu_exists('i'.$name)){
		file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx='.apcu_fetch('i'.$name).'&switchcmd=Set%20Level&level='.$level);
		//sleep(2);
	}
}
function ud($name,$nvalue,$svalue,$info=""){
	if(apcu_exists('i'.$name)){
		file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx='.apcu_fetch('i'.$name).'&nvalue='.$nvalue.'&svalue='.$svalue);
		//sleep(4);
	}else{
		apcu_store('s'.$name,$svalue);apcu_store('t'.$name,time);
	}
}
function telegram($msg,$silent=true,$to=1){
	$telegrambot='123456789:ABCD-xCRhO-RBfUqICiJs8q9A_3YIr9irxI';
	$telegramchatid=123456789;
	$telegramchatid2=234567890;
	for($x=1;$x<=100;$x++){
		$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid.'&text='.urlencode($msg).'&disable_notification='.$silent));
		if(isset($result->ok))
			if($result->ok===true){lg('telegram sent to 1: '.$msg);break;}
			else lg('telegram sent failed');sleep($x*3);
		global $actions;$actions=$actions+1;
	}
	if($to>=2)
		for($x=1;$x<=100;$x++){
			$result=json_decode(file_get_contents('https://api.telegram.org/bot'.$telegrambot.'/sendMessage?chat_id='.$telegramchatid2.'&text='.urlencode($msg).'&disable_notification='.$silent));
			if(isset($result->ok))
				if($result->ok===true){lg('telegram sent to 2: '.$msg);break;}
				else lg('telegram sent failed');sleep($x*3);
			global $actions;$actions=$actions+1;
		}
	elseif($to==3){ios($msg);global $actions;$actions=$actions+1;}

}
function lg($msg){file_get_contents('http://127.0.0.1:8080/json.htm?type=command&param=addlogmessage&message='.urlencode('=> '.$msg));}
function ios($msg){
	$appledevice='1234567890/ZHxYptWlD4zoKvGC1VYH805kSRqROHYVNSUzmWV';
	$appleid='[email protected]';
	$applepass='applepass';
	require_once('findmyiphone.php');
	$fmi=new FindMyiPhone(appleid,applepass);
	$fmi->playSound(appledevice,$msg);
	sms($msg);
}
function sms($msg){
	exit;
	$smsuser='clickatelluser';
	$smspassword='clickatellpass';
	$smsapi=1234567;
	$smstofrom=32123456789;
	file_get_contents('http://api.clickatell.com/http/sendmsg?user='.$smsuser.'&password='.$smspassword.'&api_id='.$smsapi.'&to='.$smstofrom.'&text='.urlencode($msg).'&from='.$smstofrom.'');
}
function RefreshZwave($node){
	$last=apcu_fetch('refresh'.$node);
	apcu_store('refresh'.$node,time);
	if($last<time-3600){
		$devices=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=openzwavenodes&idx=3',false),true);
		foreach($devices['result'] as $devozw)
			if($devozw['NodeID']==$node){
				$device=$devozw['Description'].' '.$devozw['Name'];
				break;
			}
		print strftime("%Y-%m-%d %H:%M:%S",time()).'   => Refreshing node '.$node.' '.$device.PHP_EOL;
		for($k=1;$k<=5;$k++){
			$result=file_get_contents('http://127.0.0.1:8080/ozwcp/refreshpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>'racp','node'=>$node)),),)));
			if($result==='OK')break;
			sleep(1);
		}
		if(apcu_fetch('timedeadnodes')<time-298){
			apcu_store('timedeadnodes',time);
			foreach($devices as $node=>$data){
				if($node=="result"){
					foreach($data as $index=>$eltsNode){
						if($eltsNode["State"]=="Dead"&&!in_array($eltsNode['NodeID'],array(57))){
							telegram('Node '.$eltsNode['NodeID'].' '.$eltsNode['Description'].' ('.$eltsNode['Name'].') marked as dead, reviving '.ZwaveCommand($eltsNode['NodeID'],'HasNodeFailed'));
							ControllerBusy(10);
							ZwaveCommand(1,'Cancel');
						}
					}
				}
			}
		}
	}
}
function Zwavecancelaction(){file_get_contents('http://127.0.0.1:8080/ozwcp/admpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>'cancel')),),)));}
function ZwaveCommand($node,$command){$cm=array('AssignReturnRoute'=>'assrr','DeleteAllReturnRoutes'=>'delarr','NodeNeighbourUpdate'=>'reqnnu','RefreshNodeInformation'=>'refreshnode','RequestNetworkUpdate'=>'reqnu','HasNodeFailed'=>'hnf','Cancel'=>'cancel');$cm=$cm[$command];for($k=1;$k<=5;$k++){$result=file_get_contents('http://127.0.0.1:8080/ozwcp/admpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>$cm,'node'=>'node'.$node)),),)));if($result=='OK')break;sleep(1);}return $result;}
function ControllerBusy($retries){for($k=1;$k<=$retries;$k++){$result=file_get_contents('http://127.0.0.1:8080/ozwcp/poll.xml');$p=xml_parser_create();xml_parse_into_struct($p,$result,$vals,$index);xml_parser_free($p);foreach($vals as $val){if($val['tag']=='ADMIN'){$result=$val['attributes']['ACTIVE'];break;}}if($result=='false')break;if($k==$retries){ZwaveCommand(1,'Cancel');break;}sleep(1);}}
function convertToHours($time){if($time<600)return substr(strftime('%M:%S',$time),1);elseif($time>=600&&$time<3600)return strftime('%M:%S',$time);else return strftime('%k:%M:%S',$time);}
function ex($x){
	$return=array();
	$pieces=explode('#',$x);
	foreach($pieces as $piece){
		$keyval=explode('|',$piece);
		if(count($keyval)>1)$return[$keyval[0]]=$keyval[1];
		else $return[$keyval[0]]='';
	}
	return $return;
}
function endswith($string, $test) {
    $strlen = strlen($string);
    $testlen = strlen($test);
    if ($testlen > $strlen) return false;
    return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
}
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

What's in the domoticz log? Looking in bash that is. Something like tail -f /var/log/domoticz.log
That shows more than the logfile in the webui.
Do you have apcu installed? apt-get install php5-apcu or apt-get install php7-apcu depening on your php version.

I'm still not at that point of the installation at my friends pi. Thing is so outdated that It's already busy for 2 hours updating...
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

adding some more and more to your script ;)
great way to learn php :D

one more question:
you are using also 'slapen'
it is set to 'on' when some PIR have not detected motion for some time, but where do you set this back to 'off' ?
thanks!
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

From my floorplan, or with a simple remote upstairs.
Slapen (sleep) activates pirs downstairs as alarm, makes sure everything downstairs is off.
We mostly activate it ourself, the script after 4 hours is there in case we forgot it.
Same thing with 'weg' (away) after 12 hours.
When away upstairs is also off and armed.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Hey @Egregius more and more people getting inspired :) . System is snoring like a kitten here in The Netherlands. :)

Sent from my SM-G925F using Tapatalk
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Lol, thanks and enjoy ;)
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Egregius wrote:Lol, thanks and enjoy ;)
@Egregius.. Just to keep things fast as they are.

What do you think when using grafana and influxdb.. Use pass2php to push the data in Influxdb... Or have domoticz deal with it using data - push.

As most tutorials describe the push one but hey they are not familiar with the speed of pass2php.

Just want to create some nice dashboard :)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

I would use the cron in pass2php ;)
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: RE: Re: Pass2PHP

Post by sincze »

Egregius wrote:I would use the cron in pass2php ;)
A yes. That is what I thought :) the famous__CRON.php

Sent from my SM-G925F using Tapatalk
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

do you save all measured data to a mysql server?

something off topic: is your domoticz database copied to somewhere else?
i'm just affraid my sdcard will get lost sometime of my raspberry pi and would love to have all data stored somewhere else, for example my nas server, maybe in a sql server?
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Try rsync to sync the dB each hour day :) it works excellent

Sent from my SM-G925F using Tapatalk
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

You can easily backup the whole sql3lite db with rsync.
And/or send data in realtime to sql.
I only sent all temps every minute to sql, just for good analysis of the heating script.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

Code: Select all

$query="INSERT IGNORE INTO `temp`(`stamp`,`buiten`,`living`,`badkamer`,`kamer`,`tobi`,`alex`,`zolder`,`s_living`,`s_badkamer`,`s_kamer`,`s_tobi`,`s_alex`,`brander`,`badkamervuur`) VALUES ('$stamp','$buiten_temp','$living','$badkamer','$kamer','$tobi','$alex','$zolder','$s_living','$s_badkamer','$s_kamer','$s_tobi','$s_alex','$brander','$badkamervuur');";

$db=new mysqli('localhost','kodi','kodi','domotica');if($db->connect_errno>0)die('Unable to connect to database [' . $db->connect_error . ']');if(!$result=$db->query($query))die('There was an error running the query ['.$query .' - ' . $db->error . ']');$db->close();
i see you are using this, is it possible to give some more information about the 'new mysqli'
my sql server is running on my nas, so i will need to put instead of 'localhost', my address of nas-server
then we have the first and second 'kodi' and 'domotica'
what are these?

Thank you for your help ;)
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

hmm, just thinking:
1st kodi: username
2nd kodi: password
domotica: ?

$query="INSERT IGNORE INTO `temp` => temp will be the tabel where you store the values?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests