mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
98_weekprofile: send values for on/off instead of "on"/"off"
git-svn-id: https://svn.fhem.de/fhem/trunk@16140 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
59f39ebf6e
commit
c1fe8aaa2d
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- changed: 98_weekprofile: send values for on/off instead of "on"/"off"
|
||||||
- feature: 93_DbRep: V7.9.0, new attribute "avgTimeWeightMean" (averageValue)
|
- feature: 93_DbRep: V7.9.0, new attribute "avgTimeWeightMean" (averageValue)
|
||||||
some code review and corrections
|
some code review and corrections
|
||||||
- bugfix: 88_xs1Bridge: fix Code
|
- bugfix: 88_xs1Bridge: fix Code
|
||||||
|
@ -14,6 +14,8 @@ use warnings;
|
|||||||
use JSON; #libjson-perl
|
use JSON; #libjson-perl
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
use Storable qw(dclone);
|
||||||
|
|
||||||
use vars qw(%defs);
|
use vars qw(%defs);
|
||||||
use vars qw($FW_ME);
|
use vars qw($FW_ME);
|
||||||
use vars qw($FW_wname);
|
use vars qw($FW_wname);
|
||||||
@ -82,6 +84,17 @@ sub weekprofile_timeToMinutes($)
|
|||||||
return $hours * 60 + $minutes;
|
return $hours * 60 + $minutes;
|
||||||
}
|
}
|
||||||
##############################################
|
##############################################
|
||||||
|
sub myAttrVal($$$)
|
||||||
|
{
|
||||||
|
my ($me,$name,$def) = @_;
|
||||||
|
my $val = AttrVal($me, $name, $def);
|
||||||
|
|
||||||
|
if (defined($val) && ($name eq 'tempON' || $name eq 'tempOFF')) {
|
||||||
|
$val = sprintf("%.1f", $val);
|
||||||
|
}
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
##############################################
|
||||||
sub weekprofile_getDeviceType($$;$)
|
sub weekprofile_getDeviceType($$;$)
|
||||||
{
|
{
|
||||||
my ($me,$device,$sndrcv) = @_;
|
my ($me,$device,$sndrcv) = @_;
|
||||||
@ -209,8 +222,8 @@ sub weekprofile_readDayProfile($@)
|
|||||||
for(my $i = 0; $i < scalar(@temps); $i+=1){
|
for(my $i = 0; $i < scalar(@temps); $i+=1){
|
||||||
Log3 $me, 4, "$me(ReadDayProfile): temp $i $temps[$i]";
|
Log3 $me, 4, "$me(ReadDayProfile): temp $i $temps[$i]";
|
||||||
$temps[$i] =~s/[^\d.]//g; #only numbers
|
$temps[$i] =~s/[^\d.]//g; #only numbers
|
||||||
my $tempON = AttrVal($me, "tempON", undef);
|
my $tempON = myAttrVal($me, "tempON", undef);
|
||||||
my $tempOFF = AttrVal($me, "tempOFF", undef);
|
my $tempOFF = myAttrVal($me, "tempOFF", undef);
|
||||||
|
|
||||||
$temps[$i] =~s/$tempOFF/off/g if (defined($tempOFF)); # temp off
|
$temps[$i] =~s/$tempOFF/off/g if (defined($tempOFF)); # temp off
|
||||||
$temps[$i] =~s/$tempON/on/g if (defined($tempON)); # temp on
|
$temps[$i] =~s/$tempON/on/g if (defined($tempON)); # temp on
|
||||||
@ -290,6 +303,8 @@ sub weekprofile_sendDevProfile(@)
|
|||||||
|
|
||||||
my $devPrf = weekprofile_readDevProfile($device,$type,$me);
|
my $devPrf = weekprofile_readDevProfile($device,$type,$me);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# only send changed days
|
# only send changed days
|
||||||
my @dayToTransfer = ();
|
my @dayToTransfer = ();
|
||||||
foreach my $day (@shortDays){
|
foreach my $day (@shortDays){
|
||||||
@ -302,7 +317,7 @@ sub weekprofile_sendDevProfile(@)
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $equal = 1;
|
my $equal = 1;
|
||||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||||
if ( ($prf->{DATA}->{$day}->{"temp"}[$i] ne $devPrf->{$day}->{"temp"}[$i] ) ||
|
if ( ($prf->{DATA}->{$day}->{"temp"}[$i] ne $devPrf->{$day}->{"temp"}[$i] ) ||
|
||||||
$prf->{DATA}->{$day}->{"time"}[$i] ne $devPrf->{$day}->{"time"}[$i] ) {
|
$prf->{DATA}->{$day}->{"time"}[$i] ne $devPrf->{$day}->{"time"}[$i] ) {
|
||||||
$equal = 0;
|
$equal = 0;
|
||||||
@ -321,19 +336,33 @@ sub weekprofile_sendDevProfile(@)
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#make a copy because of replacements
|
||||||
|
my $prfData= dclone($prf->{DATA});
|
||||||
|
my $tempON = myAttrVal($me, "tempON", "30.5");
|
||||||
|
my $tempOFF = myAttrVal($me, "tempOFF", "4.5");
|
||||||
|
|
||||||
|
#replace variables with values
|
||||||
|
foreach my $day (@dayToTransfer){
|
||||||
|
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||||
|
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||||
|
$prfData->{$day}->{"temp"}[$i] = $tempON if ($prfData->{$day}->{"temp"}[$i] =~/on/i);
|
||||||
|
$prfData->{$day}->{"temp"}[$i] = $tempOFF if ($prfData->{$day}->{"temp"}[$i] =~/off/i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $cmd;
|
my $cmd;
|
||||||
if($type eq "MAX") {
|
if($type eq "MAX") {
|
||||||
$cmd = "set $device weekProfile ";
|
$cmd = "set $device weekProfile ";
|
||||||
foreach my $day (@dayToTransfer){
|
foreach my $day (@dayToTransfer){
|
||||||
my $tmpCnt = scalar(@{$prf->{DATA}->{$day}->{"temp"}});
|
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||||
|
|
||||||
$cmd.=$day.' ';
|
$cmd.=$day.' ';
|
||||||
|
|
||||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||||
my $endTime = $prf->{DATA}->{$day}->{"time"}[$i];
|
my $endTime = $prfData->{$day}->{"time"}[$i];
|
||||||
|
|
||||||
$endTime = ($endTime eq "24:00") ? ' ' : ','.$endTime.',';
|
$endTime = ($endTime eq "24:00") ? ' ' : ','.$endTime.',';
|
||||||
$cmd.=$prf->{DATA}->{$day}->{"temp"}[$i].$endTime;
|
$cmd.=$prfData->{$day}->{"temp"}[$i].$endTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elsif ($type eq "CUL_HM") {
|
} elsif ($type eq "CUL_HM") {
|
||||||
@ -344,9 +373,9 @@ sub weekprofile_sendDevProfile(@)
|
|||||||
$cmd .= $day;
|
$cmd .= $day;
|
||||||
$cmd .= ($k < $dayCnt-1) ? " prep": " exec";
|
$cmd .= ($k < $dayCnt-1) ? " prep": " exec";
|
||||||
|
|
||||||
my $tmpCnt = scalar(@{$prf->{DATA}->{$day}->{"temp"}});
|
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||||
$cmd .= " ".$prf->{DATA}->{$day}->{"time"}[$i]." ".$prf->{DATA}->{$day}->{"temp"}[$i];
|
$cmd .= " ".$prfData->{$day}->{"time"}[$i]." ".$prfData->{$day}->{"temp"}[$i];
|
||||||
}
|
}
|
||||||
$cmd .= ($k < $dayCnt-1) ? "; ": "";
|
$cmd .= ($k < $dayCnt-1) ? "; ": "";
|
||||||
$k++;
|
$k++;
|
||||||
@ -361,10 +390,10 @@ sub weekprofile_sendDevProfile(@)
|
|||||||
my $dpTime = "P1_ENDTIME_$reading";
|
my $dpTime = "P1_ENDTIME_$reading";
|
||||||
my $dpTemp = "P1_TEMPERATURE_$reading";
|
my $dpTemp = "P1_TEMPERATURE_$reading";
|
||||||
|
|
||||||
my $tmpCnt = scalar(@{$prf->{DATA}->{$day}->{"temp"}});
|
my $tmpCnt = scalar(@{$prfData->{$day}->{"temp"}});
|
||||||
for (my $i = 0; $i < $tmpCnt; $i++) {
|
for (my $i = 0; $i < $tmpCnt; $i++) {
|
||||||
$cmd .= " " . $dpTemp . "_" . ($i + 1) . "=" . $prf->{DATA}->{$day}->{"temp"}[$i];
|
$cmd .= " " . $dpTemp . "_" . ($i + 1) . "=" . $prfData->{$day}->{"temp"}[$i];
|
||||||
$cmd .= " " . $dpTime . "_" . ($i + 1) . "=" . weekprofile_timeToMinutes($prf->{DATA}->{$day}->{"time"}[$i]);
|
$cmd .= " " . $dpTime . "_" . ($i + 1) . "=" . weekprofile_timeToMinutes($prfData->{$day}->{"time"}[$i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#$cmd .= ($k < $dayCnt-1) ? "; ": "";
|
#$cmd .= ($k < $dayCnt-1) ? "; ": "";
|
||||||
@ -1031,12 +1060,12 @@ sub weekprofile_Attr($$$)
|
|||||||
return if (!defined($attrVal));
|
return if (!defined($attrVal));
|
||||||
|
|
||||||
Log3 $me, 5, "$me(weekprofile_Attr): $cmd, $attrName, $attrVal";
|
Log3 $me, 5, "$me(weekprofile_Attr): $cmd, $attrName, $attrVal";
|
||||||
|
|
||||||
$attr{$me}{$attrName} = $attrVal;
|
$attr{$me}{$attrName} = $attrVal;
|
||||||
weekprofile_writeProfilesToFile($hash) if ($attrName eq 'configFile');
|
weekprofile_writeProfilesToFile($hash) if ($attrName eq 'configFile');
|
||||||
|
|
||||||
if ($attrName eq 'tempON') {
|
if ($attrName eq 'tempON') {
|
||||||
my $tempOFF = AttrVal($me, "tempOFF", $attrVal);
|
my $tempOFF = myAttrVal($me, "tempOFF", $attrVal);
|
||||||
if ($tempOFF > $attrVal) {
|
if ($tempOFF > $attrVal) {
|
||||||
Log3 $me, 2, "$me(weekprofile_Attr): warning: tempON must be bigger than tempOFF";
|
Log3 $me, 2, "$me(weekprofile_Attr): warning: tempON must be bigger than tempOFF";
|
||||||
|
|
||||||
@ -1044,7 +1073,7 @@ sub weekprofile_Attr($$$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($attrName eq 'tempOFF') {
|
if ($attrName eq 'tempOFF') {
|
||||||
my $tempON = AttrVal($me, "tempON", $attrVal);
|
my $tempON = myAttrVal($me, "tempON", $attrVal);
|
||||||
if ($tempON < $attrVal) {
|
if ($tempON < $attrVal) {
|
||||||
Log3 $me, 2, "$me(weekprofile_Attr): warning: tempOFF must be smaller than tempON";
|
Log3 $me, 2, "$me(weekprofile_Attr): warning: tempOFF must be smaller than tempON";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user