mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 01:09:47 +00:00
Unit.pm: save units as attribute and add extended module support
git-svn-id: https://svn.fhem.de/fhem/trunk@12533 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
90629d8527
commit
fba06e6863
@ -72,6 +72,64 @@ sub HP1000_Initialize($) {
|
||||
$hash->{AttrList} =
|
||||
"wu_push:1,0 wu_id wu_password wu_realtime:1,0 extSrvPush_Url stateReadingsLang:en,de,at,ch,nl,fr,pl stateReadings stateReadingsFormat:0,1,2 "
|
||||
. $readingFnAttributes;
|
||||
|
||||
$hash->{readingsDesc} = {
|
||||
"UV" => { "unit" => "uvi", },
|
||||
"UVR" => { "unit" => "uwpscm", },
|
||||
"dewpoint" => { "unit" => "c", },
|
||||
"dewpoint_f" => { "unit" => "f", },
|
||||
"humidity" => { "unit" => "pct", },
|
||||
"humidityAbs" => { "unit" => "c", },
|
||||
"humidityAbs_f" => { "unit" => "f", },
|
||||
"indoorDewpoint" => { "unit" => "c", },
|
||||
"indoorDewpoint_f" => { "unit" => "f", },
|
||||
"indoorHumidity" => { "unit" => "pct", },
|
||||
"indoorHumidityAbs" => { "unit" => "c", },
|
||||
"indoorHumidityAbs_f" => { "unit" => "f", },
|
||||
"indoorTemperature" => { "unit" => "c", },
|
||||
"indoorTemperature_f" => { "unit" => "f", },
|
||||
"luminosity" => { "unit" => "lx", },
|
||||
"pressure" => { "unit" => "hpamb", },
|
||||
"pressureAbs_in" => { "unit" => "inhg", },
|
||||
"pressureAbs_mm" => { "unit" => "mmhg", },
|
||||
"pressure_in" => { "unit" => "inhg", },
|
||||
"pressure_mm" => { "unit" => "mmhg", },
|
||||
"rain" => { "unit" => "mm", },
|
||||
"rain_day" => { "unit" => "mm", },
|
||||
"rain_day_in" => { "unit" => "in", },
|
||||
"rain_in" => { "unit" => "in", },
|
||||
"rain_month" => { "unit" => "mm", },
|
||||
"rain_month_in" => { "unit" => "in", },
|
||||
"rain_week" => { "unit" => "mm", },
|
||||
"rain_week_in" => { "unit" => "in", },
|
||||
"rain_year" => { "unit" => "mm", },
|
||||
"rain_year_in" => { "unit" => "in", },
|
||||
"solarradiation" => { "unit" => "wpsm", },
|
||||
"temperature" => { "unit" => "c", },
|
||||
"temperature_f" => { "unit" => "f", },
|
||||
"wind_chill" => { "unit" => "c", },
|
||||
"wind_chill_f" => { "unit" => "f", },
|
||||
"wind_direction" => { "unit" => "gon", },
|
||||
"wind_direction_avg2m" => { "unit" => "gon", },
|
||||
"wind_gust" => { "unit" => "kmh", },
|
||||
"wind_gust_bft" => { "unit" => "bft", },
|
||||
"wind_gust_fts" => { "unit" => "fts", },
|
||||
"wind_gust_kn" => { "unit" => "kn", },
|
||||
"wind_gust_mph" => { "unit" => "mph", },
|
||||
"wind_gust_mph_sum10m" => { "unit" => "mph", },
|
||||
"wind_gust_mps" => { "unit" => "mps", },
|
||||
"wind_gust_sum10m" => { "unit" => "kmh", },
|
||||
"wind_speed" => { "unit" => "kmh", },
|
||||
"wind_speed_avg2m" => { "unit" => "kmh", },
|
||||
"wind_speed_bft" => { "unit" => "bft", },
|
||||
"wind_speed_bft_avg2m" => { "unit" => "bft", },
|
||||
"wind_speed_kn" => { "unit" => "kn", },
|
||||
"wind_speed_kn_avg2m" => { "unit" => "kn", },
|
||||
"wind_speed_mph" => { "unit" => "mph", },
|
||||
"wind_speed_mph_avg2m" => { "unit" => "mph", },
|
||||
"wind_speed_mps" => { "unit" => "mps", },
|
||||
"wind_speed_mps_avg2m" => { "unit" => "mps", },
|
||||
};
|
||||
}
|
||||
|
||||
###################################
|
||||
@ -222,9 +280,9 @@ sub HP1000_SetAliveState($;$) {
|
||||
my $activity = "dead";
|
||||
$activity = "alive" if ($alive);
|
||||
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "Activity", $activity );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged( $hash, "Activity", $activity );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
|
||||
InternalTimer( gettimeofday() + 120, "HP1000_SetAliveState", $hash, 0 );
|
||||
|
||||
@ -646,7 +704,7 @@ sub HP1000_CGI() {
|
||||
|
||||
# write general readings
|
||||
#
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
while ( ( my $p, my $v ) = each %$webArgs ) {
|
||||
|
||||
@ -709,7 +767,7 @@ sub HP1000_CGI() {
|
||||
$p = "wind_gust_mph" if ( $p eq "_windgustmph" );
|
||||
$p = "wind_speed_mph" if ( $p eq "_windspdmph" );
|
||||
|
||||
readingsUnitBulkUpdate( $hash, $p, $v );
|
||||
readingsBulkUpdate( $hash, $p, $v );
|
||||
}
|
||||
|
||||
# calculate additional readings
|
||||
@ -719,20 +777,20 @@ sub HP1000_CGI() {
|
||||
my $israining = 0;
|
||||
$israining = 1
|
||||
if ( defined( $webArgs->{rainrate} ) && $webArgs->{rainrate} > 0 );
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "israining", $israining );
|
||||
readingsBulkUpdateIfChanged( $hash, "israining", $israining );
|
||||
|
||||
# daylight
|
||||
my $daylight = 0;
|
||||
$daylight = 1
|
||||
if ( defined( $webArgs->{light} ) && $webArgs->{light} > 50 );
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "daylight", $daylight );
|
||||
readingsBulkUpdateIfChanged( $hash, "daylight", $daylight );
|
||||
|
||||
# condition
|
||||
if ( defined( $webArgs->{light} ) ) {
|
||||
my $temp = ( $webArgs->{outtemp} ? $webArgs->{outtemp} : "10" );
|
||||
my $hum = ( $webArgs->{outhumi} ? $webArgs->{outhumi} : "50" );
|
||||
|
||||
readingsUnitBulkUpdateIfChanged(
|
||||
readingsBulkUpdateIfChanged(
|
||||
$hash,
|
||||
"condition",
|
||||
UConv::values2weathercondition(
|
||||
@ -743,25 +801,25 @@ sub HP1000_CGI() {
|
||||
|
||||
# humidityCondition
|
||||
if ( defined( $webArgs->{outhumi} ) ) {
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "humidityCondition",
|
||||
readingsBulkUpdateIfChanged( $hash, "humidityCondition",
|
||||
UConv::humidity2condition( $webArgs->{outhumi} ) );
|
||||
}
|
||||
|
||||
# indoorHumidityCondition
|
||||
if ( defined( $webArgs->{inhumi} ) ) {
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "indoorHumidityCondition",
|
||||
readingsBulkUpdateIfChanged( $hash, "indoorHumidityCondition",
|
||||
UConv::humidity2condition( $webArgs->{inhumi} ) );
|
||||
}
|
||||
|
||||
# UV (convert from uW/cm2)
|
||||
if ( defined( $webArgs->{UV} ) ) {
|
||||
$webArgs->{UVI} = UConv::uwpscm2uvi( $webArgs->{UV} );
|
||||
readingsUnitBulkUpdate( $hash, "UV", $webArgs->{UVI}, "uvi" );
|
||||
readingsBulkUpdate( $hash, "UV", $webArgs->{UVI} );
|
||||
}
|
||||
|
||||
# UVcondition
|
||||
if ( defined( $webArgs->{UVI} ) ) {
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "UVcondition",
|
||||
readingsBulkUpdateIfChanged( $hash, "UVcondition",
|
||||
UConv::uvi2condition( $webArgs->{UVI} ) );
|
||||
}
|
||||
|
||||
@ -769,23 +827,21 @@ sub HP1000_CGI() {
|
||||
if ( defined( $webArgs->{light} ) ) {
|
||||
$webArgs->{solarradiation} =
|
||||
UConv::lux2wpsm( $webArgs->{light} );
|
||||
readingsUnitBulkUpdate( $hash, "solarradiation",
|
||||
$webArgs->{solarradiation}, "wpsm" );
|
||||
readingsBulkUpdate( $hash, "solarradiation",
|
||||
$webArgs->{solarradiation} );
|
||||
}
|
||||
|
||||
# pressure_mm in mmHg (convert from hpa)
|
||||
if ( defined( $webArgs->{relbaro} ) ) {
|
||||
$webArgs->{barommm} = UConv::hpa2mmhg( $webArgs->{relbaro} );
|
||||
readingsUnitBulkUpdate( $hash, "pressure_mm", $webArgs->{barommm},
|
||||
"mmhg" );
|
||||
readingsBulkUpdate( $hash, "pressure_mm", $webArgs->{barommm} );
|
||||
}
|
||||
|
||||
# pressureAbs_mm in mmHg (convert from hpa)
|
||||
if ( defined( $webArgs->{absbaro} ) ) {
|
||||
$webArgs->{absbarommm} =
|
||||
UConv::hpa2mmhg( $webArgs->{absbaro} );
|
||||
readingsUnitBulkUpdate( $hash, "pressureAbs_mm",
|
||||
$webArgs->{absbarommm}, "mmhg" );
|
||||
readingsBulkUpdate( $hash, "pressureAbs_mm", $webArgs->{absbarommm} );
|
||||
}
|
||||
|
||||
# indoorDewpoint in Celsius
|
||||
@ -797,8 +853,7 @@ sub HP1000_CGI() {
|
||||
);
|
||||
$webArgs->{indewpoint} =
|
||||
round( dewpoint_dewpoint( $webArgs->{intemp}, $h ), 1 );
|
||||
readingsUnitBulkUpdate( $hash, "indoorDewpoint",
|
||||
$webArgs->{indewpoint}, "c" );
|
||||
readingsBulkUpdate( $hash, "indoorDewpoint", $webArgs->{indewpoint} );
|
||||
}
|
||||
|
||||
# indoorDewpoint in Fahrenheit
|
||||
@ -814,8 +869,8 @@ sub HP1000_CGI() {
|
||||
);
|
||||
$webArgs->{indoordewpointf} =
|
||||
round( dewpoint_dewpoint( $webArgs->{indoortempf}, $h ), 1 );
|
||||
readingsUnitBulkUpdate( $hash, "indoorDewpoint_f",
|
||||
$webArgs->{indoordewpointf}, "f" );
|
||||
readingsBulkUpdate( $hash, "indoorDewpoint_f",
|
||||
$webArgs->{indoordewpointf} );
|
||||
}
|
||||
|
||||
# humidityAbs / humidityAbs_f
|
||||
@ -827,12 +882,11 @@ sub HP1000_CGI() {
|
||||
);
|
||||
$webArgs->{outhumiabs} =
|
||||
round( dewpoint_absFeuchte( $webArgs->{outtemp}, $h ), 1 );
|
||||
readingsUnitBulkUpdate( $hash, "humidityAbs", $webArgs->{outhumiabs} );
|
||||
readingsBulkUpdate( $hash, "humidityAbs", $webArgs->{outhumiabs} );
|
||||
|
||||
$webArgs->{outhumiabsf} =
|
||||
round( dewpoint_absFeuchte( $webArgs->{outtempf}, $h ), 1 );
|
||||
readingsUnitBulkUpdate( $hash, "humidityAbs_f",
|
||||
$webArgs->{outhumiabsf} );
|
||||
readingsBulkUpdate( $hash, "humidityAbs_f", $webArgs->{outhumiabsf} );
|
||||
}
|
||||
|
||||
# indoorHumidityAbs
|
||||
@ -844,8 +898,7 @@ sub HP1000_CGI() {
|
||||
);
|
||||
$webArgs->{inhumiabs} =
|
||||
round( dewpoint_absFeuchte( $webArgs->{intemp}, $h ), 1 );
|
||||
readingsUnitBulkUpdate( $hash, "indoorHumidityAbs",
|
||||
$webArgs->{inhumiabs} );
|
||||
readingsBulkUpdate( $hash, "indoorHumidityAbs", $webArgs->{inhumiabs} );
|
||||
}
|
||||
|
||||
# indoorHumidityAbs_f
|
||||
@ -861,7 +914,7 @@ sub HP1000_CGI() {
|
||||
);
|
||||
$webArgs->{indoorhumidityabsf} =
|
||||
round( dewpoint_absFeuchte( $webArgs->{indoortempf}, $h ), 1 );
|
||||
readingsUnitBulkUpdate( $hash, "indoorHumidityAbs_f",
|
||||
readingsBulkUpdate( $hash, "indoorHumidityAbs_f",
|
||||
$webArgs->{indoorhumidityabsf} );
|
||||
}
|
||||
|
||||
@ -869,7 +922,7 @@ sub HP1000_CGI() {
|
||||
if ( defined( $webArgs->{winddir} ) ) {
|
||||
$webArgs->{windcompasspoint} =
|
||||
UConv::deg2compasspoint( $webArgs->{winddir} );
|
||||
readingsUnitBulkUpdate( $hash, "wind_compasspoint",
|
||||
readingsBulkUpdate( $hash, "wind_compasspoint",
|
||||
$webArgs->{windcompasspoint} );
|
||||
}
|
||||
|
||||
@ -877,47 +930,42 @@ sub HP1000_CGI() {
|
||||
if ( defined( $webArgs->{windspeed} ) ) {
|
||||
$webArgs->{windspeedbft} =
|
||||
UConv::kph2bft( $webArgs->{windspeed} );
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_bft",
|
||||
$webArgs->{windspeedbft} );
|
||||
readingsBulkUpdate( $hash, "wind_speed_bft", $webArgs->{windspeedbft} );
|
||||
}
|
||||
|
||||
# wind_speed_kn in kn (convert from km/h)
|
||||
if ( defined( $webArgs->{windspeed} ) ) {
|
||||
my $v = UConv::kph2kn( $webArgs->{windspeed} );
|
||||
$webArgs->{windspeedkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_kn",
|
||||
$webArgs->{windspeedkn} );
|
||||
readingsBulkUpdate( $hash, "wind_speed_kn", $webArgs->{windspeedkn} );
|
||||
}
|
||||
|
||||
# wind_speed_fts in ft/s (convert from mph)
|
||||
if ( defined( $webArgs->{windspeedmph} ) ) {
|
||||
my $v = UConv::mph2fts( $webArgs->{windspeedmph} );
|
||||
$webArgs->{windspeedfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_fts",
|
||||
$webArgs->{windspeedfts} );
|
||||
readingsBulkUpdate( $hash, "wind_speed_fts", $webArgs->{windspeedfts} );
|
||||
}
|
||||
|
||||
# wind_gust_bft in Beaufort (convert from km/h)
|
||||
if ( defined( $webArgs->{windgust} ) ) {
|
||||
$webArgs->{windgustbft} =
|
||||
UConv::kph2bft( $webArgs->{windgust} );
|
||||
readingsUnitBulkUpdate( $hash, "wind_gust_bft",
|
||||
$webArgs->{windgustbft} );
|
||||
readingsBulkUpdate( $hash, "wind_gust_bft", $webArgs->{windgustbft} );
|
||||
}
|
||||
|
||||
# wind_gust_kn in m/s (convert from km/h)
|
||||
if ( defined( $webArgs->{windgust} ) ) {
|
||||
my $v = UConv::kph2kn( $webArgs->{windgust} );
|
||||
$webArgs->{windgustkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
|
||||
readingsUnitBulkUpdate( $hash, "wind_gust_kn", $webArgs->{windgustkn} );
|
||||
readingsBulkUpdate( $hash, "wind_gust_kn", $webArgs->{windgustkn} );
|
||||
}
|
||||
|
||||
# wind_gust_fts ft/s (convert from mph)
|
||||
if ( defined( $webArgs->{windgustmph} ) ) {
|
||||
my $v = UConv::mph2fts( $webArgs->{windgustmph} );
|
||||
$webArgs->{windgustfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
|
||||
readingsUnitBulkUpdate( $hash, "wind_gust_fts",
|
||||
$webArgs->{windgustfts} );
|
||||
readingsBulkUpdate( $hash, "wind_gust_fts", $webArgs->{windgustfts} );
|
||||
}
|
||||
|
||||
# averages/wind_direction_avg2m
|
||||
@ -926,7 +974,7 @@ sub HP1000_CGI() {
|
||||
HP1000_GetAvg( $hash, "winddir", 2 * 60, $webArgs->{winddir} ) );
|
||||
|
||||
if ( $hash->{INTERVAL} > 0 ) {
|
||||
readingsUnitBulkUpdate( $hash, "wind_direction_avg2m", $v );
|
||||
readingsBulkUpdate( $hash, "wind_direction_avg2m", $v );
|
||||
$webArgs->{winddir_avg2m} = $v;
|
||||
}
|
||||
}
|
||||
@ -935,7 +983,7 @@ sub HP1000_CGI() {
|
||||
if ( defined( $webArgs->{winddir_avg2m} ) ) {
|
||||
$webArgs->{windcompasspoint_avg2m} =
|
||||
UConv::deg2compasspoint( $webArgs->{winddir_avg2m} );
|
||||
readingsUnitBulkUpdate( $hash, "wind_compasspoint_avg2m",
|
||||
readingsBulkUpdate( $hash, "wind_compasspoint_avg2m",
|
||||
$webArgs->{windcompasspoint_avg2m} );
|
||||
}
|
||||
|
||||
@ -945,7 +993,7 @@ sub HP1000_CGI() {
|
||||
HP1000_GetAvg( $hash, "windspeed", 2 * 60, $webArgs->{windspeed} );
|
||||
|
||||
if ( $hash->{INTERVAL} > 0 ) {
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_avg2m", $v );
|
||||
readingsBulkUpdate( $hash, "wind_speed_avg2m", $v );
|
||||
$webArgs->{windspeed_avg2m} = $v;
|
||||
}
|
||||
}
|
||||
@ -956,7 +1004,7 @@ sub HP1000_CGI() {
|
||||
HP1000_GetAvg( $hash, "windspdmph", 2 * 60, $webArgs->{windspdmph} );
|
||||
|
||||
if ( $hash->{INTERVAL} > 0 ) {
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_mph_avg2m", $v );
|
||||
readingsBulkUpdate( $hash, "wind_speed_mph_avg2m", $v );
|
||||
$webArgs->{windspdmph_avg2m} = $v;
|
||||
}
|
||||
}
|
||||
@ -965,7 +1013,7 @@ sub HP1000_CGI() {
|
||||
if ( defined( $webArgs->{windspeed_avg2m} ) ) {
|
||||
$webArgs->{windspeedbft_avg2m} =
|
||||
UConv::kph2bft( $webArgs->{windspeed_avg2m} );
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_bft_avg2m",
|
||||
readingsBulkUpdate( $hash, "wind_speed_bft_avg2m",
|
||||
$webArgs->{windspeedbft_avg2m} );
|
||||
}
|
||||
|
||||
@ -973,7 +1021,7 @@ sub HP1000_CGI() {
|
||||
if ( defined( $webArgs->{windspeed_avg2m} ) ) {
|
||||
$webArgs->{windspeedkn_avg2m} =
|
||||
UConv::kph2kn( $webArgs->{windspeed_avg2m} );
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_kn_avg2m",
|
||||
readingsBulkUpdate( $hash, "wind_speed_kn_avg2m",
|
||||
$webArgs->{windspeedkn_avg2m} );
|
||||
}
|
||||
|
||||
@ -982,7 +1030,7 @@ sub HP1000_CGI() {
|
||||
my $v = UConv::kph2mps( $webArgs->{windspeed_avg2m} );
|
||||
$webArgs->{windspeedmps_avg2m} =
|
||||
( $v > 0.5 ? round( $v, 1 ) : "0.0" );
|
||||
readingsUnitBulkUpdate( $hash, "wind_speed_mps_avg2m",
|
||||
readingsBulkUpdate( $hash, "wind_speed_mps_avg2m",
|
||||
$webArgs->{windspeedmps_avg2m} );
|
||||
}
|
||||
|
||||
@ -992,7 +1040,7 @@ sub HP1000_CGI() {
|
||||
HP1000_GetSum( $hash, "windgust", 10 * 60, $webArgs->{windgust} );
|
||||
|
||||
if ( $hash->{INTERVAL} > 0 ) {
|
||||
readingsUnitBulkUpdate( $hash, "wind_gust_sum10m", $v );
|
||||
readingsBulkUpdate( $hash, "wind_gust_sum10m", $v );
|
||||
$webArgs->{windgust_10m} = $v;
|
||||
}
|
||||
}
|
||||
@ -1004,7 +1052,7 @@ sub HP1000_CGI() {
|
||||
$webArgs->{windgustmph} );
|
||||
|
||||
if ( $hash->{INTERVAL} > 0 ) {
|
||||
readingsUnitBulkUpdate( $hash, "wind_gust_mph_sum10m", $v );
|
||||
readingsBulkUpdate( $hash, "wind_gust_mph_sum10m", $v );
|
||||
$webArgs->{windgustmph_10m} = $v;
|
||||
}
|
||||
}
|
||||
@ -1030,8 +1078,8 @@ sub HP1000_CGI() {
|
||||
getMultiValStatus( $name, $stateReadings,
|
||||
$stateReadingsLang, $stateReadingsFormat );
|
||||
|
||||
readingsUnitBulkUpdate( $hash, "state", $result );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsBulkUpdate( $hash, "state", $result );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
|
||||
HP1000_PushWU( $hash, $webArgs )
|
||||
if AttrVal( $name, "wu_push", 0 ) eq "1";
|
||||
@ -1152,9 +1200,9 @@ sub HP1000_PushWU($$) {
|
||||
|
||||
my $return = "error: missing attributes wu_user and wu_password";
|
||||
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged( $hash, "wu_state", $return );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1228,9 +1276,9 @@ sub HP1000_ReturnSrv($$$) {
|
||||
my $return = "error: connection timeout";
|
||||
Log3 $name, 4, "HP1000 $name: EXTSRV HTTP " . $return;
|
||||
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "extsrv_state", $return );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged( $hash, "extsrv_state", $return );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
|
||||
# data received
|
||||
@ -1245,9 +1293,9 @@ sub HP1000_ReturnSrv($$$) {
|
||||
Log3 $name, $logprio,
|
||||
"HP1000 $name: EXTSRV HTTP return: " . $param->{code} . " - $data";
|
||||
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "extsrv_state", $return );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged( $hash, "extsrv_state", $return );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
|
||||
return;
|
||||
@ -1264,9 +1312,9 @@ sub HP1000_ReturnWU($$$) {
|
||||
my $return = "error: connection timeout";
|
||||
Log3 $name, 4, "HP1000 $name: WU HTTP " . $return;
|
||||
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged( $hash, "wu_state", $return );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
|
||||
# data received
|
||||
@ -1283,9 +1331,9 @@ sub HP1000_ReturnWU($$$) {
|
||||
Log3 $name, $logprio,
|
||||
"HP1000 $name: WU HTTP return: " . $param->{code} . " - $data";
|
||||
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged( $hash, "wu_state", $return );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -57,6 +57,120 @@ sub Wunderground_Initialize($) {
|
||||
"disable:0,1 timeout:1,2,3,4,5 pollInterval:300,450,600,750,900 wu_lang:en,de,at,ch,nl,fr,pl stateReadings stateReadingsFormat:0,1,2 "
|
||||
. $readingFnAttributes;
|
||||
|
||||
$hash->{readingsDesc} = {
|
||||
"UV" => { "unit" => "uvi" },
|
||||
"dewpoint" => { "unit" => "c" },
|
||||
"dewpoint_f" => { "unit" => "f" },
|
||||
"fc0_high_c" => { "unit" => "c" },
|
||||
"fc0_high_f" => { "unit" => "f" },
|
||||
"fc0_humidity" => { "unit" => "pct" },
|
||||
"fc0_humidity_max" => { "unit" => "pct" },
|
||||
"fc0_humidity_min" => { "unit" => "pct" },
|
||||
"fc0_low_c" => { "unit" => "c" },
|
||||
"fc0_low_f" => { "unit" => "f" },
|
||||
"fc0_rain_day" => { "unit" => "mm" },
|
||||
"fc0_rain_day_in" => { "unit" => "in" },
|
||||
"fc0_rain_night" => { "unit" => "mm" },
|
||||
"fc0_rain_night_in" => { "unit" => "in" },
|
||||
"fc0_snow_day" => { "unit" => "cm" },
|
||||
"fc0_snow_day_in" => { "unit" => "in" },
|
||||
"fc0_snow_night" => { "unit" => "cm" },
|
||||
"fc0_snow_night_in" => { "unit" => "in" },
|
||||
"fc0_wind_direction" => { "unit" => "gon" },
|
||||
"fc0_wind_direction_max" => { "unit" => "gon" },
|
||||
"fc0_wind_speed" => { "unit" => "kmh" },
|
||||
"fc0_wind_speed_max" => { "unit" => "kmh" },
|
||||
"fc0_wind_speed_max_mph" => { "unit" => "mph" },
|
||||
"fc0_wind_speed_mph" => { "unit" => "mph" },
|
||||
"fc1_high_c" => { "unit" => "c" },
|
||||
"fc1_high_f" => { "unit" => "f" },
|
||||
"fc1_humidity" => { "unit" => "pct" },
|
||||
"fc1_humidity_max" => { "unit" => "pct" },
|
||||
"fc1_humidity_min" => { "unit" => "pct" },
|
||||
"fc1_low_c" => { "unit" => "c" },
|
||||
"fc1_low_f" => { "unit" => "f" },
|
||||
"fc1_rain_day" => { "unit" => "mm" },
|
||||
"fc1_rain_day_in" => { "unit" => "in" },
|
||||
"fc1_rain_night" => { "unit" => "mm" },
|
||||
"fc1_rain_night_in" => { "unit" => "in" },
|
||||
"fc1_snow_day" => { "unit" => "cm" },
|
||||
"fc1_snow_day_in" => { "unit" => "in" },
|
||||
"fc1_snow_night" => { "unit" => "cm" },
|
||||
"fc1_snow_night_in" => { "unit" => "in" },
|
||||
"fc1_wind_direction" => { "unit" => "gon" },
|
||||
"fc1_wind_direction_max" => { "unit" => "gon" },
|
||||
"fc1_wind_speed" => { "unit" => "kmh" },
|
||||
"fc1_wind_speed_max" => { "unit" => "kmh" },
|
||||
"fc1_wind_speed_max_mph" => { "unit" => "mph" },
|
||||
"fc1_wind_speed_mph" => { "unit" => "mph" },
|
||||
"fc2_high_c" => { "unit" => "c" },
|
||||
"fc2_high_f" => { "unit" => "f" },
|
||||
"fc2_humidity" => { "unit" => "pct" },
|
||||
"fc2_humidity_max" => { "unit" => "pct" },
|
||||
"fc2_humidity_min" => { "unit" => "pct" },
|
||||
"fc2_low_c" => { "unit" => "c" },
|
||||
"fc2_low_f" => { "unit" => "f" },
|
||||
"fc2_rain_day" => { "unit" => "mm" },
|
||||
"fc2_rain_day_in" => { "unit" => "in" },
|
||||
"fc2_rain_night" => { "unit" => "mm" },
|
||||
"fc2_rain_night_in" => { "unit" => "in" },
|
||||
"fc2_snow_day" => { "unit" => "cm" },
|
||||
"fc2_snow_day_in" => { "unit" => "in" },
|
||||
"fc2_snow_night" => { "unit" => "cm" },
|
||||
"fc2_snow_night_in" => { "unit" => "in" },
|
||||
"fc2_wind_direction" => { "unit" => "gon" },
|
||||
"fc2_wind_direction_max" => { "unit" => "gon" },
|
||||
"fc2_wind_speed" => { "unit" => "kmh" },
|
||||
"fc2_wind_speed_max" => { "unit" => "kmh" },
|
||||
"fc2_wind_speed_max_mph" => { "unit" => "mph" },
|
||||
"fc2_wind_speed_mph" => { "unit" => "mph" },
|
||||
"fc3_high_c" => { "unit" => "c" },
|
||||
"fc3_high_f" => { "unit" => "f" },
|
||||
"fc3_humidity" => { "unit" => "pct" },
|
||||
"fc3_humidity_max" => { "unit" => "pct" },
|
||||
"fc3_humidity_min" => { "unit" => "pct" },
|
||||
"fc3_low_c" => { "unit" => "c" },
|
||||
"fc3_low_f" => { "unit" => "f" },
|
||||
"fc3_rain_day" => { "unit" => "mm" },
|
||||
"fc3_rain_day_in" => { "unit" => "in" },
|
||||
"fc3_rain_night" => { "unit" => "mm" },
|
||||
"fc3_rain_night_in" => { "unit" => "in" },
|
||||
"fc3_snow_day" => { "unit" => "cm" },
|
||||
"fc3_snow_day_in" => { "unit" => "in" },
|
||||
"fc3_snow_night" => { "unit" => "cm" },
|
||||
"fc3_snow_night_in" => { "unit" => "in" },
|
||||
"fc3_wind_direction" => { "unit" => "gon" },
|
||||
"fc3_wind_direction_max" => { "unit" => "gon" },
|
||||
"fc3_wind_speed" => { "unit" => "kmh" },
|
||||
"fc3_wind_speed_max" => { "unit" => "kmh" },
|
||||
"fc3_wind_speed_max_mph" => { "unit" => "mph" },
|
||||
"fc3_wind_speed_mph" => { "unit" => "mph" },
|
||||
"feelslike_c" => { "unit" => "c" },
|
||||
"feelslike_f" => { "unit" => "f" },
|
||||
"heat_index_c" => { "unit" => "c" },
|
||||
"heat_index_f" => { "unit" => "f" },
|
||||
"humidity" => { "unit" => "pct" },
|
||||
"moon_pct" => { "unit" => "pct" },
|
||||
"pressure" => { "unit" => "hpamb" },
|
||||
"pressure_in" => { "unit" => "inhg" },
|
||||
"rain" => { "unit" => "mm" },
|
||||
"rain_day" => { "unit" => "mm" },
|
||||
"rain_day_in" => { "unit" => "in" },
|
||||
"rain_in" => { "unit" => "in" },
|
||||
"solarradiation" => { "unit" => "wpsm" },
|
||||
"temp_c" => { "unit" => "c" },
|
||||
"temp_f" => { "unit" => "f" },
|
||||
"visibility" => { "unit" => "km" },
|
||||
"visibility_mi" => { "unit" => "mi" },
|
||||
"wind_chill" => { "unit" => "c" },
|
||||
"wind_chill_f" => { "unit" => "f" },
|
||||
"wind_direction" => { "unit" => "gon" },
|
||||
"wind_gust" => { "unit" => "kmh" },
|
||||
"wind_gust_mph" => { "unit" => "mph" },
|
||||
"wind_speed" => { "unit" => "kmh" },
|
||||
"wind_speed_mph" => { "unit" => "mph" }
|
||||
};
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -239,7 +353,7 @@ sub Wunderground_ReceiveCommand($$$) {
|
||||
Log3 $name, 5,
|
||||
"Wunderground $name: called function Wunderground_ReceiveCommand()";
|
||||
|
||||
readingsUnitBeginUpdate($hash);
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
# service not reachable
|
||||
if ($err) {
|
||||
@ -292,10 +406,10 @@ sub Wunderground_ReceiveCommand($$$) {
|
||||
getMultiValStatus( $name, $stateReadings,
|
||||
$stateReadingsLang, $stateReadingsFormat );
|
||||
|
||||
readingsUnitBulkUpdate( $hash, "state", $state );
|
||||
readingsUnitBulkUpdateIfChanged( $hash, "lastQueryResult",
|
||||
readingsBulkUpdate( $hash, "state", $state );
|
||||
readingsBulkUpdateIfChanged( $hash, "lastQueryResult",
|
||||
$lastQueryResult );
|
||||
readingsUnitEndUpdate( $hash, 1 );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
|
||||
return;
|
||||
}
|
||||
@ -382,16 +496,16 @@ sub Wunderground_Hash2Readings($$;$) {
|
||||
$moonset =~ s/^(\d):(\d\d)$/0$1:$2/;
|
||||
$moonset =~ s/^(\d\d):(\d)$/$1:0$2/;
|
||||
|
||||
readingsUnitBulkUpdate( $hash, "sunrise", $sunrise );
|
||||
readingsUnitBulkUpdate( $hash, "sunset", $sunset );
|
||||
readingsUnitBulkUpdate( $hash, "moonrise", $moonrise );
|
||||
readingsUnitBulkUpdate( $hash, "moonset", $moonset );
|
||||
readingsBulkUpdate( $hash, "sunrise", $sunrise );
|
||||
readingsBulkUpdate( $hash, "sunset", $sunset );
|
||||
readingsBulkUpdate( $hash, "moonrise", $moonrise );
|
||||
readingsBulkUpdate( $hash, "moonset", $moonset );
|
||||
|
||||
readingsUnitBulkUpdate( $hash, "moon_age",
|
||||
readingsBulkUpdate( $hash, "moon_age",
|
||||
$h->{moon_phase}{ageOfMoon} );
|
||||
readingsUnitBulkUpdate( $hash, "moon_pct",
|
||||
readingsBulkUpdate( $hash, "moon_pct",
|
||||
$h->{moon_phase}{percentIlluminated} );
|
||||
readingsUnitBulkUpdate( $hash, "moon_phase",
|
||||
readingsBulkUpdate( $hash, "moon_phase",
|
||||
$h->{moon_phase}{phaseofMoon} );
|
||||
}
|
||||
|
||||
@ -402,104 +516,104 @@ sub Wunderground_Hash2Readings($$;$) {
|
||||
my $period = $h->{period} - 1;
|
||||
$reading = "fc" . $period . "_";
|
||||
|
||||
readingsUnitBulkUpdate( $hash, $reading . "condition",
|
||||
readingsBulkUpdate( $hash, $reading . "condition",
|
||||
$h->{conditions} );
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "high_c",
|
||||
$h->{high}{celsius}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "high_f",
|
||||
$h->{high}{fahrenheit}
|
||||
);
|
||||
readingsUnitBulkUpdate( $hash, $reading . "humidity",
|
||||
readingsBulkUpdate( $hash, $reading . "humidity",
|
||||
$h->{avehumidity} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "humidity_min",
|
||||
readingsBulkUpdate( $hash, $reading . "humidity_min",
|
||||
$h->{minhumidity} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "humidity_max",
|
||||
readingsBulkUpdate( $hash, $reading . "humidity_max",
|
||||
$h->{maxhumidity} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "icon", $h->{icon} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "icon_url",
|
||||
readingsBulkUpdate( $hash, $reading . "icon", $h->{icon} );
|
||||
readingsBulkUpdate( $hash, $reading . "icon_url",
|
||||
$h->{icon_url} );
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "low_c",
|
||||
$h->{low}{celsius}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "low_f",
|
||||
$h->{low}{fahrenheit}
|
||||
);
|
||||
readingsUnitBulkUpdate( $hash, $reading . "pop", $h->{pop} );
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate( $hash, $reading . "pop", $h->{pop} );
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "rain_day",
|
||||
$h->{qpf_allday}{mm}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "rain_day_in",
|
||||
$h->{qpf_allday}{in}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "rain_night",
|
||||
$h->{qpf_night}{mm}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "rain_night_in",
|
||||
$h->{qpf_night}{in}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "snow_day",
|
||||
$h->{snow_allday}{cm}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "snow_day_in",
|
||||
$h->{snow_allday}{in}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "snow_night",
|
||||
$h->{snow_night}{cm}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "snow_night_in",
|
||||
$h->{snow_night}{in}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "wind_direction",
|
||||
$h->{avewind}{degrees}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "wind_direction_max",
|
||||
$h->{maxwind}{degrees}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "wind_speed",
|
||||
$h->{avewind}{kph}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "wind_speed_mph",
|
||||
$h->{avewind}{mph}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "wind_speed_max",
|
||||
$h->{maxwind}{kph}
|
||||
);
|
||||
readingsUnitBulkUpdate(
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
$reading . "wind_speed_max_mph",
|
||||
$h->{maxwind}{mph}
|
||||
@ -532,17 +646,17 @@ sub Wunderground_Hash2Readings($$;$) {
|
||||
|
||||
$reading = "fc" . $period . "_";
|
||||
|
||||
readingsUnitBulkUpdate( $hash, $reading . "icon$night",
|
||||
readingsBulkUpdate( $hash, $reading . "icon$night",
|
||||
$h->{icon} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "icon_url$night",
|
||||
readingsBulkUpdate( $hash, $reading . "icon_url$night",
|
||||
$h->{icon_url} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "pop$night",
|
||||
readingsBulkUpdate( $hash, $reading . "pop$night",
|
||||
$h->{pop} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "text$night",
|
||||
readingsBulkUpdate( $hash, $reading . "text$night",
|
||||
$h->{fcttext_metric} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "text_f$night",
|
||||
readingsBulkUpdate( $hash, $reading . "text_f$night",
|
||||
$h->{fcttext} );
|
||||
readingsUnitBulkUpdate( $hash, $reading . "title$night",
|
||||
readingsBulkUpdate( $hash, $reading . "title$night",
|
||||
$h->{title} );
|
||||
}
|
||||
|
||||
@ -565,7 +679,7 @@ sub Wunderground_Hash2Readings($$;$) {
|
||||
|
||||
$value =~ s/^(\d+)%$/$1/;
|
||||
|
||||
readingsUnitBulkUpdate( $hash, $reading, $value );
|
||||
readingsBulkUpdate( $hash, $reading, $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -577,7 +691,7 @@ sub Wunderground_Hash2Readings($$;$) {
|
||||
Wunderground_Hash2Readings( $hash, $_, $r . $i );
|
||||
}
|
||||
else {
|
||||
readingsUnitBulkUpdate( $hash, $r . $i, $_ );
|
||||
readingsBulkUpdate( $hash, $r . $i, $_ );
|
||||
}
|
||||
|
||||
$i++;
|
||||
|
@ -549,6 +549,25 @@ sub activity2log($) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
#TODO rewrite for Unit.pm
|
||||
sub fmtTime($) {
|
||||
my ($value) = @_;
|
||||
my $suffix = ' s';
|
||||
|
||||
if ( $value >= 60 ) {
|
||||
$value = sprintf( "%.1f", $value / 60 );
|
||||
$suffix = ' min';
|
||||
|
||||
if ( $value >= 60 ) {
|
||||
$value = sprintf( "%.1f", $value / 60 );
|
||||
$suffix = ' h';
|
||||
}
|
||||
}
|
||||
|
||||
return ( $value, $suffix ) if (wantarray);
|
||||
return $value . $suffix;
|
||||
}
|
||||
|
||||
####################
|
||||
# HELPER FUNCTIONS
|
||||
|
||||
|
1472
fhem/FHEM/Unit.pm
1472
fhem/FHEM/Unit.pm
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user