2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-28 17:12:32 +00:00

UConv: fix clima condition calculation

git-svn-id: https://svn.fhem.de/fhem/trunk@19396 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2019-05-18 10:51:41 +00:00
parent 3756372728
commit 6e61e59b3b

View File

@ -228,7 +228,7 @@ our %sdt2daytimes = (
} }
}, },
# AUTUMN SEASON # FALL SEASON
2 => { 2 => {
# DST = no # DST = no
@ -265,7 +265,7 @@ our %sdt2daytimes = (
); );
our %seasons = ( our %seasons = (
en => [ "Spring", "Summer", "Autumn", "Winter", ], en => [ "Spring", "Summer", "Fall", "Winter", ],
de => [ "Frühling", "Sommer", "Herbst", "Winter", ], de => [ "Frühling", "Sommer", "Herbst", "Winter", ],
nl => [ "Voorjaar", "Zomer", "Herfst", "Winter", ], nl => [ "Voorjaar", "Zomer", "Herfst", "Winter", ],
fr => [ "Printemps", "Été", "Automne", "Hiver", ], fr => [ "Printemps", "Été", "Automne", "Hiver", ],
@ -282,8 +282,8 @@ our %seasonsPheno = (
"Midsummer", "Midsummer",
"Late Summer", "Late Summer",
"Early Fall", "Early Fall",
"Autumn", "Fall",
"Late Autumn", "Late Fall",
"Winter", "Winter",
], ],
de => [ de => [
@ -459,131 +459,35 @@ our %dateformatss = (
# https://www.luftfeuchtigkeit-raumklima.de/tabelle.php # https://www.luftfeuchtigkeit-raumklima.de/tabelle.php
our %ideal_clima = ( our %ideal_clima = (
bathroom => { bathroom => {
c => { c => [ -273.15, 6, 16, 20, 23, 27, ],
'273.15' => 0, h => [ 0, 40, 50, 70, 80 ],
'6' => 1,
'16' => 2,
'20' => 3,
'23' => 4,
'27' => 5,
},
h => {
'0' => 0,
'40' => 1,
'50' => 2,
'70' => 3,
'80' => 4,
},
}, },
living => { living => {
c => { c => [ -273.15, 6, 16, 20, 23, 27, ],
'273.15' => 0, h => [ 0, 30, 40, 60, 70 ],
'6' => 1,
'16' => 2,
'20' => 3,
'23' => 4,
'27' => 5,
},
h => {
'0' => 0,
'30' => 1,
'40' => 2,
'60' => 3,
'70' => 4,
},
}, },
kitchen => { kitchen => {
c => { c => [ -273.15, 6, 16, 18, 20, 27, ],
'273.15' => 0, h => [ 0, 40, 50, 60, 70 ],
'6' => 1,
'16' => 2,
'18' => 3,
'20' => 4,
'27' => 5,
},
h => {
'0' => 0,
'40' => 1,
'50' => 2,
'60' => 3,
'70' => 4,
},
}, },
bedroom => { bedroom => {
c => { c => [ -273.15, 6, 12, 17, 20, 23, ],
'273.15' => 0, h => [ 0, 30, 40, 60, 70 ],
'6' => 1,
'12' => 2,
'17' => 3,
'20' => 4,
'23' => 5,
},
h => {
'0' => 0,
'30' => 1,
'40' => 2,
'60' => 3,
'70' => 4,
},
}, },
hallway => { hallway => {
c => { c => [ -273.15, 6, 12, 15, 18, 23, ],
'273.15' => 0, h => [ 0, 30, 40, 60, 70 ],
'6' => 1,
'12' => 2,
'15' => 3,
'18' => 4,
'23' => 5,
},
h => {
'0' => 0,
'30' => 1,
'40' => 2,
'60' => 3,
'70' => 4,
},
}, },
cellar => { cellar => {
c => { c => [ -273.15, 6, 7, 10, 15, 20, ],
'273.15' => 0, h => [ 0, 40, 50, 60, 70 ],
'6' => 1,
'7' => 2,
'10' => 3,
'15' => 4,
'20' => 5,
},
h => {
'0' => 0,
'40' => 1,
'50' => 2,
'60' => 3,
'70' => 4,
},
}, },
outdoor => { outdoor => {
c => { c => [ -273.15, 2.5, 5, 14, 30, 35, ],
'273.15' => 0, h => [ 0, 40, 50, 70, 80 ],
'2.5' => 1,
'5' => 2,
'14' => 3,
'30' => 4,
'35' => 5,
},
h => {
'0' => 0,
'40' => 1,
'50' => 2,
'70' => 3,
'80' => 4,
},
}, },
); );
our %clima_rgb = (
c => [ "0055BB", "0066CC", "009999", "4C9329", "E7652B", "C72A23" ],
h => [ "C72A23", "E7652B", "4C9329", "009999", "0066CC" ],
);
our %clima_names = ( our %clima_names = (
c => { c => {
en => [ "freeze", "cold", "low", "ideal", "high", "hot" ], en => [ "freeze", "cold", "low", "ideal", "high", "hot" ],
@ -592,13 +496,15 @@ our %clima_names = (
fr => [ "froid", "froid", "faible", "optimal", "haut", "chaud" ], fr => [ "froid", "froid", "faible", "optimal", "haut", "chaud" ],
pl => pl =>
[ "chłodny", "zimno", "niski", "optymalny", "wysoki", "gorący" ], [ "chłodny", "zimno", "niski", "optymalny", "wysoki", "gorący" ],
rgb => [ "0055BB", "0066CC", "009999", "4C9329", "E7652B", "C72A23" ],
}, },
h => { h => {
en => [ "dry", "low", "ideal", "high", "wet" ], en => [ "dry", "low", "ideal", "high", "wet" ],
de => [ "trocken", "niedrig", "optimal", "hoch", "nass" ], de => [ "trocken", "niedrig", "optimal", "hoch", "nass" ],
nl => [ "droog", "laag", "optimale", "hoog", "nat" ], nl => [ "droog", "laag", "optimale", "hoog", "nat" ],
fr => [ "sec", "faible", "optimal", "haut", "humide" ], fr => [ "sec", "faible", "optimal", "haut", "humide" ],
pl => [ "suchy", "niski", "optymalny", "wysoki", "mokro" ], pl => [ "suchy", "niski", "optymalny", "wysoki", "mokro" ],
rgb => [ "C72A23", "E7652B", "4C9329", "009999", "0066CC" ],
} }
); );
@ -1156,13 +1062,16 @@ sub c2condition($;$$) {
} }
if ( defined( $ideal_clima{$roomType} ) ) { if ( defined( $ideal_clima{$roomType} ) ) {
foreach my $th ( reverse sort keys %{ $ideal_clima{$roomType} } ) { my $i = 0;
if ( $data >= $th ) { foreach my $th ( @{ $ideal_clima{$roomType}{c} } ) {
my $i = $ideal_clima{$roomType}{$th}; if ( $data > $th ) {
$val = $clima_names{c}{$lang}[$i]; $val = $clima_names{c}{$lang}[$i];
$rgb = $clima_rgb{c}[$i]; $rgb = $clima_names{c}{rgb}[$i];
}
else {
last; last;
} }
$i++;
} }
} }
@ -1171,26 +1080,32 @@ sub c2condition($;$$) {
} }
# Condition: convert humidity (percent) to humidity condition # Condition: convert humidity (percent) to humidity condition
sub humidity2condition($;$) { sub humidity2condition($;$$) {
my ( $data, $indoor ) = @_; my ( $data, $roomType, $lang ) = @_;
my $val = "dry"; my $val = "?";
my $rgb = "C72A23"; my $rgb = "FFFFFF";
$lang = "en" if ( !$lang );
if ( $data >= 80 ) { if ($roomType) {
$val = "wet"; $roomType = "living"
$rgb = "0066CC"; if ( looks_like_number($roomType) );
} }
elsif ( $data >= 70 ) { else {
$val = "high"; $roomType = "outdoor";
$rgb = "009999";
} }
elsif ( $data >= 50 ) {
$val = "ideal"; if ( defined( $ideal_clima{$roomType} ) ) {
$rgb = "4C9329"; my $i = 0;
} foreach my $th ( @{ $ideal_clima{$roomType}{h} } ) {
elsif ( $data >= 40 ) { if ( $data > $th ) {
$val = "low"; $val = $clima_names{h}{$lang}[$i];
$rgb = "E7652B"; $rgb = $clima_names{h}{rgb}[$i];
}
else {
last;
}
$i++;
}
} }
return ( $val, $rgb ) if (wantarray); return ( $val, $rgb ) if (wantarray);
@ -1472,8 +1387,6 @@ sub GetDaytime(;$$$$) {
$ret = GetSeason( $ret, $lang ); $ret = GetSeason( $ret, $lang );
$ret = _GetSeasonPheno( $ret, $lang ); $ret = _GetSeasonPheno( $ret, $lang );
#$ret = GetSeasonSocial( $ret, $lang ); #TODO https://de.wikipedia.org/wiki/F%C3%BCnfte_Jahreszeit
# change midnight event when season changes # change midnight event when season changes
$ret->{events}{ $ret->{midnight_t} }{VALUE} = 1 $ret->{events}{ $ret->{midnight_t} }{VALUE} = 1
if ( $ret->{seasonMeteoChng} && $ret->{seasonMeteoChng} == 1 ); if ( $ret->{seasonMeteoChng} && $ret->{seasonMeteoChng} == 1 );
@ -1687,22 +1600,31 @@ sub GetSeason (;$$$) {
$l =~ s/^([a-z]+).*/$1/g; $l =~ s/^([a-z]+).*/$1/g;
next unless ( $seasons{$l} ); next unless ( $seasons{$l} );
if ($l eq 'en') { if ( $l eq 'en' ) {
$ret->{'-1'}{seasonMeteo_long} = $seasons{$l}[ $ret->{'-1'}{seasonMeteo} ]; $ret->{'-1'}{seasonMeteo_long} =
$ret->{seasonMeteo_long} = $seasons{$l}[ $ret->{seasonMeteo} ]; $seasons{$l}[ $ret->{'-1'}{seasonMeteo} ];
$ret->{1}{seasonMeteo_long} = $seasons{$l}[ $ret->{1}{seasonMeteo} ]; $ret->{seasonMeteo_long} = $seasons{$l}[ $ret->{seasonMeteo} ];
$ret->{1}{seasonMeteo_long} =
$seasons{$l}[ $ret->{1}{seasonMeteo} ];
$ret->{'-1'}{seasonAstro_long} = $seasons{$l}[ $ret->{'-1'}{seasonAstro} ]; $ret->{'-1'}{seasonAstro_long} =
$ret->{seasonAstro_long} = $seasons{$l}[ $ret->{seasonAstro} ]; $seasons{$l}[ $ret->{'-1'}{seasonAstro} ];
$ret->{1}{seasonAstro_long} = $seasons{$l}[ $ret->{1}{seasonAstro} ]; $ret->{seasonAstro_long} = $seasons{$l}[ $ret->{seasonAstro} ];
} else { $ret->{1}{seasonAstro_long} =
$ret->{'-1'}{$l}{seasonMeteo_long} = $seasons{$l}[ $ret->{'-1'}{seasonMeteo} ]; $seasons{$l}[ $ret->{1}{seasonAstro} ];
$ret->{$l}{seasonMeteo_long} = $seasons{$l}[ $ret->{seasonMeteo} ]; }
$ret->{1}{$l}{seasonMeteo_long} = $seasons{$l}[ $ret->{1}{seasonMeteo} ]; else {
$ret->{'-1'}{$l}{seasonMeteo_long} =
$seasons{$l}[ $ret->{'-1'}{seasonMeteo} ];
$ret->{$l}{seasonMeteo_long} = $seasons{$l}[ $ret->{seasonMeteo} ];
$ret->{1}{$l}{seasonMeteo_long} =
$seasons{$l}[ $ret->{1}{seasonMeteo} ];
$ret->{'-1'}{$l}{seasonAstro_long} = $seasons{$l}[ $ret->{'-1'}{seasonAstro} ]; $ret->{'-1'}{$l}{seasonAstro_long} =
$ret->{$l}{seasonAstro_long} = $seasons{$l}[ $ret->{seasonAstro} ]; $seasons{$l}[ $ret->{'-1'}{seasonAstro} ];
$ret->{1}{$l}{seasonAstro_long} = $seasons{$l}[ $ret->{1}{seasonAstro} ]; $ret->{$l}{seasonAstro_long} = $seasons{$l}[ $ret->{seasonAstro} ];
$ret->{1}{$l}{seasonAstro_long} =
$seasons{$l}[ $ret->{1}{seasonAstro} ];
} }
} }
@ -1755,7 +1677,7 @@ sub _GetSeasonPheno ($$;$$) {
my $ret; my $ret;
if ( ref($time) eq "HASH" ) { if ( ref($time) eq "HASH" ) {
$ret = $time; $ret = $time;
} }
else { else {
$ret = _time($time); $ret = _time($time);
@ -1766,28 +1688,28 @@ sub _GetSeasonPheno ($$;$$) {
# stick to astro season first # stick to astro season first
my $index = $seasons{pheno}[ $ret->{seasonAstro} ]; my $index = $seasons{pheno}[ $ret->{seasonAstro} ];
# meteos say it's spring time # meteos say its spring time
if ( $ret->{seasonMeteo} == 0 ) { if ( $ret->{seasonMeteo} == 0 ) {
$index = 0; $index = 0;
} }
# meteos say it's summer time # meteos say its summer time
elsif ( $ret->{seasonMeteo} == 1 ) { elsif ( $ret->{seasonMeteo} == 1 ) {
$index = 3; $index = 3;
} }
# meteos say it's autumn time # meteos say its fall time
elsif ( $ret->{seasonMeteo} == 2 ) { elsif ( $ret->{seasonMeteo} == 2 ) {
$index = 6; $index = 6;
} }
# meteos say it's winter time # meteos say its winter time
elsif ( $ret->{seasonMeteo} == 3 ) { elsif ( $ret->{seasonMeteo} == 3 ) {
$index = 9; $index = 9;
} }
# if we know our position and spring is ahead # if we know our position and spring is ahead
if ( ( $index == 0 || $index == 1 ) if ( ( $index == 0 || $index == 1 || $index == 2 )
&& $main::attr{global}{latitude} && $main::attr{global}{latitude}
&& $main::attr{global}{longitude} ) && $main::attr{global}{longitude} )
{ {
@ -1818,7 +1740,7 @@ sub _GetSeasonPheno ($$;$$) {
} }
# assume spring progress from calendar # assume spring progress from calendar
elsif ( ( $index == 0 || $index == 1 ) ) { elsif ( ( $index == 0 || $index == 1 || $index == 2 ) ) {
$index = 1 if ( $ret->{monISO} == 4 ); $index = 1 if ( $ret->{monISO} == 4 );
$index = 2 if ( $ret->{monISO} == 5 ); $index = 2 if ( $ret->{monISO} == 5 );
} }
@ -1830,7 +1752,7 @@ sub _GetSeasonPheno ($$;$$) {
} }
# if we know our position and autumn is ahead # if we know our position and autumn is ahead
elsif (( $index == 6 || $index == 7 ) elsif (( $index == 6 || $index == 7 || $index == 8 )
&& $main::attr{global}{latitude} && $main::attr{global}{latitude}
&& $main::attr{global}{longitude} ) && $main::attr{global}{longitude} )
{ {
@ -1861,7 +1783,7 @@ sub _GetSeasonPheno ($$;$$) {
} }
# assume autumn progress from calendar # assume autumn progress from calendar
elsif ( ( $index == 6 || $index == 7 ) ) { elsif ( ( $index == 6 || $index == 7 || $index == 8 ) ) {
$index = 7 if ( $ret->{monISO} == 10 ); $index = 7 if ( $ret->{monISO} == 10 );
$index = 8 if ( $ret->{monISO} == 11 ); $index = 8 if ( $ret->{monISO} == 11 );
} }
@ -1869,10 +1791,18 @@ sub _GetSeasonPheno ($$;$$) {
$ret->{seasonPheno} = $index; $ret->{seasonPheno} = $index;
return ( $ret->{seasonPheno} ) if (wantarray); return ( $ret->{seasonPheno} ) if (wantarray);
( $ret->{'-1'}{seasonPheno} ) = ( $ret->{'-1'}{seasonPheno} ) = _GetSeasonPheno(
_GetSeasonPheno( $ret->{'-1'}{time_t}, $lang, $ret->{'-1'}{seasonAstro}, $ret->{'-1'}{seasonMeteo} ); $ret->{'-1'}{time_t},
( $ret->{1}{seasonPheno} ) = $lang,
_GetSeasonPheno( $ret->{1}{time_t}, $lang, $ret->{1}{seasonAstro}, $ret->{1}{seasonMeteo} ); $ret->{'-1'}{seasonAstro},
$ret->{'-1'}{seasonMeteo}
);
( $ret->{1}{seasonPheno} ) = _GetSeasonPheno(
$ret->{1}{time_t},
$lang,
$ret->{1}{seasonAstro},
$ret->{1}{seasonMeteo}
);
# text strings # text strings
my @langs = ('EN'); my @langs = ('EN');
@ -1882,14 +1812,20 @@ sub _GetSeasonPheno ($$;$$) {
$l =~ s/^([a-z]+).*/$1/g; $l =~ s/^([a-z]+).*/$1/g;
next unless ( $seasonsPheno{$l} ); next unless ( $seasonsPheno{$l} );
if ($l eq 'en') { if ( $l eq 'en' ) {
$ret->{'-1'}{seasonPheno_long} = $seasonsPheno{$l}[ $ret->{'-1'}{seasonPheno} ]; $ret->{'-1'}{seasonPheno_long} =
$ret->{seasonPheno_long} = $seasonsPheno{$l}[ $ret->{seasonPheno} ]; $seasonsPheno{$l}[ $ret->{'-1'}{seasonPheno} ];
$ret->{1}{seasonPheno_long} = $seasonsPheno{$l}[ $ret->{1}{seasonPheno} ]; $ret->{seasonPheno_long} = $seasonsPheno{$l}[ $ret->{seasonPheno} ];
} else { $ret->{1}{seasonPheno_long} =
$ret->{'-1'}{$l}{seasonPheno_long} = $seasonsPheno{$l}[ $ret->{'-1'}{seasonPheno} ]; $seasonsPheno{$l}[ $ret->{1}{seasonPheno} ];
$ret->{$l}{seasonPheno_long} = $seasonsPheno{$l}[ $ret->{seasonPheno} ]; }
$ret->{1}{$l}{seasonPheno_long} = $seasonsPheno{$l}[ $ret->{1}{seasonPheno} ]; else {
$ret->{'-1'}{$l}{seasonPheno_long} =
$seasonsPheno{$l}[ $ret->{'-1'}{seasonPheno} ];
$ret->{$l}{seasonPheno_long} =
$seasonsPheno{$l}[ $ret->{seasonPheno} ];
$ret->{1}{$l}{seasonPheno_long} =
$seasonsPheno{$l}[ $ret->{1}{seasonPheno} ];
} }
} }