LUA Pass2php
Deze code gekregen van tweaker Intellium en verder uitgewerkt tot het helemaal past binnen mijn noden.
Grootste verschil met de oude code is vooral de snelheid.
Voorheen werd mijn php script opgeroepen door Domoticz, nadat Domoticz klaar was met al zijn dingen te doen. Door het nu vanuit LUA te triggeren wordt het script meteen uitgevoerd.
Waar het voorheen 500 tot 1200msec duurde voordat er geschakeld werd is dat nu slecht 80msec.
Anyway, de code:
Download deze 2 bestanden en plaats ze in de Domoticz scripts folder:
JSON.lua ee5_base64.lua
Maak in Domoticz Events een device lua script, pas eventueel de foldernamen aan.
JSON = (loadfile '/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua')() base64 = loadfile('/volume1/@appstore/domoticz/var/scripts/lua/ee5_base64.lua')() enc_devicechanged = base64.encode(JSON:encode(devicechanged)) enc_otherdevices = base64.encode(JSON:encode(otherdevices)) enc_otherdevices_idx = base64.encode(JSON:encode(otherdevices_idx)) enc_otherdevices_lastupdate = base64.encode(JSON:encode(otherdevices_lastupdate)) os.execute( '/volume1/web/secure/pass2php.php "device" "' ..enc_devicechanged.. '" "' ..enc_otherdevices.. '" "' ..enc_otherdevices_idx.. '" "' ..enc_otherdevices_lastupdate.. '" &') commandArray = {} return commandArray
Maak een php bestand met de naam uit os_execute hierboven.
#!/usr/bin/php <?php error_reporting(E_ALL); ini_set("display_errors","on"); setlocale(LC_ALL,'nl_NL.UTF-8'); setlocale(LC_ALL,'nld_nld'); date_default_timezone_set('Europe/Brussels'); $d=new logic; $d->c=json_decode(base64_decode($argv[2]),true); $d->s=json_decode(base64_decode($argv[3]),true); $d->i=json_decode(base64_decode($argv[4]),true); $d->t=json_decode(base64_decode($argv[5]),true); $d->a=$d->s[key($d->c)]; $devidx = $d->i[key($d->c)]; if(isset($d->events[$devidx])) call_user_func(array($d,$d->events[$devidx])); class domoticz { function __construct(){ $time=$_SERVER['REQUEST_TIME']; $this->api="http://127.0.0.1:8084/"; $this->denon='http://192.168.0.4'; $this->ctx=stream_context_create(array('http'=>array('timeout' => 7,))); $this->applepass='password'; $this->appledevice='939FEdWFh848REeBN1nZk0sD/ZHxYptWlD2zoKvGC1VYH405kSRqROHYVNSRzmWV'; $this->appleid='appleid'; $this->sms=false; $this->smsuser='user'; $this->smspassword='password'; $this->smsapi=1234567; $this->smstofrom=32470123456; $this->time=$time; $this->eensec=$time-1; $this->tweesec=$time-2; $this->driesec=$time-3; $this->vijfsec=$time-5; $this->tiensec=$time-10; $this->dertigsec=$time-29; $this->eenmin=$time-58; $this->tweemin=$time-118; $this->driemin=$time-178; $this->vijfmin=$time-298; $this->tienmin=$time-598; $this->halfuur=$time-1795; $this->eenuur=$time-3598; $this->tweeuur=$time-7198; $this->drieuur=$time-10795; $this->vieruur=$time-14395; $this->achtuur=$time-28795; $this->twaalfuur=$time-43190; $this->eendag=$time-82800; $this->zevenochtend=strtotime('7:00'); $this->achtochtend=strtotime('8:00'); $this->achtavond=strtotime('20:00'); $t=microtime(true); $micro=sprintf("%03d",($t-floor($t))*1000); $this->stamp=strftime("%Y-%m-%d %H:%M:%S.", $t).$micro; } function sw($idx,$state="",$name=""){ print $this->stamp." --- SWITCH ".$idx." ".$name." ".$state." "; if(empty($state))file_get_contents($this->api."json.htm?type=command¶m=switchlight&idx=".$idx."&switchcmd=Toggle"); else file_get_contents($this->api."json.htm?type=command¶m=switchlight&idx=".$idx."&switchcmd=".$state); usleep(250000); } function sl($idx,$level,$name=""){ print $this->stamp." --- SET LEVEL ".$idx." ".$name." ".$level." "; file_get_contents($this->api . "json.htm?type=command¶m=switchlight&idx=".$idx."&switchcmd=Set%20Level&level=".$level); usleep(250000); } function ud($idx,$nvalue,$svalue,$name=""){ print $this->stamp." --- UPDATE ".$idx." ".$name." ".$nvalue." ".$svalue." "; file_get_contents($this->api . 'json.htm?type=command¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue); usleep(250000); } function setradiator($name,$dif,$koudst=false){ $setpoint=number_format($this->s[$name.'_set'],1)-ceil(number_format($dif,1)*3); if($koudst==true)$setpoint=number_format($this->s[$name.'_set']+3,1); if($setpoint>25)$setpoint=25.0; else if($setpoint<4)$setpoint=4.0; return number_format($setpoint,1); } function telegram($msg,$silent=true,$to='Guy'){ if($to=='Kirby')$telegramchatid=12345678;else $telegramchatid=87654321; file_get_contents('https://api.telegram.org/bot123456789:AAEZ-xCRhO-RBfUqICiJs6q9A_1YIr9irxI/sendMessage',false,stream_context_create(array('http'=>array('method'=>'POST','header'=>"Content-Type:application/x-www-form-urlencoded\r\n",'content'=>http_build_query(array('chat_id'=>$telegramchatid,'text'=>$msg,'disable_notification'=>$silent)),),))); usleep(250000); } function ios($msg){ include ("findmyiphone.php"); $fmi=new FindMyiPhone($this->appleid,$this->applepass); $fmi->playSound($this->appledevice,$msg); usleep(250000); } function sms($msg){ file_get_contents('http://api.clickatell.com/http/sendmsg?user='.$this->smsuser.'&password='.$this->smspassword.'&api_id='.$this->smsapi.'&to='.$this->smstofrom.'&text='.urlencode($msg).'&from='.$this->smstofrom.''); usleep(250000); } function cset($name,$value){ file_put_contents('/volume1/web/logs/'.$name.'.cache',$value); usleep(10000); } function cget($name){ if(file_exists('/volume1/web/logs/'.$name.'.cache')===true)$reply=file_get_contents('/volume1/web/logs/'.$name.'.cache'); else $reply=0; return $reply; } function pingDomain($domain,$port){ $file=fsockopen($domain,$port,$errno,$errstr,3); $status=0; if(!$file) $status=-1; else {fclose($file);$status=1;} return $status; } function RefreshZwave($node,$name='auto',$device=''){ $this->cset('timerefresh-'.$device,$this->time); $devices=json_decode(file_get_contents($this->api.'json.htm?type=openzwavenodes&idx=4'),true); for ($k=1;$k<=5;$k++){ $result=file_get_contents($this->api.'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'){ $this->cset('timerefresh-'.$device,$this->time); break; } sleep(1); } if($this->cget('timedeadnodes')<$this->vijfmin){ $this->cset('timedeadnodes',$this->time); foreach($devices as $node=>$data){ if($node=="result"){ foreach($data as $index=>$eltsNode){ if($eltsNode["State"]=="Dead"&&!in_array($eltsNode['NodeID'],array(31,50,53,55))){ $this->telegram('Node '.$eltsNode['NodeID'].' '.$eltsNode['Description'].' ('.$eltsNode['Name'].') marked as dead, reviving '.$this->ZwaveHasnodefailed($eltsNode['NodeID'])); sleep(3); $this->Zwavecancelaction(); } } } } } } function ZwaveHasnodefailed($node){ for ($k=1;$k<=5;$k++){ sleep(1); $result=file_get_contents($this->api.'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'=>'hnf','node'=>'node'.$node)),),)));if($result=='OK') break;sleep(1); } } function Zwavecancelaction(){ file_get_contents($this->api.'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')),),))); } } class logic extends domoticz { function __construct(){ parent::__construct(); //Maak array om functie op te roepen indien deze idx getriggerd werd $this->events=array(1=>'pirliving', 2=>'poort', 3=>'cron', 4=>'minihall1s', 6=>'cron', 9=>'camvoordeur', 10=>'denon', 12=>'cron', 13=>'cron', 14=>'cron', 15=>'cron', 16=>'cron', 18=>'miniliving1s', 19=>'miniliving2s', 20=>'miniliving3s', 21=>'miniliving4s', 22=>'miniliving1l', 23=>'miniliving2l', 24=>'miniliving3l', 25=>'miniliving4l', 59=>'belknop', 72=>'miniliving1l', 73=>'miniliving1s', 74=>'miniliving2s', 75=>'miniliving3l', 76=>'deurbel', 78=>'werkbladtuin', 87=>'hallzolder', 98=>'lichtbadkamer', 122=>'inkomvoordeur', 141=>'SDliving', 147=>'cron', 148=>'raamliving', 150=>'pirliving', 152=>'pirkeuken', 153=>'pirkeuken', 154=>'pirgarage', 158=>'water', 163=>'garageterras', 172=>'achterdeur', 196=>'SDalex', 205=>'minihall1s', 206=>'minihall2s', 207=>'minihall3s', 208=>'minihall4s', 209=>'minihall1l', 210=>'minihall2l', 211=>'minihall3l', 212=>'minihall4l', 216=>'SDkamer', 225=>'SDbadkamer', 231=>'deurbadkamer', 238=>'SDzolder', 244=>'cron', 246=>'cron', 247=>'pirinkom', 249=>'pirhall', 278=>'cron', 282=>'wasbakkookplaat', 293=>'cron', 308=>'alex', 320=>'keukenzolderg', 330=>'cron', 343=>'camoprit', 350=>'SDtobi', 356=>'cron', 379=>'sirene', 412=>'cron', 437=>'remotewater'); } //$this->a = status van de idx die deze functie opriep //$this->s = array met alle device statussen //$this->t = array met alle last update tijdstippen //$this->i = array met alle idx van de devices function achterdeur(){ if($this->a=="On"){ if(($this->s['weg']=='On'||$this->s['slapen']=='On')&&$this->s['meldingen']=='On'){ if($this->cget('timealertachterdeur')<$this->eenmin){ $this->sw($this->i['sirene'],'On'); $msg='Achterdeur open om '.$this->t['achterdeur']; $this->cset('timealertachterdeur',$this->time); $this->telegram($msg); $this->ios($msg); if($this->sms===true)$this->sms($msg); } } } } function alex(){ if(filter_var($this->a,FILTER_SANITIZE_NUMBER_INT)==20)$this->sl($this->i['alex'],0,'dimmer Alex'); } function belknop(){ if($this->a=="On"&&$this->s['meldingen']=='On'&&$this->s['slapen']=='Off'){ if($this->cget('timetelegramdeurbel')<$this->eenmin){ $this->cset('timetelegramdeurbel',$this->time); if($this->s['weg']=='Off'&&$this->s['slapen']=='Off')$this->sw($this->i['deurbel'],'On','deurbel'); $this->telegram('Deurbel',false); $this->telegram('Deurbel',false,'Kirby'); file_get_contents('http://192.168.0.11/telegram.php?snapshot=true',false,$this->ctx); if($this->s['weg']=='Off'&&$this->s['slapen']=='Off')shell_exec('/volume1/web/secure/picam1.sh &'); } $this->ud($this->i['belknop'],0,'Off','belknop reset'); } } function camvoordeur(){ if($this->s['meldingen']=='On'&&$this->s['slapen']=='Off'){ if($this->cget('timetelegrammotionvoordeur')<$this->tweemin){ $this->cset('timetelegrammotionvoordeur',$this->time); //$this->sw($this->i['deurbel'],'On','beweging voordeur bel'); $this->telegram('Motion Cam Voordeur',false);$this->telegram('Motion Cam Voordeur',false,'Kirby'); if($this->s['weg']=='Off')shell_exec('/volume1/web/secure/picam1.sh'); if($this->s['zon']=0)$this->sw($this->i['voordeur'],'On');}}} function camoprit(){ if($this->s['meldingen']=='On'){ if($this->s['slapen']=='Off'){ if($this->cget('timetelegrammotionoprit')<$this->tweemin){ $this->cset('timetelegrammotionoprit',$this->time); $this->telegram('Motion Cam Oprit',false); $this->telegram('Motion Cam Oprit',false,'Kirby'); if($this->s['weg']=='Off')shell_exec('/volume1/web/secure/picam3.sh'); if($this->s['zon']<100)$this->sw($this->i['voordeur'],'On','voordeur'); } } } } function denon(){ if($this->a=="On"){ $this->sw($this->i['denonpower'],'On','denonpower'); sleep(20); for($x=0;$x<=10;$x++){ sleep(1); $denon=json_decode(json_encode(simplexml_load_string(file_get_contents($this->denon.'/goform/formMainZone_MainZoneXml.xml?_='.time(),false, $this->ctx))), TRUE); if($denon['ZonePower']['value']!='ON') { file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON&cmd1=aspMainZone_WebUpdateStatus%2F',false,$this->ctx); sleep(1); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON&cmd1=aspMainZone_WebUpdateStatus%2F&ZoneName=ZONE2',false,$this->ctx); sleep(1); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_InputFunction/TUNER',false,$this->ctx); } else break; } }else{ file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF&cmd1=aspMainZone_WebUpdateStatus%2F&ZoneName=ZONE2',false,$this->ctx); sleep(1); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF&cmd1=aspMainZone_WebUpdateStatus%2F',false,$this->ctx); sleep(3); $this->sw($this->i['denonpower'],'Off','denonpower'); } } function deurbadkamer(){ if($this->a=="Open"){ if($this->s['slapen']=='Off'||($this->time>strtotime('6:00')&&$this->time<strtotime('12:00'))){if($this->s['lichtbadkamer1']=='Off')$this->sw($this->i['lichtbadkamer1'],'On','lichtbadkamer1');if($this->s['lichtbadkamer2']=='On')$this->sw($this->i['lichtbadkamer2'],'Off','lichtbadkamer2');} else {if($this->s['lichtbadkamer2']=='Off')$this->sw($this->i['lichtbadkamer2'],'On','lichtbadkamer2');if($this->s['lichtbadkamer1']=='On')$this->sw($this->i['lichtbadkamer1'],'Off','lichtbadkamer1');}} call_user_func(array($this,'cron'));} function deurbel(){if($this->a=="On")$this->sw($this->i['deurbel'],'Off','Deurbel reset');} function garageterras(){$this->RefreshZwave(24,'switch','garageterras');} function hallzolder(){$this->RefreshZwave(7,'switch','hallzolder');} function inkomvoordeur(){$this->RefreshZwave(12,'switch','inkomvoordeur');} function keukenzolderg(){$this->RefreshZwave(49,'switch','keukenzolderg');} function lichtbadkamer(){ //if($this->a=="On"){} call_user_func(array($this,'cron')); $this->RefreshZwave(8,'switch','lichtbadkamer'); } function minihall1s(){ if($this->a=="On"){ $items=array('pirkeuken','pirgarage','pirinkom','pirhall'); foreach($items as $item)if($this->s[$item]!='Off')$this->ud($this->i[$item],0,'Off'); $items=array('bureel','denon','tv','tvled','kristal','eettafel','zithoek','garage','terras','tuin','voordeur','keuken','werkblad','wasbak','kookplaat','GroheRed','hall'); foreach($items as $item)if($this->s[$item]!='Off')$this->sw($this->i[$item],'Off',$item); } if($this->s['lichten_auto']=='Off')$this->sw($this->i['lichten_auto'],'On','lichten auto aan'); if($this->s['luifel']!='Open')$this->sw($this->i['luifel'],'Off','zonneluifel dicht'); } function minihall2s(){$this->sw($this->i['zoldertrap'],'Off','zoldertrap open');} function minihall3s(){ if($this->s['slapen']=='On')$this->sw($this->i['slapen'],'Off','slapen'); if($this->s['zon']<600&&$this->s['hall']=='Off')$this->sw($this->i['hall'],'On','hall'); } function minihall4s(){$this->sw($this->i['zoldertrap'],'On');} function minihall1l(){ if($this->s['slapen']=='On')$this->sw($this->i['slapen'],'Off','slapen'); if($this->s['hall']=='Off')$this->sw($this->i['hall'],'On','hall'); if($this->s['lichtbadkamer1']=='Off')$this->sw($this->i['lichtbadkamer1'],'On','lichtbadkamer1'); if($this->s['kamer']!='On')$this->sl($this->i['kamer'],100,'dimmer kamer'); if($this->s['tobi']!='On')$this->sl($this->i['tobi'],100,'dimmer Tobi'); if($this->s['alex']!='On')$this->sl($this->i['alex'],100,'dimmer Alex'); } function minihall2l(){$this->sl($this->i['alex'],2,'Alex');} function minihall3l(){ $items=array('lichtbadkamer1','lichtbadkamer2','kamer','tobi','alex'); foreach($items as $item) if($this->s[$item]!='Off')$this->sw($this->i[$item],'Off',$item);} function minihall4l(){$this->sl($this->i['tobi'],18,'dimmer Tobi');$this->cset('dimmertobi',1);} function miniliving1s(){ if($this->s['denon']=='Off'){$this->sw($this->i['denon'],'On','Denon');usleep(600000);} if($this->s['tv']=='Off')$this->sw($this->i['tv'],'On','TV'); if($this->s['zon']<100){ if($this->s['kristal']=='Off')$this->sw($this->i['kristal'],'On','kristal'); if($this->s['tvled']=='Off')$this->sw($this->i['tvled'],'On','tvled'); } else if($this->s['zon']>300){ if($this->s['kristal']=='On')$this->sw($this->i['kristal'],'Off','kristal'); if($this->s['tvled']=='On')$this->sw($this->i['tvled'],'Off','tvled'); } file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_InputFunction/SAT/CBL',false,$this->ctx);usleep(600000); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/-42.0',false,$this->ctx); if($this->s['subwoofer']=='Off')$this->sw($this->i['subwoofer'],'On','subwoofer'); } function miniliving2s(){ if($this->s['kodi']=='Off')$this->sw($this->i['kodi'],'On','Kodi'); if($this->s['denon']=='Off')$this->sw($this->i['denon'],'On','Denon'); if($this->s['tv']=='Off')$this->sw($this->i['tv'],'On','TV'); if($this->s['zon']<100){ if($this->s['kristal']=='Off')$this->sw($this->i['kristal'],'On','kristal'); if($this->s['tvled']=='Off')$this->sw($this->i['tvled'],'On','tvled'); } else if($this->s['zon']>300){ if($this->s['kristal']=='On')$this->sw($this->i['kristal'],'Off','kristal'); if($this->s['tvled']=='On')$this->sw($this->i['tvled'],'Off','tvled'); } file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_InputFunction/DVD',false,$this->ctx);usleep(600000); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/-30.0',false,$this->ctx); if($this->s['subwoofer']=='Off')$this->sw($this->i['subwoofer'],'On','subwoofer'); } function miniliving3s(){ $denon=json_decode(json_encode(simplexml_load_string(file_get_contents($this->denon.'/goform/formMainZone_MainZoneXml.xml?_='.$this->time,false,$this->ctx))),TRUE); if($denon){ $denon['MasterVolume']['value']=='--'?$setvalue=-55:$setvalue=$denon['MasterVolume']['value']; $setvalue=$setvalue-3; if($setvalue>-10)$setvalue=-10;if($setvalue<-80)$setvalue=-80;$volume=80+$setvalue; usleep(10000);file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/'.$setvalue.'.0',false,$this->ctx);} } function miniliving4s(){ $denon=json_decode(json_encode(simplexml_load_string(file_get_contents($this->denon.'/goform/formMainZone_MainZoneXml.xml?_='.$this->time,false,$this->ctx))),TRUE); if($denon){ $denon['MasterVolume']['value']=='--'?$setvalue=-55:$setvalue=$denon['MasterVolume']['value']; $setvalue=$setvalue+3; if($setvalue>-10)$setvalue=-10;if($setvalue<-80)$setvalue=-80;$volume=80+$setvalue; usleep(10000);file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/'.$setvalue.'.0',false,$this->ctx);} } function miniliving1l(){ if($this->s['denon']=='Off'){$this->sw($this->i['denon'],'On','Denon');usleep(600000);} if($this->s['tv']=='On')$this->sw($this->i['tv'],'Off','TV'); if($this->s['zon']>0){ if($this->s['kristal']=='On')$this->sw($this->i['kristal'],'Off','Kristal'); if($this->s['tvled']=='On')$this->sw($this->i['tvled'],'Off','tvled'); } file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/-50.0',false,$this->ctx);usleep(600000); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_InputFunction/TUNER',false,$this->ctx); if($this->s['subwoofer']=='Off')$this->sw($this->i['subwoofer'],'On','subwoofer'); } function miniliving2l(){$this->sw($this->i['bureel'],'Toggle','Bureel');} function miniliving3l(){ $this->sl($this->i['eettafel'],9,'dimmer eettafel'); if($this->s['tv']=='On')$this->sw($this->i['tv'],'Off','TV'); if($this->s['kristal']=='On')$this->sw($this->i['kristal'],'Off','kristal'); if($this->s['tvled']=='On')$this->sw($this->i['tvled'],'Off','tvled'); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON&cmd1=aspMainZone_WebUpdateStatus%2F',false,$this->ctx);usleep(600000); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/-55.0',false,$this->ctx);usleep(600000); file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_InputFunction/TUNER',false,$this->ctx); if($this->s['subwoofer']=='Off')$this->sw($this->i['subwoofer'],'On','subwoofer'); } function miniliving4l(){ $items=array('pirkeuken','pirgarage','pirinkom','pirhall'); foreach($items as $item) if($this->s[$item]!='Off')$this->ud($this->i[$item],0,'Off',$item); $items=array('eettafel','zithoek','garage','inkom','hall','keuken','werkblad','wasbak','kookplaat'); foreach($items as $item) if($this->s[$item]!='Off')$this->sw($this->i[$item],'Off',$item); } function pirgarage(){ if($this->a=="On"&&($this->time<$this->achtochtend||$this->s['zon']<1200)&&$this->s['garage']=='Off')$this->sw($this->i['garage'],'On','garage'); if(($this->s['weg']=='On'||$this->s['slapen']=='On')&&$this->s['meldingen']=='On'&&strtotime($this->t['weg'])<$this->driemin&&strtotime($this->t['slapen'])<$this->driemin){ if($this->cget('timealertpirgarage')<$this->eenmin){ $this->sw($this->i['sirene'],'On'); $msg='Beweging garage om '.strftime("%H:%M:%S",$this->time); $this->cset('timealertpirgarage',$this->time); $this->telegram($msg,false); $this->ios($msg); if($this->sms===true)$this->sms($msg); } } } function pirhall(){ if($this->a=="On"){ if($this->s['slapen']=='Off'&&$this->s['hall']=='Off'&&($this->time<$this->achtochtend||$this->s['zon']<100))$this->sw($this->i['hall'],'On','hal'); if($this->s['inkom']=='Off'&&($this->time<$this->achtochtend||$this->s['zon']<200))$this->sw($this->i['inkom'],'On','inkom'); if($this->s['weg']=='On'&&$this->s['meldingen']=='On'&&strtotime($this->t['weg'])<$this->driemin){ if($this->cget('timealertpirhall')<$this->eenmin){ $this->sw($this->i['sirene'],'On','SIRENE'); $msg='Beweging hall om '.strftime("%H:%M:%S",$this->time); $this->cset('timealertpirhall',$his->time); $this->telegram($msg,false); $this->ios($msg); if($this->sms===true)$this->sms($msg); } } } } function pirinkom(){ if($this->a=="On"){ if($this->s['inkom']=='Off'&&($this->time<$this->achtochtend||$this->s['zon']<100))$this->sw($this->i['inkom'],'On','inkom'); if($this->s['slapen']=='Off'&&$this->s['hall']=='Off'&&($this->time<$this->achtochtend||$this->s['zon']<150))$this->sw($this->i['hall'],'On','hall'); if(($this->s['weg']=='On'||$this->s['slapen']=='On')&&$this->s['meldingen']=='On'&&strtotime($this->t['weg'])<$this->driemin&&strtotime($this->t['slapen'])<$this->driemin){ if($this->cget('timealertpirinkom')<$this->eenmin){ $this->sw($this->i['sirene'],'On','SIRENE'); $msg='Beweging inkom om '.strftime("%H:%M:%S",$this->time); $this->cset('timealertpirinkom',$this->time); $this->telegram($msg,false); $this->ios($msg); if($this->sms===true)$this->sms($msg); } } } } function pirkeuken(){ if($this->a=="On"){ if($this->s['keuken']=='Off'&&$this->s['wasbak']=='Off'&&$this->s['werkblad']=='Off'&&$this->s['kookplaat']=='Off'&&$this->s['zon']<400)$this->sw($this->i['wasbak'],'On','wasbak'); if(($this->s['weg']=='On'||$this->s['slapen']=='On')&&$this->s['meldingen']=='On'&&strtotime($this->t['weg'])<$this->driemin&&strtotime($this->t['slapen'])<$this->driemin){ if($this->cget('timealertpirkeuken')<$this->eenmin){ $this->sw($this->i['sirene'],'On','SIRENE'); $msg='Beweging keuken om '.strftime("%H:%M:%S",$this->time); $this->cset('timealertpirkeuken',$this->time); $this->telegram($msg,false); $this->ios($msg);if($this->sms===true)$this->sms($msg); } } } } function pirliving(){if($this->a=="On"){ if($this->s['denon']=='Off'&&$this->s['weg']=='Off'&$this->s['slapen']=='Off'){ if($this->s['zon']<100){ if($this->s['wasbak']=='Off')$this->sw($this->i['wasbak'],'On','wasbak'); if($this->s['bureel']=='Off')$this->sw($this->i['bureel'],'On','bureel'); } call_user_func(array($this,'miniliving1l')); } if(($this->s['weg']=='On'||$this->s['slapen']=='On')&&$this->s['meldingen']=='On'&&strtotime($this->t['weg'])<$this->driemin&&strtotime($this->t['slapen'])<$this->driemin){ if($this->cget('timealertpirliving')<$this->eenmin){ $this->sw($this->i['sirene'],'On','SIRENE'); $msg='Beweging living om '.strftime("%H:%M:%S",$this->time); $this->cset('timealertpirliving',$this->time); $this->telegram($msg,false);$this->ios($msg);if($this->sms===true)$this->sms($msg); } } }} function poort(){ if($this->a=="On"){ if($this->s['zon']<600&&$this->s['garage']=='Off')$this->sw($this->i['garage'],'On','garage'); if(($this->s['weg']=='On'||$this->s['slapen']=='On')&&$this->s['meldingen']=='On'&&strtotime($this->t['weg'])<$this->driemin){ if($this->cget('timealertpoort')<$this->eenmin){ $this->sw($this->i['sirene'],'On','SIRENE'); $msg='Poort open om '.$this->t['poort']; $this->cset('timealertpoort',$this->time); $this->telegram($msg,false); $this->ios($msg); if($this->sms===true)$this->sms($msg); } } } } function raamliving(){ if($this->a=="On"){ if(($this->s['weg']=='On'||$this->s['slapen']=='On')&&$this->s['meldingen']=='On'){ if($this->cget('timealertraamliving')<$this->eenmin){ $this->sw($this->i['sirene'],'On','SIRENE'); $msg='Raam living open om '.$this->t['raamliving']; $this->cset('timealertraamliving',$this->time); $this->telegram($msg); $this->ios($msg); if($this->sms===true)$this->sms($msg); } } } } function SDalex(){if($this->a=="On"){$msg='Rook gedecteerd bij Alex!';$this->telegram($msg,false);$this->telegram($msg,false,'Kirby');$this->ios($msg);if($this->sms===true)$this->sms($msg);$this->resetsecurity($this->i['SDalex'],'Alex');}} function SDbadkamer(){if($this->a=="On"){$msg='Rook gedecteerd in badkamer!';$this->telegram($msg,false);$this->telegram($msg,false,'Kirby');$this->ios($msg);if($this->sms===true)$this->sms($msg);$this->resetsecurity($this->i['SDbadkamer'],'Badkamer');}} function SDkamer(){if($this->a=="On"){$msg='Rook gedecteerd in slaapkamer!';$this->telegram($msg,false);$this->telegram($msg,false,'Kirby');$this->ios($msg);if($this->sms===true)$this->sms($msg);$this->resetsecurity($this->i['SDkamer'],'Slaapkamer');}} function SDliving(){if($this->a=="On"){$msg='Rook gedecteerd in living!';$this->telegram($msg,false);$this->telegram($msg,false,'Kirby');$this->ios($msg);if($this->sms===true)$this->sms($msg);$this->resetsecurity($this->i['SDliving'],'Living');}} function SDtobi(){if($this->a=="On"){$msg='Rook gedecteerd bij Tobi!';$this->telegram($msg,false);$this->telegram($msg,false,'Kirby');$this->ios($msg);if($this->sms===true)$this->sms($msg);$this->resetsecurity($this->i['SDtobi'],'Tobi');}} function SDzolder(){if($this->a=="On"){$msg='Rook gedecteerd op zolder!';$this->telegram($msg,false);$this->telegram($msg,false,'Kirby');$this->ios($msg);if($this->sms===true)$this->sms($msg);$this->resetsecurity($this->i['SDzolder'],'Zolder');}} function remotewater(){if($this->a=="On")$this->sw($this->i['water'],'On','water aan');else $this->sw($this->i['water'],'Off','water uit');} function sirene(){if($this->a=="On"){$this->sw($this->i['deurbel'],'On','Deurbel sirene');sleep(2);$this->sw($this->i['sirene'],'Off','sirene');}} function wasbakkookplaat(){$this->RefreshZwave(61,'switch','wasbakkookplaat');} function water(){ if($this->a=="On"){ sleep($this->cget('water')); $this->sw($this->i['water'],'Off','water'); }else $this->cset('water',4); } /* ============== CRON ACTIVATED EVERY MINUTE BY SOLAR PANELS ================ */function cron(){print $this->stamp." === CRON === ";$Tbuiten=explode(";",$this->s['buiten_temp']);$Tbuiten=$Tbuiten[0];$buien=$this->s['buienradar']; //===== Sleep dimmers ===== $items=array('eettafel','zithoek','tobi','kamer','alex'); foreach($items as $item){if($this->s[$item]!='Off'){if(strtotime($this->t[$item]) < $this->dertigsec){$action=$this->cget('dimmer'.$item); if($action==1){$level=filter_var($this->s[$item],FILTER_SANITIZE_NUMBER_INT);$level=floor($level*0.95);if($level<2) $level=0;if($level==20) $level=19;$this->sl($this->i[$item],$level,$item);if($level==0)$this->cset('dimmer'.$item,0); } else if($action == 2){$level=filter_var($this->s[$item],FILTER_SANITIZE_NUMBER_INT);$level=$level+2;if($level==20) $level=21;if($level>30) $level=30;$this->sl($this->i[$item],$level,$item);if($level==30)$this->cset('dimmer'.$item,0);}}}} //===== VERWARMING ===== if($this->s['weg']=='On'){if($this->s['heating']!='Off'&&strtotime($this->t['heating'])<$this->eenuur){$this->sw($this->i['heating'],'Off','heating');$this->s['heating']='Off';}} //else {if($this->s['heating']!='On'){$this->sw($this->i['heating'],'On','heating');$this->s['heating']='On';}} $Setkamer=8.0;$setpointkamer=$this->cget('setpointkamer'); if($setpointkamer!=0&&strtotime($this->t['kamer_set'])<$this->eenuur){$this->cset('setpointkamer',0);$setpointkamer=0;} if($setpointkamer!=2){ if($Tbuiten<15&&$this->s['raamkamer']=='Closed'&&$this->s['heating']=='On'&&(strtotime($this->t['raamkamer'])<$this->tweeuur||$this->time>$this->achtavond)){ $Setkamer=12.0;if($this->time<$this->zevenochtend||$this->time>$this->achtavond)$Setkamer=16.0; } $Setkamer=number_format($Setkamer,1);if($this->s['kamer_set']!=$Setkamer){$this->ud($this->i['kamer_set'],0,$Setkamer,'Rkamer_set');$this->s['kamer_set']=$Setkamer;} } $Settobi=8.0;$setpointtobi=$this->cget('setpointtobi'); if($setpointtobi!=0&&strtotime($this->t['tobi_set'])<$this->eenuur){$this->cset('setpointtobi',0);$setpointtobi=0;} if($setpointtobi!=2){ if($Tbuiten<15&&$this->s['raamtobi']=='Closed'&&$this->s['heating']=='On'&&(strtotime($this->t['raamtobi'])<$this->tweeuur||$this->time>$this->achtavond)){ $Settobi=12.0; if(date('W')%2==1){ if(date('N')==3){if($this->time>$this->achtavond)$Settobi=16.0;} else if(date('N')==4){if($this->time<$this->zevenochtend||$this->time>$this->achtavond)$Settobi=16.0;} else if(date('N')==5){if($this->time<$this->zevenochtend)$Settobi=16.0;} } else { if(date('N')==3){if($this->time>$this->achtavond) $Settobi=16.0;} else if(in_array(date('N'),array(4,5,6))){if($this->time<$this->zevenochtend||$this->time>$this->achtavond)$Settobi=16.0;} else if(date('N')==7){if($this->time<$this->zevenochtend)$Settobi=16.0;} } } $Settobi=number_format($Settobi,1);if($this->s['tobi_set']!=$Settobi){$this->ud($this->i['tobi_set'],0,$Settobi,'Rtobi_set');$this->s['tobi_set']=$Settobi;} } $Setalex=8.0;$setpointalex=$this->cget('setpointalex'); if($setpointalex!=0&&strtotime($this->t['alex_set'])<$this->achtuur){$this->cset('setpointalex',0);$setpointalex=0;} if($setpointalex!=2){ if(number_format($Tbuiten,1)<17&&$this->s['raamalex']=='Closed'&&$this->s['heating']=='On'&&(strtotime($this->t['raamalex'])<$this->tweeuur||$this->time>$this->achtavond)){ $Setalex=12.0;if($this->time<strtotime('8:00')||$this->time>$this->achtavond)$Setalex=18.5; } $Setalex=number_format($Setalex,1); if($this->s['alex_set'] != $Setalex){$this->ud($this->i['alex_set'],0,$Setalex,'Ralex_set');$this->s['alex_set']=$Setalex;} } $Setliving=14.0;$setpointliving=$this->cget('setpointliving'); if($setpointliving!=0&&strtotime($this->t['living_set'])<$this->drieuur){$this->cset('setpointliving',0);$setpointliving=0;} if($setpointliving!=2){ if($Tbuiten<20&&$this->s['heating']=='On'&&$this->s['raamliving']=='Closed'){$Setliving=17.0; if($this->time>=strtotime('3:00')&&$this->time<$this->zevenochtend)$this->s['slapen']=='Off'?$Setliving=20.5:$Setliving=17.0; else if($this->time>=$this->zevenochtend&&$this->time<strtotime('22:30'))$this->s['slapen']=='Off'?$Setliving=20.5:$Setliving=17.0; } $Setliving=number_format($Setliving,1); if($this->s['living_set']!= $Setliving){$this->ud($this->i['living_set'],0,$Setliving,'Rliving_set');$this->s['living_set']=$Setliving;} } if($this->s['deurbadkamer']=="Open") { if($this->s['badkamer_set']!=10&&strtotime($this->t['deurbadkamer'])<$this->eenmin){ $this->ud($this->i['badkamer_set'],0,10,'badkamer_set 10 deur open'); $this->s['badkamer_set']=10; } }else if($this->s['deurbadkamer']=="Closed"){ if($this->s['lichtbadkamer']=='On'&&$this->s['badkamer_set']!=22){ $this->ud($this->i['badkamer_set'],0,22,'badkamer_set 22 deur dicht en licht aan'); $this->s['badkamer_set']=22; }else if($this->s['lichtbadkamer']=='Off'&&$this->s['badkamer_set']!=15){ $this->ud($this->i['badkamer_set'],0,15,'badkamer_set 15 deur dicht en licht uit'); $this->s['badkamer_set']=15; } } $kamers=array('living','badkamer','tobi','alex','kamer'); $kamersgas=array('living','alex'); $bigdif=100;$brander=$this->s['brander'];$Tbrander=strtotime($this->t['brander']);$Ibrander=$this->i['brander']; foreach($kamers as $kamer){${'dif'.$kamer}=number_format($this->s[$kamer.'_temp']-$this->s[$kamer.'_set'],1);if(in_array($kamer,$kamersgas))if(${'dif'.$kamer}<$bigdif)$bigdif=${'dif'.$kamer};${'Set'.$kamer}=number_format($this->s[$kamer.'_set'],1);} foreach($kamers as $kamer){if(${'dif'.$kamer}<=number_format(($bigdif+ 0.2),1)&&${'dif'.$kamer}<1)${'RSet'.$kamer}=$this->setradiator($kamer,${'dif'.$kamer},true);else ${'RSet'.$kamer}=$this->setradiator($kamer,${'dif'.$kamer},false);} if(number_format($this->s['kamerZ'],1)!==number_format($RSetkamer,1)){$this->ud($this->i['kamerZ'],0,number_format($RSetkamer,1),'RkamerZ');} if(number_format($this->s['tobiZ'],1)!==number_format($RSettobi,1)){$this->ud($this->i['tobiZ'],0,number_format($RSettobi,1),'RtobiZ');} if(number_format($this->s['alexZ'],1)!==number_format($RSetalex,1)){$this->ud($this->i['alexZ'],0,number_format($RSetalex,1),'RalexZ');} //if(number_format($this->s['badkamerZ'],1)!==number_format($RSetbadkamer,1)){$this->ud($this->i['badkamerZ'],0,number_format($RSetbadkamer,1),'RbadkamerZ');} if(number_format($this->s['livingZ'],1)!==number_format($RSetliving,1)){$this->ud($this->i['livingZ'],0,number_format($RSetliving,1),'RlivingZ');} if(number_format($this->s['livingZZ'],1)!==number_format($RSetliving,1)){$this->ud($this->i['livingZZ'],0,number_format($RSetliving,1),'RlivingZZ');} if(number_format($this->s['livingZE'],1)!==number_format($RSetliving,1)){$this->ud($this->i['livingZE'],0,number_format($RSetliving,1),'RlivingZE');} if(strtotime($this->t['tobi_set'])<$this->eendag)$this->ud($this->i['tobi_set'],0,$this->s['tobi_set'],'Update tobi'); if(strtotime($this->t['living_set'])<$this->eendag)$this->ud($this->i['living_set'],0,$this->s['living_set'],'Update living'); if(strtotime($this->t['kamer_set'])<$this->eendag)$this->ud($this->i['kamer_set'],0,$this->s['kamer_set'],'Update kamer'); if(strtotime($this->t['alex_set'])<$this->eendag)$this->ud($this->i['alex_set'],0,$this->s['alex_set'],'Update alex'); if($bigdif<=-0.3&&$brander=="Off"&& $Tbrander<$this->time-60)$this->sw($Ibrander,'On','brander dif = '.$bigdif); else if($bigdif<=-0.2&&$brander=="Off"&& $Tbrander<$this->time-120)$this->sw($Ibrander,'On','brander dif = '.$bigdif); else if($bigdif<=-0.1&&$brander=="Off"&& $Tbrander<$this->time-180)$this->sw($Ibrander,'On','brander dif = '.$bigdif); else if($bigdif<=0&&$brander=="Off"&& $Tbrander<$this->time-240)$this->sw($Ibrander,'On','brander dif = '.$bigdif); else if($bigdif>=0.1&&$brander=="On"&& $Tbrander<$this->time)$this->sw($Ibrander,'Off','brander dif = '.$bigdif); else if($bigdif>=0&&$brander=="On"&& $Tbrander<$this->time-60)$this->sw($Ibrander,'Off','brander dif = '.$bigdif); else if($bigdif>=-0.1&&$brander=="On"&& $Tbrander<$this->time-120)$this->sw($Ibrander,'Off','brander dif = '.$bigdif); else if($bigdif>=-0.2&&$brander=="On"&& $Tbrander<$this->time-180)$this->sw($Ibrander,'Off','brander dif = '.$bigdif); else if($bigdif>=-0.3&&$brander=="On"&& $Tbrander<$this->time-240)$this->sw($Ibrander,'Off','brander dif = '.$bigdif); $badkvuur=$this->s['badkamervuur'];$Tbadkvuur=strtotime($this->t['badkamervuur']);$Ibadkvuur=$this->i['badkamervuur']; if($difbadkamer<=-0.2&&$badkvuur=="Off"&&$Tbadkvuur<$this->time-180)$this->sw($Ibadkvuur,'On','badkamervuur dif = '.$difbadkamer); else if($difbadkamer<=-0.1&&$badkvuur=="Off"&&$Tbadkvuur<$this->time-240)$this->sw($Ibadkvuur,'On','badkamervuur dif = '.$difbadkamer); else if($difbadkamer<=0&&$badkvuur=="Off"&&$Tbadkvuur<$this->time-360)$this->sw($Ibadkvuur,'On','badkamervuur dif = '.$difbadkamer); else if($difbadkamer>=0.1&&$badkvuur=="On"&&$Tbadkvuur<$this->time)$this->sw($Ibadkvuur,'Off','badkamervuur dif = '.$difbadkamer); else if($difbadkamer>=0&&$badkvuur=="On"&&$Tbadkvuur<$this->time-45)$this->sw($Ibadkvuur,'Off','badkamervuur dif = '.$difbadkamer); else if($difbadkamer>=-0.1&&$badkvuur=="On"&&$Tbadkvuur<$this->time-90)$this->sw($Ibadkvuur,'Off','badkamervuur dif = '.$difbadkamer); else if($difbadkamer>=-0.3&&$badkvuur=="On"&&$Tbadkvuur<$this->time-150)$this->sw($Ibadkvuur,'Off','badkamervuur dif = '.$difbadkamer); //Temperatuurcheck if($this->s['meldingen']=='On'){$items=array('living_temp','badkamer_temp','kamer_temp','tobi_temp','alex_temp','zolder_temp');$avg=0; foreach($items as $item)$avg=$avg+$this->s[$item];$avg=$avg/6; foreach($items as $item){$temp=$this->s[$item];if($temp>$avg + 5&&$temp>25){$msg='T '.$item.'='.$temp.'°C. AVG='.round($avg,1).'°C';if($this->cget('timealerttemp'.$item)<$this->eenuur){$this->telegram($msg,false);$this->telegram($msg,false,'Kirby');$this->ios($msg);if($this->sms===true)$this->sms($msg);$this->cset('timealerttemp'.$item,$this->time);}}if(strtotime($this->t[$item])<$this->vieruur){if($this->cget('timealerttempupd'.$item)<$this->twaalfuur){$this->telegram($item.' not updated');$this->cset('timealerttempupd'.$item,$this->time);}}}} /* ==== Zonneluifel ==== */ $wind=explode(";",$this->s['Wind']); if($this->s['luifel']!='Closed'&&($wind[2]>83||$wind[3]>83||$buien>10||$this->s['zon']==0)){ print $this->stamp.' --- Luifel: Wind='.$wind[2].'|Gust='.$wind[3].'|Buien='.round($buien,0).'|Zon='.$this->s['zon'].'|Luifel='.$this->s['luifel'].'|Last='.$this->t['luifel'].' '; if($wind[2]>83){$msg='Luifel dicht, wind '.$wind[2]/10 .'m/s';$this->sw($this->i['luifel'],'Off',$msg);$this->telegram($msg); if(strtotime($this->t['luifel'])<$this->eenuur)$this-sw($this->i['luifel'],'Off',$msg.' repeat'); } else if($wind[3]>83){$msg='Luifel dicht, gust '.$wind[2]/10 .'m/s'; $this->sw($this->i['luifel'],'Off',$msg);$this->telegram($msg); if(strtotime($this->t['luifel'])<$this->eenuur)$this-sw($this->i['luifel'],'Off',$msg.' repeat'); } else if($buien>25){$msg='Luifel dicht, '.round($buien,0) .'% regen voorspeld'; $this->sw($this->i['luifel'],'Off',$msg);$this->telegram($msg); if(strtotime($this->t['luifel'])<$this->eenuur)$this-sw($this->i['luifel'],'Off',$msg.' repeat'); } else if($this->s['zon']==0){ $msg='Luifel dicht, geen zon meer'; $this->sw($this->i['luifel'],'Off',$msg);$this->telegram($msg); if(strtotime($this->t['luifel'])<$this->eenuur)$this-sw($this->i['luifel'],'Off',$msg.' repeat'); } } else if($this->s['luifel']=='Closed'&&$this->time>strtotime('10:25')&&$wind[2]<83&&$wind[3]<83&&$buien<25&&$this->s['living_temp']>20&&$this->s['zon']>1200&&strtotime($this->t['luifel'])<$this->tienmin){ print $this->stamp.' --- Luifel: Wind='.$wind[2].'|Gust='.$wind[3].'|Buien='.round($buien,0).'|Zon='.$this->s['zon'].'|Luifel='.$this->s['luifel'].'|Last='.$this->t['luifel'].' '; $msg='Luifel open';$this->sw($this->i['luifel'],'On',$msg);$this->telegram($msg); if(strtotime($this->t['luifel'])<$this->eenuur)$this-sw($this->i['luifel'],'On',$msg.' repeat'); } /* === 1 keer per minuut === */ if($this->cget('time-cron')<$this->eenmin){$this->cset('time-cron',$this->time); //Check last updatetime and alert $devices=array('tobiZ','alexZ','livingZ','livingZZ','livingZE','kamerZ'); foreach($devices as $device){if(strtotime($this->t[$device])<$this->vieruur){if($this->cget('timealert'.$device)<$twaalfuur){$this->telegram($device.' geen communicatie');$this->cset('timealert'.$device,$this->time);}}} //KODI if($this->s['kodi']=='On'&&strtotime($this->t['kodi'])<$this->vijfmin){$status=$this->pingDomain('192.168.0.7',1597);if($status!=1){$this->cset('timekodi',$this->time);sleep(10);$status2=$this->pingDomain('192.168.0.7',1597);if($status2!=1)$this->sw($this->i['kodi'],'Off','kodi');}} //Ramen open/dicht. if($this->s['weg']=='Off'&&$this->s['slapen']=='Off'){ if(($Tbuiten>$this->s['kamer_temp']&&$Tbuiten>$this->s['tobi_temp']&&$Tbuiten>$this->s['alex_temp'])&&$Tbuiten>19&&($this->s['kamer_temp']>19||$this->s['tobi_temp']>19||$this->s['alex_temp']>19)&&($this->s['raamkamer']=='Open'||$this->s['raamtobi']=='Open'||$this->s['raamalex']=='Open')) if($this->cget('timeramen')<$this->tweeuur){$this->telegram('Ramen boven dicht doen, te warm buiten',false);$this->telegram('Ramen boven dicht doen, te warm buiten',false,'Kirby');$this->cset('timeramen',$this->time);} else if(($Tbuiten<=$this->s['kamer_temp']||$Tbuiten<=$this->s['tobi_temp']||$Tbuiten<=$this->s['alex_temp'])&&($this->s['kamer_temp']>20||$this->s['tobi_temp']>20||$this->s['alex_temp']>20)&&($this->s['raamkamer']=='Closed'||$this->s['raamkamer']=='Closed'||$this->s['raamkamer']=='Closed')) if($this->cget('timeramen')<$this->tweeuur){$this->telegram('Ramen boven open doen, te warm binnen',false);$this->telegram('Ramen boven open doen, te warm binnen',false,'Kirby');$this->cset('timeramen',$this->time);} } //REGENPOMP $regenpomp=$this->s['regenpomp'];$Tregenpomp=strtotime($this->t['regenpomp']); if($buien>0)$pomppauze = 14400/$buien;else $pomppauze=14400; if($regenpomp=='On'&&$Tregenpomp<$this->eenmin)$this->sw($this->i['regenpomp'],'Off','regenpomp'); else if($regenpomp=='Off'&&$Tregenpomp<$this->time-$pomppauze)$this->sw($this->i['regenpomp'],'On','regenpomp'); //Fan vestiaire if($this->s['living_temp']>21&&$this->s['living_temp']>$Tbuiten&&$this->s['fanvestiaire']=='Off'&&strtotime($this->t['fanvestiaire'])<$this->eenuur)$this->sw($this->i['fanvestiaire'],'On','Fan Vestiaire'); else if(($this->s['living_temp']<$Tbuiten||$this->s['living_temp']<=21)&&$this->s['fanvestiaire']=='On'&&strtotime($this->t['fanvestiaire'])<$this->eenuur)$this->sw($this->i['fanvestiaire'],'Off','Fan Vestiaire'); if($this->s['pirlivingR']!='Off'&&strtotime($this->t['pirlivingR'])<$this->eenmin)$this->sw($this->i['pirlivingR'],'Off','Reset pirlivingR'); if($this->s['pirgarage']=='Off'&&$this->s['poort']=='Closed'&&strtotime($this->t['pirgarage'])<$this->driemin&&strtotime($this->t['poort'])<$this->driemin&&strtotime($this->t['garage'])<$this->eenmin&&$this->s['garage']=='On'&&$this->s['lichten_auto']=='On')$this->sw($this->i['garage'],'Off','licht garage'); if(strtotime($this->t['pirinkom'])<$this->tweemin&&strtotime($this->t['pirhall'])<$this->tweemin&&strtotime($this->t['inkom'])<$this->tweemin&&strtotime($this->t['hall'])<$this->tweemin&&$this->s['lichten_auto']=='On'){if($this->s['inkom']=='On')$this->sw($this->i['inkom'],'Off','licht inkom');if($this->s['hall']=='On')$this->sw($this->i['hall'],'Off','licht hall');} if(strtotime($this->t['pirkeuken'])<$this->tweemin&&strtotime($this->t['wasbak'])<$this->tweemin&&$this->s['pirkeuken']=='Off'&&$this->s['wasbak']=='On'&&$this->s['werkblad']=='Off'&&$this->s['keuken']=='Off'&&$this->s['kookplaat']=='Off')$this->sw($this->i['wasbak'],'Off','wasbak pir keuken'); if($this->s['voordeur']=='On'&&strtotime($this->t['voordeur'])<$this->tienmin)$this->sw($this->i['voordeur'],'Off','Voordeur uit'); if($this->s['lichten_auto']=='Off') if(strtotime($this->t['lichten_auto'])<$this->drieuur)$this->sw($this->i['lichten_auto'],'Off','lichten_auto aan'); //meldingen inschakelen indien langer dan 3 uur uit. if($this->s['meldingen']=='Off'&&strtotime($this->t['meldingen'])<$this->drieuur)$this->sw($this->i['meldingen'],'On','meldingen'); //slapen-weg bij geen beweging if(strtotime($this->t['pirliving'])<$this->vieruur&&strtotime($this->t['pirlivingR'])<$this->vieruur&&strtotime($this->t['pirgarage'])<$this->vieruur&&strtotime($this->t['pirinkom'])<$this->vieruur&&strtotime($this->t['pirhall'])<$this->vieruur&&strtotime($this->t['slapen'])<$this->vieruur&&strtotime($this->t['weg'])<$this->vieruur&&$this->s['weg']=='Off'&&$this->s['slapen']=="Off"){$this->sw($this->i['slapen'],'On','slapen');$this->telegram('slapen ingeschakeld na 4 uur geen beweging');} if(strtotime($this->t['pirliving'])<$this->twaalfuur&&strtotime($this->t['pirlivingR'])<$this->twaalfuur&&strtotime($this->t['pirgarage'])<$this->twaalfuur&&strtotime($this->t['pirinkom'])<$this->twaalfuur&&strtotime($this->t['pirhall'])<$this->twaalfuur&&strtotime($this->t['slapen'])<$this->twaalfuur&&strtotime($this->t['weg'])<$this->twaalfuur&&$this->s['weg']=='Off'&&$this->s['slapen']=="On"){$this->sw($this->i['slapen'],'Off','slapen');$this->sw($this->i['weg'],'On','weg');$this->telegram('weg ingeschakeld na 12 uur geen beweging');} if($this->s['buienradar']==0&&$this->s['regenpomp']=='On')$this->sw($this->i['regenpomp'],'Off','regenpomp'); //Pomp - Verwarming zwembad uitschakelen if($this->s['zwembadfilter']=='On'){if(strtotime($this->t['zwembadfilter'])<$this->vieruur&&$this->time>strtotime("18:00")&&$this->s['zwembadwarmte']=='Off')$this->sw($this->i['zwembadfilter'],'Off','zwembadfilter');} else {if(strtotime($this->t['zwembadfilter'])<$this->vieruur&&$this->time>strtotime("12:00")&&$this->time<strtotime("16:00"))$this->sw($this->i['zwembadfilter'],'On','zwembadfilter');} if($this->s['zwembadwarmte']=='On'){if(strtotime($this->t['zwembadwarmte'])<$this->eendag)$this->sw($this->i['zwembadwartme'],'Off','warmtepomp zwembad');if($this->s['zwembadfilter']=='Off')$this->sw($this->i['zwembadfilter'],'On','zwembadfilter');} //Alles uitschakelen if($this->s['weg']=='On'||$this->s['slapen']=='On'){if(strtotime($this->t['weg'])>$this->eenmin||strtotime($this->t['slapen'])>$this->eenmin) $uit=$this->eenmin; else $uit=$this->tienmin; $items=array('denon','bureel','tv','tvled','kristal','eettafel','zithoek','garage','terras','tuin','voordeur','keuken','werkblad','wasbak','kookplaat');foreach($items as $item) if($this->s[$item]!='Off'&&strtotime($this->t[$item])<$uit)$this->sw($this->i[$item],'Off',$item); $items=array('lichtbadkame1','lichtbadkamer2','badkamervuur');foreach($items as $item) if($this->s[$item]!='Off'&&strtotime($this->t[$item])<$this->halfuur)$this->sw($this->i[$item],'Off',$item); $items=array('living','badkamer','kamer','tobi','alex');foreach ($items as $item){${'setpoint'.$item}=$this->cget('setpoint'.$item);if(${'setpoint'.$item}!=0&&strtotime($this->t[$item])<$this->eenuur)$this->cset('setpoint'.$item,0);} if($this->s['weg']=='On'){$items=array('lichtbadkamer1','lichtbadkamer2','kamer','tobi','alex');foreach($items as $item) if($this->s[$item]!='Off'&&strtotime($this->t[$item])<$uit)$this->sw($this->i[$item],'Off',$item);} } else { if($this->s['GroheRed']=='Off')$this->sw($this->i['GroheRed'],'On','GroheRed'); } //Schakelingen herhalen $items=array('brander','badkamervuur');foreach($items as $item) if($this->s[$item]!='Off'&&strtotime($this->t[$item])<$this->eenuur)$this->sw($this->i[$item],$this->s[$item],$item); //Service online checks $devcheck='PiCam1 Voordeur';if($this->pingDomain('192.168.0.11',80)==1){$prevcheck=$this->cget('check'.$devcheck);if($prevcheck>=4)$this->telegram($devcheck.' online');if($prevcheck>0)$this->cset('check'.$devcheck,0);}else {$check=$this->cget('check'.$devcheck) + 1;if($check>0)$this->cset('check'.$devcheck,$check);if($check==4)$this->telegram($devcheck.' Offline');if($check%100==0)$this->telegram($devcheck.' nog steeds Offline');} $devcheck='PiCam2 Alex';if($this->pingDomain('192.168.0.12',80)==1){$prevcheck=$this->cget('check'.$devcheck);if($prevcheck>=4)$this->telegram($devcheck.' online');if($prevcheck>0)$this->cset('check'.$devcheck,0);}else {$check=$this->cget('check'.$devcheck) + 1;if($check>0)$this->cset('check'.$devcheck,$check);if($check==4)$this->telegram($devcheck.' Offline');if($check%100==0)$this->telegram($devcheck.' nog steeds Offline');} $devcheck='PiHole DNS';if($this->pingDomain('192.168.0.2',53)==1){$prevcheck=$this->cget('check'.$devcheck);if($prevcheck>=4)$this->telegram($devcheck.' online');if($prevcheck>0)$this->cset('check'.$devcheck,0);}else {$check=$this->cget('check'.$devcheck) + 1;if($check>0)$this->cset('check'.$devcheck,$check);if($check==4)$this->telegram($devcheck.' Offline');if($check%100==0)$this->telegram($devcheck.' nog steeds Offline');} $devcheck='PiHole WWW';if($this->pingDomain('192.168.0.2',80)==1){$prevcheck=$this->cget('check'.$devcheck);if($prevcheck>=4)$this->telegram($devcheck.' online');if($prevcheck>0)$this->cset('check'.$devcheck,0);}else {$check=$this->cget('check'.$devcheck) + 1;if($check>0) cset('check'.$devcheck,$check);if($check==4)$this->telegram($devcheck.' Offline');if($check%100==0)$this->telegram($devcheck.' nog steeds Offline');} if($this->s['water']=='On'){if(strtotime($this->t['water'])<$this->cget('water'))$this->sw($this->i['water'],'Off','Water uitschakelen');} //Refresh Zwave devices $refresh=$this->time-1800; $items=array(3=>'media',7=>'hallzolder',8=>'lichtbadkamer',9=>'badkamervuur',12=>'inkomvoordeur',13=>'brander',15=>'bureeltobi',22=>'werkbladtuin',23=>'water',24=>'garageterras',49=>'keukenzolderg',56=>'grohered',57=>'fanvestiaire',58=>'tuinpomp',59=>'zwembad',61=>'wasbakkookplaat'); foreach($items as $item => $name) if($this->cget('timerefresh-'.$name)<$refresh)$this->RefreshZwave($item,'time',$name); if($this->cget('timenetworkheal')<$this->twaalfuur&&$this->time>strtotime('15:00')){ file_get_contents($this->api.'json.htm?type=command¶m=zwavenetworkheal&idx=4'); $this->cset('timenetworkheal',$this->time); } $rains=file_get_contents('http://gps.buienradar.nl/getrr.php?lat=50.892880&lon=3.112568'); $rains=str_split($rains,11); $totalrain=0; $aantal=0; foreach($rains as $rain){ $aantal=$aantal+1; $totalrain=$totalrain+substr($rain,0,3); $newrain=number_format($totalrain/$aantal,2); if($aantal==7)break; } if($newrain>100)$newrain=100; $averagerain=floor(($newrain+($this->s['buienradar']*9))/10); if($averagerain!=$this->s['buienradar']) { print $this->stamp." --- Buienradar: Prev=".$this->s['buienradar']."|New=$newrain|Update=$averagerain "; $this->ud($this->i['buienradar'],0,$averagerain,'buienradar'); } include('gcal/gcal.php'); } //END CRON } }