Skip to content

Instantly share code, notes, and snippets.

@hdo
Created October 14, 2014 12:39
Show Gist options
  • Save hdo/a716324574ee6accad9e to your computer and use it in GitHub Desktop.
Save hdo/a716324574ee6accad9e to your computer and use it in GitHub Desktop.
FHEM Erweiterung für Statusanzeige (Entsorgungskalender)
### by Huy Do (huydo1@gmail.com
package main;
use strict;
use warnings;
use POSIX;
sub muelltonnen_Initialize($$)
{
my ($hash) = @_;
}
sub muelltonnen_update_display($$) {
my $title = shift;
my $color = shift;
my $fhem_cmd = undef;
if ($title =~ /^Grau.*$/) {
$fhem_cmd = "set display color 28 ".$color;
}
if ($title =~ /^Gelb.*$/) {
$fhem_cmd = "set display color 29 ".$color;
}
if ($title =~ /^Gruen.*$/) {
$fhem_cmd = "set display color 30 ".$color;
}
if ($title =~ /^Braun.*$/) {
$fhem_cmd = "set display color 31 ".$color;
}
if ($fhem_cmd) {
Log 3, $fhem_cmd;
}
}
sub muelltonnen_check() {
#Log 3, "called muelltonnen_check()";
my $in0 = strftime("%d.%m.%y",localtime(time));
my $in1 = strftime("%d.%m.%y",localtime(time+(3600*24)));
my $in2 = strftime("%d.%m.%y",localtime(time+(3600*48)));
my $in3 = strftime("%d.%m.%y",localtime(time+(3600*72)));
#Log 3, "in 0:".$in0;
#Log 3, "in 1:".$in1;
#Log 3, "in 2:".$in2;
#Log 3, "in 3:".$in3;
my @lines = split /\n/, fhem("get CAL.ENTSORGUNG text modeUpcoming");
foreach my $line (@lines) {
my $datum = substr($line,0,8);
my $titel = substr($line,15);
# check 7 days
for (my $i=0; $i <= 6; $i++) {
my $check_datum = strftime("%d.%m.%y",localtime(time+(3600*$i*24)));
if ($datum eq $check_datum) {
Log 3, $titel." in ".$i." Tagen";
if ($i == 0) {
muelltonnen_update_display($titel, "red");
}
if ($i == 1) {
muelltonnen_update_display($titel, "orangered");
}
if ($i > 1 && $i < 4) {
muelltonnen_update_display($titel, "blue");
}
}
}
}
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment