[PATCH] Aktuelle Programmtemperatur als Reading

Begonnen von Markus M., 10 April 2015, 00:14:31

Vorheriges Thema - Nächstes Thema

Markus M.

Hi!

Ich möchte eine relative Temperaturabsenkung realisieren, bei der ich abhängig von der über Bewegungssensoren ermittelten Idle-Time des Raums die Soll-Temperatur um einen gewissen Wert absenke.

Dazu fehlte allerdings ein Reading, das immer die aktuell durch das Wochenprogramm festgelegte Temperatur enthält.

Das neue Reading programTemperature wird über die bereits bestehende Funktion ParseWeekProfile realisiert.
Wäre nett wenn das bei Gelegenheit mal ins SVN übernommen würde.

Markus

Code (patch) Auswählen

Index: FHEM/10_MAX.pm
===================================================================
--- FHEM/10_MAX.pm (revision 10825)
+++ FHEM/10_MAX.pm (working copy)
@@ -195,6 +195,17 @@
}

sub
+MAX_ParseWeekProfileProgram(@)
+{
+  my ($hash) = @_;
+  Log3 $hash, 5, "MAX ".$hash->{NAME}.": profilewrapper";
+  RemoveInternalTimer($hash);
+  readingsBeginUpdate($hash);
+  MAX_ParseWeekProfile($hash);
+  readingsEndUpdate($hash, 1);
+}
+
+sub
MAX_ParseWeekProfile(@) {
   my ($hash ) = @_;
   # Format of weekprofile: 16 bit integer (high byte first) for every control point, 13 control points for every day
@@ -204,6 +215,11 @@
   # int minute = time % 60;
   # int temperature = ((value >> 9) & 0x3F) / 2;

+  my $currenttemp = 0;
+  my $minutestoday = strftime("%H",localtime)*60 + strftime("%M",localtime);
+  my $nextchange = 900;
+  RemoveInternalTimer($hash);
+
   my $curWeekProfile = MAX_ReadingsVal($hash, ".weekProfile");
   #parse weekprofiles for each day
   for (my $i=0;$i<7;$i++) {
@@ -219,9 +235,28 @@
     for($j=0;$j<13;$j++) {
       $hours[$j] = ($time_prof[$j] / 60 % 24);
       $minutes[$j] = ($time_prof[$j]%60);
+
+      if(substr($decalcDays{$i},0,2) eq strftime("%a", localtime) && $currenttemp == 0)
+      {
+
+        if($minutestoday < ($time_prof[$j]))
+        {
+          $currenttemp = $temp_prof[$j] if($temp_prof[$j] gt 0);
+          $nextchange = (($time_prof[$j] - $minutestoday) * 60) if(($time_prof[$j] - $minutestoday) > 0);
+
+          Log3 $hash, 5, "MAX ".$hash->{NAME}.": program temperature is ".$currenttemp."˚C until ".sprintf("%02d:%02d", $hours[$j], $minutes[$j])." [block ".($j+1)."] ".strftime("%a", localtime)." ".$nextchange." ";
+        }
+        #Log3 $hash, 5, "MAX ".$hash->{NAME}.": mins is ".$minutestoday." < ".$time_prof[$j]." is ".((int($minutestoday) < int($time_prof[$j]))?"true":"false")."   next ".$nextchange."   ".$temp_prof[$j];
+
+      }
+
       #if 00:00 reached, last point in profile was found
-      last if(int($hours[$j])==0 && int($minutes[$j])==0 );
+      if($time_prof[$j]==1440)
+      {
+        last;
+      }
     }
+
     my $time_prof_str = "00:00";
     my $temp_prof_str;
     for (my $k=0;$k<=$j;$k++) {
@@ -232,9 +267,19 @@
         $temp_prof_str .= "  /  ";
       }
    }
+
+   if($currenttemp <= 0)
+   {
+     $currenttemp = 20;
+     Log3 $hash, 5, "MAX ".$hash->{NAME}.": temp fail / 20";
+   }
+
+   readingsBulkUpdate($hash, "programTemperature", $currenttemp, 1 );
+
    readingsBulkUpdate($hash, "weekprofile-$i-$decalcDays{$i}-time", $time_prof_str );
    readingsBulkUpdate($hash, "weekprofile-$i-$decalcDays{$i}-temp", $temp_prof_str );
   }
+  InternalTimer(int(gettimeofday())+$nextchange, "MAX_ParseWeekProfileProgram", $hash, 0);
}
#############################

@@ -666,7 +711,7 @@
     my $measuredTemperature = defined($until2) ? ((($until1 &0x01)<<8) + $until2)/10 : 0;
     #If the control mode is not "temporary", the cube sends the current (measured) temperature
     $measuredTemperature = "" if($mode == 2 || $measuredTemperature == 0);
-    $untilStr = "" if($mode != 2);
+    $untilStr = "(".$untilStr.")" if($mode != 2);

     $desiredTemperature = ($desiredTemperature&0x7F)/2.0; #convert to degree celcius
     Log3 $hash, 5, "battery $batterylow, rferror $rferror, panel $panel, langateway $langateway, dstsetting $dstsetting, mode $mode, valveposition $valveposition %, desiredTemperature $desiredTemperature, until $untilStr, curTemp $measuredTemperature";
@@ -800,7 +845,7 @@
   } elsif($msgtype eq "AckWakeUp") {
     my ($duration) = @args;
     #substract five seconds safety margin
-    $shash->{wakeUpUntil} = gettimeofday() + $duration - 5;
+    $shash->{wakeUpUntil} = int(gettimeofday()) + $duration - 5;

   } elsif($msgtype eq "AckConfigWeekProfile") {
     my ($day, $part, $profile) = @args;
Aktuell weder Smarthome noch FHEM vorhanden

Markus M.

Wurde das hier eigentlich einfach nur übersehen?
Ich verwende das immer noch ;)
Aktuell weder Smarthome noch FHEM vorhanden