Anstehende Geburtstage über Sonos ausgeben

Begonnen von ToM_ToM, 04 Februar 2017, 22:59:21

Vorheriges Thema - Nächstes Thema

ToM_ToM

Hallo, vielleicht kann es ja noch jemand gebrauchen. :)

Erst mal müsst ihr eure CALVIEW entsprechend konfigurieren.

define GeburtstagskalenderOverview CALVIEW Geburtstagskalender
attr GeburtstagskalenderOverview DbLogExclude .*
attr GeburtstagskalenderOverview group Geburtstag
attr GeburtstagskalenderOverview modes all
attr GeburtstagskalenderOverview isbirthday 1
attr GeburtstagskalenderOverview yobfield _description


Das Geburtsjahr muss ins description Feld des Kalenders.

Dann fügt ihr folgendes in eure 99_myUtils.pm ein:

use Encode;

##############################
#                            #
# Geburtstagsansage #
#                            #
##############################
# param1 = Name of the CALVIEW
# param2 = Name of the SONOSPLAYER
# param3 = Volume of the SONOSPLAYER
# example: UpcomingBirthdayDates("GeburtstagskalenderOverview", "Sonos_Wohnzimmer", "30")
sub
UpcomingBirthdayDates($;$;$) {

# my $birthdayCalView = "GeburtstagskalenderOverview"; #Name of the CALVIEW
# my $Sonos_OutputDevice = "Sonos_Wohnzimmer";
# my $Sonos_OutputVolume = "30";

my $birthdayCalView = shift;
my $Sonos_OutputDevice = shift;
my $Sonos_OutputVolume = shift;

my $Sonos_OutputText = "";
my $birthdayTodayCount = 0;
my $birthdayTomorrowCount = 0;
my $birthdayDayAfterTomorrowCount = 0;

my $birthdayEntryCounter = ReadingsVal($birthdayCalView,"c-term","0");

for (my $i=1; $i<=$birthdayEntryCounter; $i++) {
my @birthdayEvent = readBirtdayCalReadings($birthdayCalView, $i);
my $birthdayDate = $birthdayEvent[0];
my $birthdayName = $birthdayEvent[1];
my $birthdayAge = $birthdayEvent[2];
my $birthdayDaysLeft = $birthdayEvent[3];

if ($birthdayDaysLeft == 0) {
#heute

if ($birthdayTodayCount == 0)
{
if ($birthdayAge ne "0") {
$Sonos_OutputText = $Sonos_OutputText . "Heute hat " . $birthdayName . " Geburtstag und wird " . $birthdayAge . " Jahre alt.";
}
else {
$Sonos_OutputText = $Sonos_OutputText . "Heute hat " . $birthdayName . " Geburtstag.";
}
}
else {
if ($birthdayAge ne "0") {
$Sonos_OutputText = $Sonos_OutputText . "Außerdem hat heute auch " . $birthdayName . " Geburtstag und wird " . $birthdayAge . " Jahre alt.";
}
else {
$Sonos_OutputText = $Sonos_OutputText . "Außerdem hat heute auch " . $birthdayName . " Geburtstag.";
}
}
$birthdayTodayCount++;

}
elsif ($birthdayDaysLeft == 1) {
#morgen

if ($birthdayTomorrowCount == 0)
{
if ($birthdayAge ne "0") {
$Sonos_OutputText = $Sonos_OutputText . "Morgen hat " . $birthdayName . " Geburtstag und wird " . $birthdayAge . " Jahre alt.";
}
else {
$Sonos_OutputText = $Sonos_OutputText . "Morgen hat " . $birthdayName . " Geburtstag.";
}
}
else {
if ($birthdayAge ne "0") {
$Sonos_OutputText = $Sonos_OutputText . "Außerdem hat morgen auch " . $birthdayName . " Geburtstag und wird " . $birthdayAge . " Jahre alt.";
}
else {
$Sonos_OutputText = $Sonos_OutputText . "Außerdem hat morgen auch " . $birthdayName . " Geburtstag.";
}
}
$birthdayTomorrowCount++;

}
elsif ($birthdayDaysLeft == 2) {
#übermorgen

if ($birthdayDayAfterTomorrowCount == 0)
{
if ($birthdayAge ne "0") {
$Sonos_OutputText = $Sonos_OutputText . "Übermorgen hat " . $birthdayName . " Geburtstag und wird " . $birthdayAge . " Jahre alt.";
}
else {
$Sonos_OutputText = $Sonos_OutputText . "Übermorgen hat " . $birthdayName . " Geburtstag.";
}
}
else {
if ($birthdayAge ne "0") {
$Sonos_OutputText = $Sonos_OutputText . "Außerdem hat übermorgen auch " . $birthdayName . " Geburtstag und wird " . $birthdayAge . " Jahre alt.";
}
else {
$Sonos_OutputText = $Sonos_OutputText . "Außerdem hat übermorgen auch " . $birthdayName . " Geburtstag.";
}
}
$birthdayDayAfterTomorrowCount++;

}
}

#Sprachausgabe
if (length($Sonos_OutputText) > 0) {
fhem("set $Sonos_OutputDevice Speak $Sonos_OutputVolume de $Sonos_OutputText");
}

}

#Hilfsfunktion für UpcomingBirthdayDates()
sub readBirtdayCalReadings($;$) {

my $birthdayCalView = shift; #Name of the CALVIEW

my $entryNumber = sprintf("%03d", shift); #entryNumber

my $birthdayDate = ReadingsVal($birthdayCalView,"t_".$entryNumber."_bdate","01.01.1800");
my $birthdayName = ReadingsVal($birthdayCalView,"t_".$entryNumber."_summary","Nobody");
my $birthdayAge = ReadingsVal($birthdayCalView,"t_".$entryNumber."_age","0");
my $birthdayDaysLeft = ReadingsVal($birthdayCalView,"t_".$entryNumber."_daysleft","999");

my @birthdayEvent = ($birthdayDate, $birthdayName, $birthdayAge, $birthdayDaysLeft);

return @birthdayEvent;
}



Anschließend könnt ihr die Funktion in FHEM folgendermaßen ausführen.

1. Parameter ist der Name von eurem CALVIEW
2. Parameter ist der Name von eurem SONOSPLAYER
3. Parameter regelt die Ausgabelautstärke

{UpcomingBirthdayDates("GeburtstagskalenderOverview", "Sonos_Wohnzimmer", "30")}

Viele Grüße

Thomas
Hardware: BananaPi, Busmaster CUL, SanDisk 16GB Ultra SD, 16 GB USB-Stick | Software: Armbian, FHEM 5.8