Es weihnachtet: Sendung nicht verpassen ;-)

Hallo zusammen,

ich muss gestehen, ich habe eine Weihnachtsmacke :wink: Ich liebe „Drei Haselnüsse für Aschenbrödel“ … ist einfach so :smiley:

Da kam mir heute die Idee - um keine Sendung zu verpassen - bastelst Dir ein kleines Script … gesagt - getan!

Habe einfach mal was ich so aus allen Scripten hatte zusammenkopiert und schon war das Weihnachts-Special-Erinnerungs-Märchen-Gucker-Script fertig!

Es ist frisch aus der Presse und hat vielleicht noch seine Unzulänglichkeiten! Man kann es bestimmt auch noch optimieren, perfektionieren, erweitern und was weiß ich noch alles :wink:

Und so sieht es aus:

Und hier ist das Script


<?
################################################################################
# Scriptbezeichnung: Other.Scheduled.ips.php
# Version:	1.0.20181215
# Author:	Heiko Wilknitz (@pitti)
#
# TV Sendetermine für eine bestimmte Sendung mit Erinnerungsfuntion
#
# Anleitung:
# - Zuerst Konfigurationswerte auf eigene Bedürfnisse anpassen (max, step usw.)
# - In Konsole einfach ausführen um alles korrekt zu installieren.
#
# ------------------------------ Konfiguration ---------------------------------
#
# Erinnerungsfunktion
$min 	= 0;
$max 	= 120;
$step = 5; // Schrittweite
$suffix = "min";
#
# Bei Verwendung der Scripte 'Meldungsanzeige im WebFront' (Post #51)
# https://www.symcon.de/forum/threads/12115-Meldungsanzeige-im-WebFront
# hier die ScriptID von 'Meldungsverwaltung' eintragen, sonst 0!
$dbID	= 0 /*[Steuerung\Dashboard\Meldungsverwaltung]*/;
#
# Bei Verwendung von Push Notification (WFC_PushNotification)
# hier die Webfront Konfigurator Id eintragen, sonst 0!
$wfID	= 0 /*[Multimedia]*/;
#
# Sendungsname
$progName = 'Drei Haselnüsse für Aschenbrödel';
# Sendetermine
$progData = array(
	array('17.11.2018', '11:25', 'Das Erste'),
	array('02.12.2018', '12:00', 'KiKa'),
	array('24.12.2018', '12:00', 'Das Erste'),
	array('24.12.2018', '15:05', 'WDR'),
	array('24.12.2018', '16:40', 'NDR'),
	array('24.12.2018', '18:50', 'ONE'),
	array('24.12.2018', '20:15', 'RBB'),
	array('25.12.2018', '10:25', 'Das Erste'),
	array('25.12.2018', '23:15', 'HR'),
	array('26.12.2018', '08:05', 'SWR'),
	array('26.12.2018', '09:00', 'RBB & BR'),
	array('26.12.2018', '16:00', 'MDR'),
	array('28.12.2018', '19:30', 'KiKa')
);
#
# ------------------------------------------------------------------------------
#
# Wochentage auf Deutsch
$day	= array(
	"Sonntag",
	"Montag",
	"Dienstag",
	"Mittwoch",
	"Donnerstag",
	"Freitag",
	"Samstag"
);
#
# Übersetzungstabelle
$trans = array(
    'Monday'    => 'Montag',
    'Tuesday'   => 'Dienstag',
    'Wednesday' => 'Mittwoch',
    'Thursday'  => 'Donnerstag',
    'Friday'    => 'Freitag',
    'Saturday'  => 'Samstag',
    'Sunday'    => 'Sonntag',
    'Mon'       => 'Mo',
    'Tue'       => 'Di',
    'Wed'       => 'Mi',
    'Thu'       => 'Do',
    'Fri'       => 'Fr',
    'Sat'       => 'Sa',
    'Sun'       => 'So',
    'January'   => 'Januar',
    'February'  => 'Februar',
    'March'     => 'März',
    'May'       => 'Mai',
    'June'      => 'Juni',
    'July'      => 'Juli',
    'October'   => 'Oktober',
    'December'  => 'Dezember',
);
#
# Variablenprofile
$vpn = "Reminder.".$max.".".$step;
#
################################################################################

