epochtime)); SetValue(getVariableID($indicator." Unix Time",1),$values->epochtime); SetValue(getVariableID($indicator." Grünstromindex",1),$values->eevalue); SetValue(getVariableID($indicator." Arbeitspreis (Cent)",2),$values->energyprice); SetValue(getVariableID($indicator." CO2 (EE)",1),$values->co2_g_oekostrom); //SetValue(getVariableID($indicator." Wind (EE)",1),$values->enwind); SetValue(getVariableID($indicator." Solar (EE)",1),$values->ensolar); } function processSignal() { $signal=json_decode(GetValue(getVariableID("raw_signal",3))); if(!isset($signal->forecast)) { echo "Missing"; print_r($signal); fetchSignal(GetValueString(getVariableID("Postleitzahl",3))); processSignal(); } $ts=time(); $current=$signal->forecast[0]; $best=$signal->forecast[0]; $worst=$signal->forecast[0]; $i=0; foreach($signal->forecast as $o) { if($o->epochtime<$ts) { $current=$o; $i++; } else { if($o->eevalue>$best->eevalue) $best=$o; if($o->eevalue<$worst->eevalue) $worst=$o; } } if($i>6) fetchSignal(GetValueString(getVariableID("Postleitzahl",3))); if(time()<$current->epochtime) { setSlots("Aktuell",$current); } else { echo "FEHLER: Letzter Wert im Grünstromindex zu alt (".(time()-($current->epochtime))." Sekunden)"; SetValue(getVariableID("Aktuell Zeitpunkt",3), "-"); SetValue(getVariableID("Aktuell Unix Time",1),0); SetValue(getVariableID("Aktuell Grünstromindex",1),50); fetchSignal(GetValueString(getVariableID("Postleitzahl",3))); processSignal(); } setSlots("Grün",$best); setSlots("Grau",$worst); } function fetchSignal($plz) { //$signal_raw=file_get_contents("https://api.corrently.io/core/gsi?plz=83352"); //SetValueString(getVariableID("raw_signal",3),$signal_raw); } function getVariableID($name,$type) { $id=0; if(!IPS_GetObjectIDByName($name,$_IPS['SELF'])) { $id=IPS_CreateVariable($type); IPS_SetName($id,$name); IPS_SetParent($id,$_IPS["SELF"]); } else { $id=IPS_GetObjectIDByName($name,$_IPS['SELF']); } return $id; } // Generelle Aktualisierungs Logik date_default_timezone_set('UTC'); $plz=GetValueString(getVariableID("Postleitzahl",3)); if(strlen($plz)!=5) { $plz="83352"; SetValueString(getVariableID("Postleitzahl",3),$plz); } setUpdateSchedule(); processSignal(); ?>