2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-05 18:16:44 +00:00

50_HP1000.pm: add solarradiation, attribute extSrvPush_Url and change compasspoints to short notation

git-svn-id: https://svn.fhem.de/fhem/trunk@12323 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2016-10-11 10:57:47 +00:00
parent 740496bb26
commit e585cd6e52

View File

@ -34,7 +34,6 @@ use Time::Local;
use Data::Dumper; use Data::Dumper;
use List::Util qw(sum); use List::Util qw(sum);
use FHEM::98_dewpoint; use FHEM::98_dewpoint;
use FHEM::59_Twilight;
sub HP1000_Define($$); sub HP1000_Define($$);
sub HP1000_Undefine($$); sub HP1000_Undefine($$);
@ -69,7 +68,8 @@ sub HP1000_Initialize($) {
$hash->{DefFn} = "HP1000_Define"; $hash->{DefFn} = "HP1000_Define";
$hash->{UndefFn} = "HP1000_Undefine"; $hash->{UndefFn} = "HP1000_Undefine";
$hash->{AttrList} = $hash->{AttrList} =
"wu_push:1,0 wu_id wu_password wu_realtime:1,0 " . $readingFnAttributes; "wu_push:1,0 wu_id wu_password wu_realtime:1,0 extSrvPush_Url "
. $readingFnAttributes;
} }
################################### ###################################
@ -216,7 +216,6 @@ sub HP1000_CGI() {
$p = "temperatureIndoor" if ( $p eq "intemp" ); $p = "temperatureIndoor" if ( $p eq "intemp" );
$p = "humidity" if ( $p eq "outhumi" ); $p = "humidity" if ( $p eq "outhumi" );
$p = "temperature" if ( $p eq "outtemp" ); $p = "temperature" if ( $p eq "outtemp" );
$p = "luminosity" if ( $p eq "light" );
$p = "pressure" if ( $p eq "relbaro" ); $p = "pressure" if ( $p eq "relbaro" );
$p = "pressureAbs" if ( $p eq "absbaro" ); $p = "pressureAbs" if ( $p eq "absbaro" );
$p = "rain" if ( $p eq "rainrate" ); $p = "rain" if ( $p eq "rainrate" );
@ -229,6 +228,7 @@ sub HP1000_CGI() {
$p = "windDir" if ( $p eq "winddir" ); $p = "windDir" if ( $p eq "winddir" );
$p = "windGust" if ( $p eq "windgust" ); $p = "windGust" if ( $p eq "windgust" );
$p = "windSpeed" if ( $p eq "windspeed" ); $p = "windSpeed" if ( $p eq "windspeed" );
$p = "luminosity" if ( $p eq "light" );
readingsBulkUpdate( $hash, $p, $v ); readingsBulkUpdate( $hash, $p, $v );
} }
@ -236,19 +236,20 @@ sub HP1000_CGI() {
# calculated readings # calculated readings
# #
# uvIndex # UVindex (convert from uW/cm2)
# Forum https://forum.fhem.de/index.php/topic,44403.msg501704.html#msg501704 # Forum topic,44403.msg501704.html#msg501704
if ( defined( $webArgs->{UV} ) ) { if ( defined( $webArgs->{UV} ) ) {
my $v = floor( ( $webArgs->{UV} - 100 ) / 450 + 1 ); $webArgs->{UVindex} = floor( ( $webArgs->{UV} - 100 ) / 450 + 1 );
readingsBulkUpdate( $hash, "uvIndex", $v ); readingsBulkUpdate( $hash, "uvIndex", $webArgs->{UVindex} );
} }
# # luminosity2 # solarradiation in w/m2 (convert from lux)
# # Forum https://forum.fhem.de/index.php/topic,44403.msg501704.html#msg501704 # Forum topic,44403.msg501704.html#msg501704
# if ( defined( $webArgs->{light} ) ) { if ( defined( $webArgs->{light} ) ) {
# my $v = round( $webArgs->{light} / 126.7 * 10 ) / 10; $webArgs->{solarradiation} = round( $webArgs->{light} / 126.7, 1 );
# readingsBulkUpdate( $hash, "luminosity2", $v ); readingsBulkUpdate( $hash, "solarradiation",
# } $webArgs->{solarradiation} );
}
# dewpointIndoor # dewpointIndoor
if ( defined( $webArgs->{intemp} ) && defined( $webArgs->{inhumi} ) ) { if ( defined( $webArgs->{intemp} ) && defined( $webArgs->{inhumi} ) ) {
@ -257,8 +258,9 @@ sub HP1000_CGI() {
? 110 ? 110
: ( $webArgs->{inhumi} <= 0 ? 0.01 : $webArgs->{inhumi} ) : ( $webArgs->{inhumi} <= 0 ? 0.01 : $webArgs->{inhumi} )
); );
my $v = sprintf( '%0.1f', dewpoint_dewpoint( $webArgs->{intemp}, $h ) ); $webArgs->{dewpointin} =
readingsBulkUpdate( $hash, "dewpointIndoor", $v ); round( dewpoint_dewpoint( $webArgs->{intemp}, $h ), 1 );
readingsBulkUpdate( $hash, "dewpointIndoor", $webArgs->{dewpointin} );
} }
# humidityAbs # humidityAbs
@ -268,8 +270,9 @@ sub HP1000_CGI() {
? 110 ? 110
: ( $webArgs->{outhumi} <= 0 ? 0.01 : $webArgs->{outhumi} ) : ( $webArgs->{outhumi} <= 0 ? 0.01 : $webArgs->{outhumi} )
); );
my $v = int( dewpoint_absFeuchte( $webArgs->{outtemp}, $h ) + 0.5 ); $webArgs->{outhumiabs} =
readingsBulkUpdate( $hash, "humidityAbs", $v ); round( dewpoint_absFeuchte( $webArgs->{outtemp}, $h ), 1 );
readingsBulkUpdate( $hash, "humidityAbs", $webArgs->{outhumiabs} );
} }
# humidityIndoorAbs # humidityIndoorAbs
@ -279,45 +282,44 @@ sub HP1000_CGI() {
? 110 ? 110
: ( $webArgs->{inhumi} <= 0 ? 0.01 : $webArgs->{inhumi} ) : ( $webArgs->{inhumi} <= 0 ? 0.01 : $webArgs->{inhumi} )
); );
my $v = int( dewpoint_absFeuchte( $webArgs->{intemp}, $h ) + 0.5 ); $webArgs->{inhumiabs} =
readingsBulkUpdate( $hash, "humidityIndoorAbs", $v ); round( dewpoint_absFeuchte( $webArgs->{intemp}, $h ), 1 );
readingsBulkUpdate( $hash, "humidityIndoorAbs", $webArgs->{inhumiabs} );
} }
# windCompasspoint # windCompasspoint
if ( defined( $webArgs->{winddir} ) ) { if ( defined( $webArgs->{winddir} ) ) {
my $v = Twilight_CompassPoint( $webArgs->{winddir} ); $webArgs->{windcompasspoint} =
readingsBulkUpdate( $hash, "windCompasspoint", $v ); HP1000_CompassPoint( $webArgs->{winddir} );
$webArgs->{windCompasspoint} = $v; readingsBulkUpdate( $hash, "windCompasspoint",
$webArgs->{windcompasspoint} );
} }
# windSpeedForce in Beaufort # windSpeedForce in Beaufort
if ( defined( $webArgs->{windspeed} ) ) { if ( defined( $webArgs->{windspeed} ) ) {
my $v = HP1000_windForce( $webArgs->{windspeed} ); $webArgs->{windspeedforce} = HP1000_windForce( $webArgs->{windspeed} );
readingsBulkUpdate( $hash, "windSpeedForce", $v ); readingsBulkUpdate( $hash, "windSpeedForce",
$webArgs->{windSpeedForce} = $v; $webArgs->{windspeedforce} );
} }
# windGustForce in Beaufort # windGustForce in Beaufort
if ( defined( $webArgs->{windgust} ) ) { if ( defined( $webArgs->{windgust} ) ) {
my $v = HP1000_windForce( $webArgs->{windgust} ); $webArgs->{windfustforce} = HP1000_windForce( $webArgs->{windgust} );
readingsBulkUpdate( $hash, "windGustForce", $v ); readingsBulkUpdate( $hash, "windGustForce", $webArgs->{windfustforce} );
$webArgs->{windGustForce} = $v;
} }
# windSpeedMps in m/s # windSpeedMps in m/s
if ( defined( $webArgs->{windspeed} ) ) { if ( defined( $webArgs->{windspeed} ) ) {
my $v = HP1000_windKmh2Mps( $webArgs->{windspeed} ); my $v = HP1000_windKmh2Mps( $webArgs->{windspeed} );
$v = ( $v > 0.5 ? sprintf( '%0.1f', $v ) : "0.0" ); $webArgs->{windspeedmps} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsBulkUpdate( $hash, "windSpeedMps", $v ); readingsBulkUpdate( $hash, "windSpeedMps", $webArgs->{windspeedmps} );
$webArgs->{windSpeedMps} = $v;
} }
# windGustMps in m/s # windGustMps in m/s
if ( defined( $webArgs->{windgust} ) ) { if ( defined( $webArgs->{windgust} ) ) {
my $v = HP1000_windKmh2Mps( $webArgs->{windgust} ); my $v = HP1000_windKmh2Mps( $webArgs->{windgust} );
$v = ( $v > 0.5 ? sprintf( '%0.1f', $v ) : "0.0" ); $webArgs->{windgustmps} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsBulkUpdate( $hash, "windGustMps", $v ); readingsBulkUpdate( $hash, "windGustMps", $webArgs->{windgustmps} );
$webArgs->{windgust} = $v;
} }
# averages/windSpeed_avg2m # averages/windSpeed_avg2m
@ -343,17 +345,19 @@ sub HP1000_CGI() {
# averages/windSpeedForce_avg2m in Beaufort # averages/windSpeedForce_avg2m in Beaufort
if ( defined( $webArgs->{windspd_avg2m} ) ) { if ( defined( $webArgs->{windspd_avg2m} ) ) {
my $v = HP1000_windForce( $webArgs->{windspd_avg2m} ); $webArgs->{windspdforce_avg2m} =
readingsBulkUpdate( $hash, "windSpeedForce_avg2m", $v ); HP1000_windForce( $webArgs->{windspd_avg2m} );
$webArgs->{windSpeedForce_avg2m} = $v; readingsBulkUpdate( $hash, "windSpeedForce_avg2m",
$webArgs->{windspdforce_avg2m} );
} }
# averages/windSpeedMps_avg2m in m/s # averages/windSpeedMps_avg2m in m/s
if ( defined( $webArgs->{windspd_avg2m} ) ) { if ( defined( $webArgs->{windspd_avg2m} ) ) {
my $v = HP1000_windKmh2Mps( $webArgs->{windspd_avg2m} ); my $v = HP1000_windKmh2Mps( $webArgs->{windspd_avg2m} );
$v = ( $v > 0.5 ? sprintf( '%0.1f', $v ) : "0.0" ); $webArgs->{windspdmps_avg2m} =
readingsBulkUpdate( $hash, "windSpeedMps_avg2m", $v ); ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
$webArgs->{windspdmps_avg2m} = $v; readingsBulkUpdate( $hash, "windSpeedMps_avg2m",
$webArgs->{windspdmps_avg2m} );
} }
# averages/windDir_avg2m # averages/windDir_avg2m
@ -369,9 +373,10 @@ sub HP1000_CGI() {
# averages/windCompasspoint_avg2m # averages/windCompasspoint_avg2m
if ( defined( $webArgs->{winddir_avg2m} ) ) { if ( defined( $webArgs->{winddir_avg2m} ) ) {
my $v = Twilight_CompassPoint( $webArgs->{winddir_avg2m} ); $webArgs->{windcompasspoint_avg2m} =
readingsBulkUpdate( $hash, "windCompasspoint_avg2m", $v ); HP1000_CompassPoint( $webArgs->{winddir_avg2m} );
$webArgs->{windCompasspoint_avg2m} = $v; readingsBulkUpdate( $hash, "windCompasspoint_avg2m",
$webArgs->{windcompasspoint_avg2m} );
} }
# averages/windGust_sum10m # averages/windGust_sum10m
@ -395,28 +400,19 @@ sub HP1000_CGI() {
} }
} }
# from WU API: # from WU API - can we somehow calculate these as well?
# weather - [text] -- metar style (+RA) # weather - [text] -- metar style (+RA)
# clouds - [text] -- SKC, FEW, SCT, BKN, OVC # clouds - [text] -- SKC, FEW, SCT, BKN, OVC
# soiltempf - [F soil temperature] # soiltempf - [F soil temperature]
# soilmoisture - [%] # soilmoisture - [%]
# leafwetness - [%] # leafwetness - [%]
# visibility - [nm visibility] # visibility - [nm visibility]
# condition_forecast (based on pressure trendency) # condition_forecast (based on pressure trendency)
# day/night # day/night
# isRaining # isRaining
# solarRadiation
# soilTemperature # soilTemperature
# brightness in % ?? # brightness in % ??
# uv_index, uv_risk
if ( defined( $webArgs->{UV} ) ) {
my $wavelength = $webArgs->{UV};
}
$result = "T: " . $webArgs->{outtemp} $result = "T: " . $webArgs->{outtemp}
if ( defined( $webArgs->{outtemp} ) ); if ( defined( $webArgs->{outtemp} ) );
$result .= " H: " . $webArgs->{outhumi} $result .= " H: " . $webArgs->{outhumi}
@ -453,8 +449,12 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{relbaro} ) ); if ( defined( $webArgs->{relbaro} ) );
$result .= " UV: " . $webArgs->{UV} $result .= " UV: " . $webArgs->{UV}
if ( defined( $webArgs->{UV} ) ); if ( defined( $webArgs->{UV} ) );
$result .= " UVi: " . $webArgs->{UVindex}
if ( defined( $webArgs->{UVindex} ) );
$result .= " L: " . $webArgs->{light} $result .= " L: " . $webArgs->{light}
if ( defined( $webArgs->{light} ) ); if ( defined( $webArgs->{light} ) );
$result .= " SR: " . $webArgs->{solarradiation}
if ( defined( $webArgs->{solarradiation} ) );
readingsBulkUpdate( $hash, "state", $result ); readingsBulkUpdate( $hash, "state", $result );
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
@ -462,6 +462,9 @@ sub HP1000_CGI() {
HP1000_PushWU( $hash, $webArgs ) HP1000_PushWU( $hash, $webArgs )
if AttrVal( $name, "wu_push", 0 ) eq "1"; if AttrVal( $name, "wu_push", 0 ) eq "1";
HP1000_PushSrv( $hash, $webArgs )
if AttrVal( $name, "extSrvPush_Url", undef );
return ( "text/plain; charset=utf-8", "success" ); return ( "text/plain; charset=utf-8", "success" );
} }
@ -503,6 +506,51 @@ sub HP1000_GetSum($$$$;$) {
return $return; return $return;
} }
###################################
sub HP1000_PushSrv($$) {
my ( $hash, $webArgs ) = @_;
my $name = $hash->{NAME};
my $timeout = AttrVal( $name, "timeout", 7 );
my $http_noshutdown = AttrVal( $name, "http-noshutdown", "1" );
my $srv_url = AttrVal( $name, "extSrvPush_Url", "" );
my $cmd = "";
Log3 $name, 5, "HP1000 $name: called function HP1000_PushSrv()";
if ( $srv_url !~
/(https?):\/\/([\w\.]+):?(\d+)?([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?/
)
{
return;
}
elsif ( $4 !~ /\?/ ) {
$cmd = "?";
}
else {
$cmd = "&";
}
while ( my ( $key, $value ) = each %{$webArgs} ) {
$cmd .= "$key=" . $value . "&";
}
Log3 $name, 4,
"HP1000 $name: pushing data to external Server: $srv_url$cmd";
HttpUtils_NonblockingGet(
{
url => $srv_url . $cmd,
timeout => $timeout,
noshutdown => $http_noshutdown,
data => undef,
hash => $hash,
callback => \&HP1000_ReturnSrv,
}
);
return;
}
################################### ###################################
sub HP1000_PushWU($$) { sub HP1000_PushWU($$) {
@ -627,12 +675,7 @@ sub HP1000_PushWU($$) {
0.000295299830714; # convert from hPa to Inches of Mercury 0.000295299830714; # convert from hPa to Inches of Mercury
} }
elsif ( $key eq "light" ) { elsif ( $key eq "UVindex" ) {
$key = "solarradiation";
$value = $value * 0.01; # convert from uW/cm2 to W/m2
}
elsif ( $key eq "uvIndex" ) {
$key = "UV"; $key = "UV";
$value = $value; $value = $value;
} }
@ -660,6 +703,40 @@ sub HP1000_PushWU($$) {
return; return;
} }
###################################
sub HP1000_ReturnSrv($$$) {
my ( $param, $err, $data ) = @_;
my $hash = $param->{hash};
my $name = $hash->{NAME};
# device not reachable
if ($err) {
my $return = "error: connection timeout";
Log3 $name, 4, "HP1000 $name: EXTSRV HTTP " . $return;
readingsSingleUpdate( $hash, "extsrv_state", $return, 1 )
if ( ReadingsVal( $name, "extsrv_state", "" ) ne $return );
}
# data received
elsif ($data) {
my $logprio = 5;
my $return = "ok";
if ( $param->{code} ne "200" ) {
$logprio = 4;
$return = "error " . $param->{code} . ": $data";
}
Log3 $name, $logprio,
"HP1000 $name: EXTSRV HTTP return: " . $param->{code} . " - $data";
readingsSingleUpdate( $hash, "extsrv_state", $return, 1 )
if ( ReadingsVal( $name, "extsrv_state", "" ) ne $return );
}
return;
}
################################### ###################################
sub HP1000_ReturnWU($$$) { sub HP1000_ReturnWU($$$) {
my ( $param, $err, $data ) = @_; my ( $param, $err, $data ) = @_;
@ -741,6 +818,63 @@ sub HP1000_windForce($) {
return $v; return $v;
} }
sub HP1000_CompassPoint($) {
my ($azimuth) = @_;
my $compassPoint = "";
if ( $azimuth < 22.5 ) {
$compassPoint = "N";
}
elsif ( $azimuth < 45 ) {
$compassPoint = "NNE";
}
elsif ( $azimuth < 67.5 ) {
$compassPoint = "NE";
}
elsif ( $azimuth < 90 ) {
$compassPoint = "ENE";
}
elsif ( $azimuth < 112.5 ) {
$compassPoint = "E";
}
elsif ( $azimuth < 135 ) {
$compassPoint = "ESE";
}
elsif ( $azimuth < 157.5 ) {
$compassPoint = "SE";
}
elsif ( $azimuth < 180 ) {
$compassPoint = "SSE";
}
elsif ( $azimuth < 202.5 ) {
$compassPoint = "S";
}
elsif ( $azimuth < 225 ) {
$compassPoint = "SSW";
}
elsif ( $azimuth < 247.5 ) {
$compassPoint = "SW";
}
elsif ( $azimuth < 270 ) {
$compassPoint = "WSW";
}
elsif ( $azimuth < 292.5 ) {
$compassPoint = "W";
}
elsif ( $azimuth < 315 ) {
$compassPoint = "WNW";
}
elsif ( $azimuth < 337.5 ) {
$compassPoint = "NW";
}
elsif ( $azimuth <= 361 ) {
$compassPoint = "NNW";
}
return $compassPoint;
}
################################### ###################################
sub HP1000_windKmh2Mps($) { sub HP1000_windKmh2Mps($) {
my ($data) = @_; my ($data) = @_;