// INSTALLATION
if ($_IPS['SENDER']=='Execute') {
	$pos = 1;
	// Erinnerung
	if(IPS_VariableProfileExists($vpn)) {
		IPS_DeleteVariableProfile($vpn);
	}
	IPS_CreateVariableProfile($vpn, 1);
	IPS_SetVariableProfileValues($vpn, $min, $max, 0);
	IPS_SetVariableProfileIcon($vpn, "Hourglass");
	IPS_SetVariableProfileAssociation($vpn, $min-2, "Aus", "", 0xFF0000);
	IPS_SetVariableProfileAssociation($vpn, $min-1, "-".$step, "", -1);
	IPS_SetVariableProfileAssociation($vpn, $min, "%d ".$suffix, "", 0x00FF00);
	IPS_SetVariableProfileAssociation($vpn, $max+1, "+".$step, "", -1);
	$vid = CreateVariableByName($_IPS['SELF'], "Erinnerung", 1);
	IPS_SetVariableCustomProfile($vid, $vpn);
	IPS_SetVariableCustomAction($vid, $_IPS['SELF']);
	IPS_SetPosition($vid, $pos++);
	SetValue($vid, $min-2);
	// Sendungstabelle
	$vid = CreateVariableByName($_IPS['SELF'], $progName, 3);
	IPS_SetVariableCustomProfile($vid, '~HTMLBox');
	IPS_SetIcon($vid, "TV");
	IPS_SetPosition($vid, $pos++);
	SetValue($vid, BuildHtml($progData));
	// Mitternachtsupdate
	$midnight = mktime(0, 5, 0);
	$eid = CreateEventByName($_IPS['SELF'], "Midnight Update", $midnight);
   IPS_SetPosition($eid, -1);
}
// AKTION VIA WEBFRONT
else if($_IPS['SENDER'] == "WebFront") {
	switch($_IPS['VALUE']) {
		case $min-2:
			SetValue($_IPS['VARIABLE'], 10); 
			ReminderOff();
			break;
		case $min-1:
    		$_IPS['VALUE'] = GetValue($_IPS['VARIABLE']) - $step;
         if($_IPS['VALUE'] < 0) {
          	$_IPS['VALUE'] = -2;
				ReminderOff();
         }
         break;
		case $max+1:
			$_IPS['VALUE'] = min($max, max(0, GetValue($_IPS['VARIABLE'])) + $step);
			ReminderOn($_IPS['VALUE']);
			break;
		default:
			ReminderOn($_IPS['VALUE']);
	}
	SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
}
// TIMER EVENT
else if($_IPS['SENDER'] == "TimerEvent") {
	$eid = CreateEventByName($_IPS['SELF'], "Midnight Update", time());
	// Midnight Timer?
	if($eid == $_IPS['EVENT']) {
		$vid = CreateVariableByName($_IPS['SELF'], $progName, 3);
		SetValue($vid, BuildHtml($progData));		
	}
	// ScriptTimer
	else {
		// Notification?
		if($wfID != 0) {
			$vid = CreateVariableByName($_IPS['SELF'], "Erinnerung", 1);
			$time = GetValue($vid);
			$msg = $progName.' beginnt';
			if ($time == 0) {
				$msg = $msg.' jetzt!';
			}
			else {
				$msg = $msg.' in '.$time.' Minuten!';
			}
			WFC_PushNotification($wfID, 'Erinnerung', $msg, 'happy', 0);
			// Timer neu setzen
			ReminderOn($time);
		}
	}
}

# ------------------------------ Funktionen ------------------------------------

