1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
##############################################
# $Id: 99_myUtils.pm 5555 2014-08-27 14:13:59Z klaushuyke $
package main;
use strict;
use warnings;
use POSIX;
use Time::Local;
use HTML::Entities;
sub
myUtils_Initialize($$)
{
my ($hash) = @_;
}
sub
Abfalltermine ($)
{
my ($Ereignis) = @_;
my @Ereignisarray = split(/.*:\s/,$Ereignis);
my $Ereignisteil1 = $Ereignisarray[1];
my @uids=split(/;/,$Ereignisteil1);
my $t = time;
my $dtPapier = '';
my $dtGelberSack = '';
my $dtRest = '';
my $dtBio = '';
my $dayDiff = 0;
my $dtBeda = '';
foreach my $uid (@uids) {
my $Kalendertext = fhem("get Abfall summary $uid");
if ($Kalendertext =~ /Papiertonne/) {
my $dt = fhem("get Abfall start $uid");
my @SplitDt = split(/ /,$dt);
my @SplitDate = split(/\./,$SplitDt[0]);
my $eventDate = timelocal(0,0,0,$SplitDate[0],$SplitDate[1]-1,$SplitDate[2]);
if ($dtPapier eq '' || ($eventDate < $dtPapier && $eventDate > $t))
{
$dtPapier = $eventDate;
Log(3, $dtPapier);
}
};
if ($Kalendertext =~ /Gelber Sack/) {
my $dt = fhem("get Abfall start $uid");
my @SplitDt = split(/ /,$dt);
my @SplitDate = split(/\./,$SplitDt[0]);
my $eventDate = timelocal(0,0,0,$SplitDate[0],$SplitDate[1]-1,$SplitDate[2]);
if ($dtGelberSack eq '' || ($eventDate < $dtGelberSack && $eventDate > $t))
{
$dtGelberSack = $eventDate;
}
};
if ($Kalendertext =~ /Restmüll/) {
my $dt = fhem("get Abfall start $uid");
my @SplitDt = split(/ /,$dt);
my @SplitDate = split(/\./,$SplitDt[0]);
my $eventDate = timelocal(0,0,0,$SplitDate[0],$SplitDate[1]-1,$SplitDate[2]);
if ($dtRest eq '' || ($eventDate < $dtRest && $eventDate > $t))
{
$dtRest = $eventDate;
}
};
if ($Kalendertext =~ /Bio/) {
my $dt = fhem("get Abfall start $uid");
my @SplitDt = split(/ /,$dt);
my @SplitDate = split(/\./,$SplitDt[0]);
my $eventDate = timelocal(0,0,0,$SplitDate[0],$SplitDate[1]-1,$SplitDate[2]);
if ($dtBio eq '' || ($eventDate < $dtBio && $eventDate > $t))
{
$dtBio = $eventDate;
}
};
if ($Kalendertext =~ /Pater Beda/) {
my $dt = fhem("get Abfall start $uid");
my @SplitDt = split(/ /,$dt);
my @SplitDate = split(/\./,$SplitDt[0]);
my $eventDate = timelocal(0,0,0,$SplitDate[0],$SplitDate[1]-1,$SplitDate[2]);
if ($dtBeda eq '' || ($eventDate < $dtBeda && $eventDate > $t))
{
$dtBeda = $eventDate;
}
};
$dayDiff = floor(($dtPapier - $t) / 60 / 60 / 24 + 1);
if ($dayDiff >= 0) {
fhem("set Papiertonne $dayDiff");
}
$dayDiff = floor(($dtGelberSack - $t) / 60 / 60 / 24 + 1);
if ($dayDiff >= 0) {
fhem("set GelberSack $dayDiff");
}
$dayDiff = floor(($dtRest - $t) / 60 / 60 / 24 + 1);
if ($dayDiff >= 0) {
fhem("set Restmuell $dayDiff");
}
$dayDiff = floor(($dtBio - $t) / 60 / 60 / 24 + 1);
if ($dayDiff >= 0) {
fhem("set Bio $dayDiff");
}
$dayDiff = floor(($dtBeda - $t) / 60 / 60 / 24 + 1);
if ($dayDiff >= 0) {
fhem("set Pater_Beda $dayDiff");
}
}
}
#### Log-abriss vermeiden
# called by
# define addLog notify addLog {addLog("ez_Aussensensor","state");addLog("ez_FHT","actuator");\
# addLog("MunichWeather","humidity");addLog("MunichWeather","pressure");\
# addLog("MunichWeather","temperature");addLog("MunichWeather","wind_chill");}
# define a_midnight1 at *23:59 trigger addLog
# define a_midnight2 at *00:01 trigger addLog
sub
addLog($$) {
my ($logdevice, $reading) = @_; # device and reading to be used
my $logentry = ReadingsVal($logdevice,$reading,"addLog: invalid reading");
if ($reading =~ m,state,i) {
fhem "trigger $logdevice $logentry << addLog";
} else {
fhem "trigger $logdevice $reading: $logentry << addLog";
}
}
sub BM_MotionHandling($$){
my($device, $event) = @_;
return if($attr{$device}{subType} ne "motionDetector");
my $ResetAT = $device."_Reset";
if($event eq "motion") {
# Bewegung erkannt, erstelle AT um Status wieder zurückzusetzen
if (defined($defs{$ResetAT})) {
fhem "modify ".$ResetAT." +00:05:00 {BM_MotionHandling(\"$device\", \"scanning\")}";
} else {
fhem "define ".$ResetAT." at +00:05:00 {BM_MotionHandling(\"$device\", \"scanning\")}";
}
} elsif($event eq "scanning") {
# Status des Devices wieder zurücksetzen
readingsSingleUpdate($defs{$device}, "state", $event, 1);
}
}
###################################################
### Spritpreisübersicht - Farbsortierung ###
###################################################
sub Werte($$) {
my ($name, $wert) = @_;
# Log(3,"$name $wert");
if ($name eq "Diesel") {
return 'style="color:red"' if($wert >= 1.39);
return 'style="color:blue"' if(($wert >= 1.33) && ($wert < 1.39));
return 'style="color:green;;font-weight:bold"' if($wert <= 1.32);
}elsif ($name eq "SuperE10") {
return 'style="color:crimson"' if($wert >= 1.70);
return 'style="color:yellow"' if(($wert >= 1.55) && ($wert < 1.70));
return 'style="color:lightgreen;;font-weight:bold"' if($wert < 1.55);
}elsif ($name eq "SuperE5") {
return 'style="color:red"' if($wert >= 1.59);
return 'style="color:blue"' if(($wert >= 1.49) && ($wert < 1.59));
return 'style="color:green;;font-weight:bold"' if($wert <= 1.48);
}
}
sub time2dec($){
my ($h,$m,$s) = split(":", shift);
$m = 0 if(!$m);
$s = 0 if(!$s);
my $t = $m * 60;
$t += $s;
$t /= 3600;
$t += $h;
return ($t)
}
sub dec2hms($){
my ($t) = @_;
my $h = int($t);
my $r = ($t - $h)*3600;
my $m = int($r/60);
my $s = $r - $m*60;
return sprintf("%02d:%02d:%02d",$h,$m,$s);
}
sub
wrapLine($$)
{
my ($string, $maxLength) = @_;
$string = decode_entities($string);
my @stringParts = split(/ /, $string);
my $actRowLength = 0;
my $resultString = '';
while (scalar(@stringParts) > 0) {
my $tempString = shift @stringParts;
if ($actRowLength > 0)
{
if (($actRowLength + length($tempString)) > $maxLength)
{
$actRowLength = 0;
$resultString .= '<br>';
}
}
$resultString .= $tempString;
$actRowLength += length($tempString);
if (scalar(@stringParts) > 0)
{
$resultString .= ' ';
$actRowLength += 1;
}
}
if ($resultString eq '')
{
return ' ';
}
else
{
return $resultString;
}
}
# Weitere Subroutinen
1;
1
2
3
4
5
6
7
8
9
Subroutine myUtils_Initialize redefined at ./FHEM/99_MyUtils.pm line 12, <$fh> line 8.
Subroutine Abfalltermine redefined at ./FHEM/99_MyUtils.pm line 18, <$fh> line 8.
Subroutine addLog redefined at ./FHEM/99_MyUtils.pm line 116, <$fh> line 8.
Subroutine BM_MotionHandling redefined at ./FHEM/99_MyUtils.pm line 126, <$fh> line 8.
Subroutine Werte redefined at ./FHEM/99_MyUtils.pm line 148, <$fh> line 8.
Subroutine time2dec redefined at ./FHEM/99_MyUtils.pm line 166, <$fh> line 8.
Subroutine dec2hms redefined at ./FHEM/99_MyUtils.pm line 177, <$fh> line 8.
Subroutine wrapLine redefined at ./FHEM/99_MyUtils.pm line 188, <$fh> line 8.
2015.10.27 13:17:27 1: PERL WARNING: Use of uninitialized value $Ereignisteil1 in split at ./FHEM/99_MyUtils.pm line 22.
1
2
3
4
5
6
7
8
9
addLog($$) {
my ($logdevice, $reading) = @_; # device and reading to be used
my $logentry = ReadingsVal($logdevice,$reading,"addLog: invalid reading");
if ($reading =~ m,state,i) {
fhem( "trigger $logdevice $logentry << addLog" ); # Hier
} else {
fhem( "trigger $logdevice $reading: $logentry << addLog" ); # Hier
}
}