// Render Sendeterminliste
function BuildHtml($entries) 
{
global $day, $trans, $dbID, $progName;
   // Anzeige aufbereiten 
	$style = "";
	$style = $style.'<style type="text/css">';
	$style = $style.'table  {border-collapse: collapse; font-size: 14px; width: 100%; }';
	$style = $style.'td.fst {vertical-align: middle; text-align: center; padding: 5px; border-left: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.1); }';
	$style = $style.'td.mid {vertical-align: middle; text-align: center; padding: 5px; border-top: 1px solid rgba(255, 255, 255, 0.1); }';
	$style = $style.'td.lst {vertical-align: middle; text-align: left; padding: 5px; border-right: 1px solid rgba(255, 255, 255, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.1); }';
	$style = $style.'tr:last-child {border-bottom: 1px solid rgba(255, 255, 255, 0.2); }';
	$style = $style.'tr:nth-child(even) {  background-color: rgba(0, 0, 0, 0.2); }';	  
	$style = $style.'.th { color: rgb(255, 255, 255); background-color: rgb(160, 160, 0); font-weight:bold; background-image: linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -o-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -moz-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -webkit-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); background-image: -ms-linear-gradient(top,rgba(0,0,0,0) 0,rgba(0,0,0,0.3) 50%,rgba(0,0,0,0.3) 100%); }';
	$style = $style.'.dotE { width: 15px; height: 15px; clear: both; background: #ff8080; border-radius: 50%; margin-top: 1px; margin-left:5px; }';
	$style = $style.'.dotW { width: 15px; height: 15px; clear: both; background: #ffff80; border-radius: 50%; margin-top: 1px; margin-left:5px; }';
	$style = $style.'.dotS { width: 15px; height: 15px; clear: both; background: #80ff80; border-radius: 50%; margin-top: 1px; margin-left:5px; }';
	$style = $style.'.dotC { width: 15px; height: 15px; clear: both; background: #c0c0c0; border-radius: 50%; margin-top: 1px; margin-left:5px; }';
	$style = $style.'.dotN { width: 15px; height: 15px; clear: both; background: #ff80ff; border-radius: 50%; margin-top: 1px; margin-left:5px; }';
	$style = $style.'</style>';
	// HTML zusammenbauen	
	$html = $style;
	$html .= '<table>';
	$html .= '<tr><td class="fst th" style="width:30px;">-</td><td class="mid th" style="width:150px;">Datum</td><td class="mid th" style="width:50px;">Wochentag</td><td class="mid th" style="width:120px;">Uhrzeit</td><td class="lst th">Sender</td></tr>'; 
	
	$today = false;
	foreach ($entries as $line) {
		$date = strtotime($line[0]); 
		if($line[0] == date("d.m.Y")) {
			$wd = "<b>Heute</b>";
			$color = 'W';
			$today = true;
		}
		elseif($line[0] == date("d.m.Y", strtotime("+1 day"))) {
			$wd = "<b>Morgen</b>";
			$color = 'W';
		}
		else {
			$wd = $day[date("w", $date)];
			$color = 'S';
		}
		// Schon vorbei
		IPS_LogMessage('Reminder', $line[0].'='.$date.' <> '.date("d.m.Y"));
		if($date < strtotime(date("d.m.Y"))) {
			$color = 'E';
			$line[0] = '<s>'.$line[0].'</s>';
		}
		$html .= '<tr><td class="fst"><div class="dot'.$color.'"></div>'.'</td><td class="mid">'.$line[0].'</td><td class="mid">'.$wd.'</td><td class="mid">'.$line[1].' Uhr</td><td class="lst">'.$line[2].'</td></tr>'; 
	}
	$html.='</table>';
	// Info ans Dashboard schicken?	
	if($today && ($dbID != 0)) {
		IPS_RunScriptWaitEx($dbID, array('action' => 'add', 'text' => '"'.$progName.'" nicht verpassen!', 'type' => 3, 'expires' => time() + 24*60*60 - 600,'image' => 'TV'));
	}
	// Zurück
	return $html;	
}

// Erinnerungsfunktion einschalten
function ReminderOn($pre)
{
global $progData;
	// Timer einschalten
	$now = time();
	// Nächsten Sendetermin finden
	foreach ($progData as $line) {
		$time = strtotime($line[0].', '.$line[1]) - ($pre*60);
		// Zeit schon vorbei?
		if($time < $now) {
			continue;
		}
		// Timer setzen
		CreateTimerByName($_IPS['SELF'], "Reminder Notification", $time, true);
		return;
	}
	// Timer ausschalten, anscheinend keine Sendungen mehr da :(
	CreateTimerByName($_IPS['SELF'], "Reminder Notification", $now, false);
}

// Erinnerungsfunktion ausschalten
function ReminderOff()
{
	// Timer ausschalten, anscheinend keine Sendungen mehr da :(
	$now = time();
	CreateTimerByName($_IPS['SELF'], "Reminder Notification", $now, false);
}

// Erzeugt eine Variable unterhalb {id} mit dem Namen {name} vom Typ [type}
// Existiert die Variable schon wird diese zurückgeliefert.
// Types: 0 = Boolean, 1 = Integer, 2 = Float, 3 = String
function CreateVariableByName($id, $name, $type) 
{
	$vid = @IPS_GetVariableIDByName($name, $id); 
	if($vid===false) {
		$vid = IPS_CreateVariable($type); 
		IPS_SetParent($vid, $id); 
		IPS_SetName($vid, $name); 
	}
	return $vid; 
}

// Erzeugt einen Timer unterhalb {id} mit dem Namen {name} um Zeit {time}
// Existiert das  Event schon wird diese zurückgeliefert.
function CreateEventByName($id, $name, $time)  
{  
	$eid = @IPS_GetEventIDByName($name, $id);  
	if($eid===false) {
		// zyklisches Event  
		$eid = IPS_CreateEvent(1);  
		IPS_SetParent($eid, $id);  
		IPS_SetName($eid, $name);  
	}  
	// tägliches Event 
	IPS_SetEventCyclic($eid, 2, 1, 0, 0, 0, 0);  
	IPS_SetEventCyclicDateFrom($eid, (int)date('j',$time), (int)date('n', $time),  (int)date('Y', $time));  
	IPS_SetEventCyclicDateTo($eid, 0, 0, 0);  
	IPS_SetEventCyclicTimeFrom($eid, (int)date("H", $time), (int)date("i", $time), (int)date("s", $time));  
	IPS_SetEventCyclicTimeTo($eid, 0, 0, 0); 
	IPS_SetEventActive($eid, true);  
	return $eid;  
}  

// Erzeugt einen Timer unterhalb {id} mit dem Namen {name} um Zeit {time}
// Existiert das  Event schon wird diese zurückgeliefert.
function CreateTimerByName($id, $name, $time, $active)  
{  
	$eid = @IPS_GetEventIDByName($name, $id);  
	if($eid===false) {
		// zyklisches Event  
		$eid = IPS_CreateEvent(1);  
		IPS_SetParent($eid, $id);  
		IPS_SetName($eid, $name);  
	}  
	// einmaliges Event 
	IPS_SetEventCyclic($eid, 1, 0, 0, 0, 0, 0);  
	IPS_SetEventCyclicDateFrom($eid, (int)date('j',$time), (int)date('n', $time),  (int)date('Y', $time));  
	IPS_SetEventCyclicDateTo($eid, (int)date('j',$time), (int)date('n', $time),  (int)date('Y', $time));  
	IPS_SetEventCyclicTimeFrom($eid, (int)date("H", $time), (int)date("i", $time), (int)date("s", $time));  
	IPS_SetEventCyclicTimeTo($eid, (int)date("H", $time), (int)date("i", $time), (int)date("s", $time)); 
	IPS_SetEventActive($eid, $active);  
	return $eid;  
}  


// Erzeugt ein Variablenprofil vom Typ {type} mit Name n{name} 
function CreateProfile($name, $type)
{
	if(!IPS_VariableProfileExists($name)) {
		IPS_CreateVariableProfile($name, $type);
	}
	else {
	$profile = IPS_GetVariableProfile($name);
		if($profile['ProfileType'] != $type)
			throw new Exception("Variable profile type does not match for profile ".$name);
	}
}

// Erzeugt ein Integer-Variablenprofil
function CreateProfileInteger($name, $icon, $prefix, $suffix, $minvalue, $maxvalue, $step, $digits, $asso = NULL)
{
	CreateProfile($name, 1);
	IPS_SetVariableProfileIcon($name, $icon);
	IPS_SetVariableProfileText($name, $prefix, $suffix);
	IPS_SetVariableProfileDigits($name, $digits);
	
	if(($asso !== NULL) && (sizeof($asso) !== 0)){
		$minvalue = 0;
		$maxvalue = 0;
	} 
	IPS_SetVariableProfileValues($name, $minvalue, $maxvalue, $step);
	
	if(($asso !== NULL) && (sizeof($asso) !== 0)){
		foreach($asso as $ass) {
			IPS_SetVariableProfileAssociation($name, $ass[0], $ass[1], $ass[2], $ass[3]);
		}
	}
}
################################################################################
?>

Ciao Pitti

PS: Über die Erinnerung kann man die Vorlaufzeit die man bis zum Fernseher braucht einstellen :smiley:

PSS: Geht bestimmt auch für „Der kleine Lord“ :banghead:

Ach nö… und ich muss meine Frau jedes Jahr davon überzeugen, dass wir lieber „Stirb langsam“ gucken:banghead::smiley:
Coole Idee:cool:

Stirb langsam Sendetermine 15.12.2018 bis 08.02.2019 :smiley: