2
0
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:
jpawlowski 2016-11-09 02:06:06 +00:00
parent 90629d8527
commit fba06e6863
4 changed files with 1154 additions and 723 deletions

View File

@ -72,6 +72,64 @@ sub HP1000_Initialize($) {
$hash->{AttrList} = $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 " "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; . $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"; my $activity = "dead";
$activity = "alive" if ($alive); $activity = "alive" if ($alive);
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUnitBulkUpdateIfChanged( $hash, "Activity", $activity ); readingsBulkUpdateIfChanged( $hash, "Activity", $activity );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
InternalTimer( gettimeofday() + 120, "HP1000_SetAliveState", $hash, 0 ); InternalTimer( gettimeofday() + 120, "HP1000_SetAliveState", $hash, 0 );
@ -646,7 +704,7 @@ sub HP1000_CGI() {
# write general readings # write general readings
# #
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
while ( ( my $p, my $v ) = each %$webArgs ) { while ( ( my $p, my $v ) = each %$webArgs ) {
@ -709,7 +767,7 @@ sub HP1000_CGI() {
$p = "wind_gust_mph" if ( $p eq "_windgustmph" ); $p = "wind_gust_mph" if ( $p eq "_windgustmph" );
$p = "wind_speed_mph" if ( $p eq "_windspdmph" ); $p = "wind_speed_mph" if ( $p eq "_windspdmph" );
readingsUnitBulkUpdate( $hash, $p, $v ); readingsBulkUpdate( $hash, $p, $v );
} }
# calculate additional readings # calculate additional readings
@ -719,20 +777,20 @@ sub HP1000_CGI() {
my $israining = 0; my $israining = 0;
$israining = 1 $israining = 1
if ( defined( $webArgs->{rainrate} ) && $webArgs->{rainrate} > 0 ); if ( defined( $webArgs->{rainrate} ) && $webArgs->{rainrate} > 0 );
readingsUnitBulkUpdateIfChanged( $hash, "israining", $israining ); readingsBulkUpdateIfChanged( $hash, "israining", $israining );
# daylight # daylight
my $daylight = 0; my $daylight = 0;
$daylight = 1 $daylight = 1
if ( defined( $webArgs->{light} ) && $webArgs->{light} > 50 ); if ( defined( $webArgs->{light} ) && $webArgs->{light} > 50 );
readingsUnitBulkUpdateIfChanged( $hash, "daylight", $daylight ); readingsBulkUpdateIfChanged( $hash, "daylight", $daylight );
# condition # condition
if ( defined( $webArgs->{light} ) ) { if ( defined( $webArgs->{light} ) ) {
my $temp = ( $webArgs->{outtemp} ? $webArgs->{outtemp} : "10" ); my $temp = ( $webArgs->{outtemp} ? $webArgs->{outtemp} : "10" );
my $hum = ( $webArgs->{outhumi} ? $webArgs->{outhumi} : "50" ); my $hum = ( $webArgs->{outhumi} ? $webArgs->{outhumi} : "50" );
readingsUnitBulkUpdateIfChanged( readingsBulkUpdateIfChanged(
$hash, $hash,
"condition", "condition",
UConv::values2weathercondition( UConv::values2weathercondition(
@ -743,25 +801,25 @@ sub HP1000_CGI() {
# humidityCondition # humidityCondition
if ( defined( $webArgs->{outhumi} ) ) { if ( defined( $webArgs->{outhumi} ) ) {
readingsUnitBulkUpdateIfChanged( $hash, "humidityCondition", readingsBulkUpdateIfChanged( $hash, "humidityCondition",
UConv::humidity2condition( $webArgs->{outhumi} ) ); UConv::humidity2condition( $webArgs->{outhumi} ) );
} }
# indoorHumidityCondition # indoorHumidityCondition
if ( defined( $webArgs->{inhumi} ) ) { if ( defined( $webArgs->{inhumi} ) ) {
readingsUnitBulkUpdateIfChanged( $hash, "indoorHumidityCondition", readingsBulkUpdateIfChanged( $hash, "indoorHumidityCondition",
UConv::humidity2condition( $webArgs->{inhumi} ) ); UConv::humidity2condition( $webArgs->{inhumi} ) );
} }
# UV (convert from uW/cm2) # UV (convert from uW/cm2)
if ( defined( $webArgs->{UV} ) ) { if ( defined( $webArgs->{UV} ) ) {
$webArgs->{UVI} = UConv::uwpscm2uvi( $webArgs->{UV} ); $webArgs->{UVI} = UConv::uwpscm2uvi( $webArgs->{UV} );
readingsUnitBulkUpdate( $hash, "UV", $webArgs->{UVI}, "uvi" ); readingsBulkUpdate( $hash, "UV", $webArgs->{UVI} );
} }
# UVcondition # UVcondition
if ( defined( $webArgs->{UVI} ) ) { if ( defined( $webArgs->{UVI} ) ) {
readingsUnitBulkUpdateIfChanged( $hash, "UVcondition", readingsBulkUpdateIfChanged( $hash, "UVcondition",
UConv::uvi2condition( $webArgs->{UVI} ) ); UConv::uvi2condition( $webArgs->{UVI} ) );
} }
@ -769,23 +827,21 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{light} ) ) { if ( defined( $webArgs->{light} ) ) {
$webArgs->{solarradiation} = $webArgs->{solarradiation} =
UConv::lux2wpsm( $webArgs->{light} ); UConv::lux2wpsm( $webArgs->{light} );
readingsUnitBulkUpdate( $hash, "solarradiation", readingsBulkUpdate( $hash, "solarradiation",
$webArgs->{solarradiation}, "wpsm" ); $webArgs->{solarradiation} );
} }
# pressure_mm in mmHg (convert from hpa) # pressure_mm in mmHg (convert from hpa)
if ( defined( $webArgs->{relbaro} ) ) { if ( defined( $webArgs->{relbaro} ) ) {
$webArgs->{barommm} = UConv::hpa2mmhg( $webArgs->{relbaro} ); $webArgs->{barommm} = UConv::hpa2mmhg( $webArgs->{relbaro} );
readingsUnitBulkUpdate( $hash, "pressure_mm", $webArgs->{barommm}, readingsBulkUpdate( $hash, "pressure_mm", $webArgs->{barommm} );
"mmhg" );
} }
# pressureAbs_mm in mmHg (convert from hpa) # pressureAbs_mm in mmHg (convert from hpa)
if ( defined( $webArgs->{absbaro} ) ) { if ( defined( $webArgs->{absbaro} ) ) {
$webArgs->{absbarommm} = $webArgs->{absbarommm} =
UConv::hpa2mmhg( $webArgs->{absbaro} ); UConv::hpa2mmhg( $webArgs->{absbaro} );
readingsUnitBulkUpdate( $hash, "pressureAbs_mm", readingsBulkUpdate( $hash, "pressureAbs_mm", $webArgs->{absbarommm} );
$webArgs->{absbarommm}, "mmhg" );
} }
# indoorDewpoint in Celsius # indoorDewpoint in Celsius
@ -797,8 +853,7 @@ sub HP1000_CGI() {
); );
$webArgs->{indewpoint} = $webArgs->{indewpoint} =
round( dewpoint_dewpoint( $webArgs->{intemp}, $h ), 1 ); round( dewpoint_dewpoint( $webArgs->{intemp}, $h ), 1 );
readingsUnitBulkUpdate( $hash, "indoorDewpoint", readingsBulkUpdate( $hash, "indoorDewpoint", $webArgs->{indewpoint} );
$webArgs->{indewpoint}, "c" );
} }
# indoorDewpoint in Fahrenheit # indoorDewpoint in Fahrenheit
@ -814,8 +869,8 @@ sub HP1000_CGI() {
); );
$webArgs->{indoordewpointf} = $webArgs->{indoordewpointf} =
round( dewpoint_dewpoint( $webArgs->{indoortempf}, $h ), 1 ); round( dewpoint_dewpoint( $webArgs->{indoortempf}, $h ), 1 );
readingsUnitBulkUpdate( $hash, "indoorDewpoint_f", readingsBulkUpdate( $hash, "indoorDewpoint_f",
$webArgs->{indoordewpointf}, "f" ); $webArgs->{indoordewpointf} );
} }
# humidityAbs / humidityAbs_f # humidityAbs / humidityAbs_f
@ -827,12 +882,11 @@ sub HP1000_CGI() {
); );
$webArgs->{outhumiabs} = $webArgs->{outhumiabs} =
round( dewpoint_absFeuchte( $webArgs->{outtemp}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{outtemp}, $h ), 1 );
readingsUnitBulkUpdate( $hash, "humidityAbs", $webArgs->{outhumiabs} ); readingsBulkUpdate( $hash, "humidityAbs", $webArgs->{outhumiabs} );
$webArgs->{outhumiabsf} = $webArgs->{outhumiabsf} =
round( dewpoint_absFeuchte( $webArgs->{outtempf}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{outtempf}, $h ), 1 );
readingsUnitBulkUpdate( $hash, "humidityAbs_f", readingsBulkUpdate( $hash, "humidityAbs_f", $webArgs->{outhumiabsf} );
$webArgs->{outhumiabsf} );
} }
# indoorHumidityAbs # indoorHumidityAbs
@ -844,8 +898,7 @@ sub HP1000_CGI() {
); );
$webArgs->{inhumiabs} = $webArgs->{inhumiabs} =
round( dewpoint_absFeuchte( $webArgs->{intemp}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{intemp}, $h ), 1 );
readingsUnitBulkUpdate( $hash, "indoorHumidityAbs", readingsBulkUpdate( $hash, "indoorHumidityAbs", $webArgs->{inhumiabs} );
$webArgs->{inhumiabs} );
} }
# indoorHumidityAbs_f # indoorHumidityAbs_f
@ -861,7 +914,7 @@ sub HP1000_CGI() {
); );
$webArgs->{indoorhumidityabsf} = $webArgs->{indoorhumidityabsf} =
round( dewpoint_absFeuchte( $webArgs->{indoortempf}, $h ), 1 ); round( dewpoint_absFeuchte( $webArgs->{indoortempf}, $h ), 1 );
readingsUnitBulkUpdate( $hash, "indoorHumidityAbs_f", readingsBulkUpdate( $hash, "indoorHumidityAbs_f",
$webArgs->{indoorhumidityabsf} ); $webArgs->{indoorhumidityabsf} );
} }
@ -869,7 +922,7 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{winddir} ) ) { if ( defined( $webArgs->{winddir} ) ) {
$webArgs->{windcompasspoint} = $webArgs->{windcompasspoint} =
UConv::deg2compasspoint( $webArgs->{winddir} ); UConv::deg2compasspoint( $webArgs->{winddir} );
readingsUnitBulkUpdate( $hash, "wind_compasspoint", readingsBulkUpdate( $hash, "wind_compasspoint",
$webArgs->{windcompasspoint} ); $webArgs->{windcompasspoint} );
} }
@ -877,47 +930,42 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{windspeed} ) ) { if ( defined( $webArgs->{windspeed} ) ) {
$webArgs->{windspeedbft} = $webArgs->{windspeedbft} =
UConv::kph2bft( $webArgs->{windspeed} ); UConv::kph2bft( $webArgs->{windspeed} );
readingsUnitBulkUpdate( $hash, "wind_speed_bft", readingsBulkUpdate( $hash, "wind_speed_bft", $webArgs->{windspeedbft} );
$webArgs->{windspeedbft} );
} }
# wind_speed_kn in kn (convert from km/h) # wind_speed_kn in kn (convert from km/h)
if ( defined( $webArgs->{windspeed} ) ) { if ( defined( $webArgs->{windspeed} ) ) {
my $v = UConv::kph2kn( $webArgs->{windspeed} ); my $v = UConv::kph2kn( $webArgs->{windspeed} );
$webArgs->{windspeedkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $webArgs->{windspeedkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsUnitBulkUpdate( $hash, "wind_speed_kn", readingsBulkUpdate( $hash, "wind_speed_kn", $webArgs->{windspeedkn} );
$webArgs->{windspeedkn} );
} }
# wind_speed_fts in ft/s (convert from mph) # wind_speed_fts in ft/s (convert from mph)
if ( defined( $webArgs->{windspeedmph} ) ) { if ( defined( $webArgs->{windspeedmph} ) ) {
my $v = UConv::mph2fts( $webArgs->{windspeedmph} ); my $v = UConv::mph2fts( $webArgs->{windspeedmph} );
$webArgs->{windspeedfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $webArgs->{windspeedfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsUnitBulkUpdate( $hash, "wind_speed_fts", readingsBulkUpdate( $hash, "wind_speed_fts", $webArgs->{windspeedfts} );
$webArgs->{windspeedfts} );
} }
# wind_gust_bft in Beaufort (convert from km/h) # wind_gust_bft in Beaufort (convert from km/h)
if ( defined( $webArgs->{windgust} ) ) { if ( defined( $webArgs->{windgust} ) ) {
$webArgs->{windgustbft} = $webArgs->{windgustbft} =
UConv::kph2bft( $webArgs->{windgust} ); UConv::kph2bft( $webArgs->{windgust} );
readingsUnitBulkUpdate( $hash, "wind_gust_bft", readingsBulkUpdate( $hash, "wind_gust_bft", $webArgs->{windgustbft} );
$webArgs->{windgustbft} );
} }
# wind_gust_kn in m/s (convert from km/h) # wind_gust_kn in m/s (convert from km/h)
if ( defined( $webArgs->{windgust} ) ) { if ( defined( $webArgs->{windgust} ) ) {
my $v = UConv::kph2kn( $webArgs->{windgust} ); my $v = UConv::kph2kn( $webArgs->{windgust} );
$webArgs->{windgustkn} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $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) # wind_gust_fts ft/s (convert from mph)
if ( defined( $webArgs->{windgustmph} ) ) { if ( defined( $webArgs->{windgustmph} ) ) {
my $v = UConv::mph2fts( $webArgs->{windgustmph} ); my $v = UConv::mph2fts( $webArgs->{windgustmph} );
$webArgs->{windgustfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" ); $webArgs->{windgustfts} = ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsUnitBulkUpdate( $hash, "wind_gust_fts", readingsBulkUpdate( $hash, "wind_gust_fts", $webArgs->{windgustfts} );
$webArgs->{windgustfts} );
} }
# averages/wind_direction_avg2m # averages/wind_direction_avg2m
@ -926,7 +974,7 @@ sub HP1000_CGI() {
HP1000_GetAvg( $hash, "winddir", 2 * 60, $webArgs->{winddir} ) ); HP1000_GetAvg( $hash, "winddir", 2 * 60, $webArgs->{winddir} ) );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsUnitBulkUpdate( $hash, "wind_direction_avg2m", $v ); readingsBulkUpdate( $hash, "wind_direction_avg2m", $v );
$webArgs->{winddir_avg2m} = $v; $webArgs->{winddir_avg2m} = $v;
} }
} }
@ -935,7 +983,7 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{winddir_avg2m} ) ) { if ( defined( $webArgs->{winddir_avg2m} ) ) {
$webArgs->{windcompasspoint_avg2m} = $webArgs->{windcompasspoint_avg2m} =
UConv::deg2compasspoint( $webArgs->{winddir_avg2m} ); UConv::deg2compasspoint( $webArgs->{winddir_avg2m} );
readingsUnitBulkUpdate( $hash, "wind_compasspoint_avg2m", readingsBulkUpdate( $hash, "wind_compasspoint_avg2m",
$webArgs->{windcompasspoint_avg2m} ); $webArgs->{windcompasspoint_avg2m} );
} }
@ -945,7 +993,7 @@ sub HP1000_CGI() {
HP1000_GetAvg( $hash, "windspeed", 2 * 60, $webArgs->{windspeed} ); HP1000_GetAvg( $hash, "windspeed", 2 * 60, $webArgs->{windspeed} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsUnitBulkUpdate( $hash, "wind_speed_avg2m", $v ); readingsBulkUpdate( $hash, "wind_speed_avg2m", $v );
$webArgs->{windspeed_avg2m} = $v; $webArgs->{windspeed_avg2m} = $v;
} }
} }
@ -956,7 +1004,7 @@ sub HP1000_CGI() {
HP1000_GetAvg( $hash, "windspdmph", 2 * 60, $webArgs->{windspdmph} ); HP1000_GetAvg( $hash, "windspdmph", 2 * 60, $webArgs->{windspdmph} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsUnitBulkUpdate( $hash, "wind_speed_mph_avg2m", $v ); readingsBulkUpdate( $hash, "wind_speed_mph_avg2m", $v );
$webArgs->{windspdmph_avg2m} = $v; $webArgs->{windspdmph_avg2m} = $v;
} }
} }
@ -965,7 +1013,7 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{windspeed_avg2m} ) ) { if ( defined( $webArgs->{windspeed_avg2m} ) ) {
$webArgs->{windspeedbft_avg2m} = $webArgs->{windspeedbft_avg2m} =
UConv::kph2bft( $webArgs->{windspeed_avg2m} ); UConv::kph2bft( $webArgs->{windspeed_avg2m} );
readingsUnitBulkUpdate( $hash, "wind_speed_bft_avg2m", readingsBulkUpdate( $hash, "wind_speed_bft_avg2m",
$webArgs->{windspeedbft_avg2m} ); $webArgs->{windspeedbft_avg2m} );
} }
@ -973,7 +1021,7 @@ sub HP1000_CGI() {
if ( defined( $webArgs->{windspeed_avg2m} ) ) { if ( defined( $webArgs->{windspeed_avg2m} ) ) {
$webArgs->{windspeedkn_avg2m} = $webArgs->{windspeedkn_avg2m} =
UConv::kph2kn( $webArgs->{windspeed_avg2m} ); UConv::kph2kn( $webArgs->{windspeed_avg2m} );
readingsUnitBulkUpdate( $hash, "wind_speed_kn_avg2m", readingsBulkUpdate( $hash, "wind_speed_kn_avg2m",
$webArgs->{windspeedkn_avg2m} ); $webArgs->{windspeedkn_avg2m} );
} }
@ -982,7 +1030,7 @@ sub HP1000_CGI() {
my $v = UConv::kph2mps( $webArgs->{windspeed_avg2m} ); my $v = UConv::kph2mps( $webArgs->{windspeed_avg2m} );
$webArgs->{windspeedmps_avg2m} = $webArgs->{windspeedmps_avg2m} =
( $v > 0.5 ? round( $v, 1 ) : "0.0" ); ( $v > 0.5 ? round( $v, 1 ) : "0.0" );
readingsUnitBulkUpdate( $hash, "wind_speed_mps_avg2m", readingsBulkUpdate( $hash, "wind_speed_mps_avg2m",
$webArgs->{windspeedmps_avg2m} ); $webArgs->{windspeedmps_avg2m} );
} }
@ -992,7 +1040,7 @@ sub HP1000_CGI() {
HP1000_GetSum( $hash, "windgust", 10 * 60, $webArgs->{windgust} ); HP1000_GetSum( $hash, "windgust", 10 * 60, $webArgs->{windgust} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsUnitBulkUpdate( $hash, "wind_gust_sum10m", $v ); readingsBulkUpdate( $hash, "wind_gust_sum10m", $v );
$webArgs->{windgust_10m} = $v; $webArgs->{windgust_10m} = $v;
} }
} }
@ -1004,7 +1052,7 @@ sub HP1000_CGI() {
$webArgs->{windgustmph} ); $webArgs->{windgustmph} );
if ( $hash->{INTERVAL} > 0 ) { if ( $hash->{INTERVAL} > 0 ) {
readingsUnitBulkUpdate( $hash, "wind_gust_mph_sum10m", $v ); readingsBulkUpdate( $hash, "wind_gust_mph_sum10m", $v );
$webArgs->{windgustmph_10m} = $v; $webArgs->{windgustmph_10m} = $v;
} }
} }
@ -1030,8 +1078,8 @@ sub HP1000_CGI() {
getMultiValStatus( $name, $stateReadings, getMultiValStatus( $name, $stateReadings,
$stateReadingsLang, $stateReadingsFormat ); $stateReadingsLang, $stateReadingsFormat );
readingsUnitBulkUpdate( $hash, "state", $result ); readingsBulkUpdate( $hash, "state", $result );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
HP1000_PushWU( $hash, $webArgs ) HP1000_PushWU( $hash, $webArgs )
if AttrVal( $name, "wu_push", 0 ) eq "1"; 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"; my $return = "error: missing attributes wu_user and wu_password";
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return ); readingsBulkUpdateIfChanged( $hash, "wu_state", $return );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
return; return;
} }
@ -1228,9 +1276,9 @@ sub HP1000_ReturnSrv($$$) {
my $return = "error: connection timeout"; my $return = "error: connection timeout";
Log3 $name, 4, "HP1000 $name: EXTSRV HTTP " . $return; Log3 $name, 4, "HP1000 $name: EXTSRV HTTP " . $return;
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUnitBulkUpdateIfChanged( $hash, "extsrv_state", $return ); readingsBulkUpdateIfChanged( $hash, "extsrv_state", $return );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
} }
# data received # data received
@ -1245,9 +1293,9 @@ sub HP1000_ReturnSrv($$$) {
Log3 $name, $logprio, Log3 $name, $logprio,
"HP1000 $name: EXTSRV HTTP return: " . $param->{code} . " - $data"; "HP1000 $name: EXTSRV HTTP return: " . $param->{code} . " - $data";
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUnitBulkUpdateIfChanged( $hash, "extsrv_state", $return ); readingsBulkUpdateIfChanged( $hash, "extsrv_state", $return );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
} }
return; return;
@ -1264,9 +1312,9 @@ sub HP1000_ReturnWU($$$) {
my $return = "error: connection timeout"; my $return = "error: connection timeout";
Log3 $name, 4, "HP1000 $name: WU HTTP " . $return; Log3 $name, 4, "HP1000 $name: WU HTTP " . $return;
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return ); readingsBulkUpdateIfChanged( $hash, "wu_state", $return );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
} }
# data received # data received
@ -1283,9 +1331,9 @@ sub HP1000_ReturnWU($$$) {
Log3 $name, $logprio, Log3 $name, $logprio,
"HP1000 $name: WU HTTP return: " . $param->{code} . " - $data"; "HP1000 $name: WU HTTP return: " . $param->{code} . " - $data";
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
readingsUnitBulkUpdateIfChanged( $hash, "wu_state", $return ); readingsBulkUpdateIfChanged( $hash, "wu_state", $return );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
} }
return; return;

View File

@ -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 " "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; . $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; return;
} }
@ -239,7 +353,7 @@ sub Wunderground_ReceiveCommand($$$) {
Log3 $name, 5, Log3 $name, 5,
"Wunderground $name: called function Wunderground_ReceiveCommand()"; "Wunderground $name: called function Wunderground_ReceiveCommand()";
readingsUnitBeginUpdate($hash); readingsBeginUpdate($hash);
# service not reachable # service not reachable
if ($err) { if ($err) {
@ -292,10 +406,10 @@ sub Wunderground_ReceiveCommand($$$) {
getMultiValStatus( $name, $stateReadings, getMultiValStatus( $name, $stateReadings,
$stateReadingsLang, $stateReadingsFormat ); $stateReadingsLang, $stateReadingsFormat );
readingsUnitBulkUpdate( $hash, "state", $state ); readingsBulkUpdate( $hash, "state", $state );
readingsUnitBulkUpdateIfChanged( $hash, "lastQueryResult", readingsBulkUpdateIfChanged( $hash, "lastQueryResult",
$lastQueryResult ); $lastQueryResult );
readingsUnitEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
return; return;
} }
@ -382,16 +496,16 @@ sub Wunderground_Hash2Readings($$;$) {
$moonset =~ s/^(\d):(\d\d)$/0$1:$2/; $moonset =~ s/^(\d):(\d\d)$/0$1:$2/;
$moonset =~ s/^(\d\d):(\d)$/$1:0$2/; $moonset =~ s/^(\d\d):(\d)$/$1:0$2/;
readingsUnitBulkUpdate( $hash, "sunrise", $sunrise ); readingsBulkUpdate( $hash, "sunrise", $sunrise );
readingsUnitBulkUpdate( $hash, "sunset", $sunset ); readingsBulkUpdate( $hash, "sunset", $sunset );
readingsUnitBulkUpdate( $hash, "moonrise", $moonrise ); readingsBulkUpdate( $hash, "moonrise", $moonrise );
readingsUnitBulkUpdate( $hash, "moonset", $moonset ); readingsBulkUpdate( $hash, "moonset", $moonset );
readingsUnitBulkUpdate( $hash, "moon_age", readingsBulkUpdate( $hash, "moon_age",
$h->{moon_phase}{ageOfMoon} ); $h->{moon_phase}{ageOfMoon} );
readingsUnitBulkUpdate( $hash, "moon_pct", readingsBulkUpdate( $hash, "moon_pct",
$h->{moon_phase}{percentIlluminated} ); $h->{moon_phase}{percentIlluminated} );
readingsUnitBulkUpdate( $hash, "moon_phase", readingsBulkUpdate( $hash, "moon_phase",
$h->{moon_phase}{phaseofMoon} ); $h->{moon_phase}{phaseofMoon} );
} }
@ -402,104 +516,104 @@ sub Wunderground_Hash2Readings($$;$) {
my $period = $h->{period} - 1; my $period = $h->{period} - 1;
$reading = "fc" . $period . "_"; $reading = "fc" . $period . "_";
readingsUnitBulkUpdate( $hash, $reading . "condition", readingsBulkUpdate( $hash, $reading . "condition",
$h->{conditions} ); $h->{conditions} );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "high_c", $reading . "high_c",
$h->{high}{celsius} $h->{high}{celsius}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "high_f", $reading . "high_f",
$h->{high}{fahrenheit} $h->{high}{fahrenheit}
); );
readingsUnitBulkUpdate( $hash, $reading . "humidity", readingsBulkUpdate( $hash, $reading . "humidity",
$h->{avehumidity} ); $h->{avehumidity} );
readingsUnitBulkUpdate( $hash, $reading . "humidity_min", readingsBulkUpdate( $hash, $reading . "humidity_min",
$h->{minhumidity} ); $h->{minhumidity} );
readingsUnitBulkUpdate( $hash, $reading . "humidity_max", readingsBulkUpdate( $hash, $reading . "humidity_max",
$h->{maxhumidity} ); $h->{maxhumidity} );
readingsUnitBulkUpdate( $hash, $reading . "icon", $h->{icon} ); readingsBulkUpdate( $hash, $reading . "icon", $h->{icon} );
readingsUnitBulkUpdate( $hash, $reading . "icon_url", readingsBulkUpdate( $hash, $reading . "icon_url",
$h->{icon_url} ); $h->{icon_url} );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "low_c", $reading . "low_c",
$h->{low}{celsius} $h->{low}{celsius}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "low_f", $reading . "low_f",
$h->{low}{fahrenheit} $h->{low}{fahrenheit}
); );
readingsUnitBulkUpdate( $hash, $reading . "pop", $h->{pop} ); readingsBulkUpdate( $hash, $reading . "pop", $h->{pop} );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "rain_day", $reading . "rain_day",
$h->{qpf_allday}{mm} $h->{qpf_allday}{mm}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "rain_day_in", $reading . "rain_day_in",
$h->{qpf_allday}{in} $h->{qpf_allday}{in}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "rain_night", $reading . "rain_night",
$h->{qpf_night}{mm} $h->{qpf_night}{mm}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "rain_night_in", $reading . "rain_night_in",
$h->{qpf_night}{in} $h->{qpf_night}{in}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "snow_day", $reading . "snow_day",
$h->{snow_allday}{cm} $h->{snow_allday}{cm}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "snow_day_in", $reading . "snow_day_in",
$h->{snow_allday}{in} $h->{snow_allday}{in}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "snow_night", $reading . "snow_night",
$h->{snow_night}{cm} $h->{snow_night}{cm}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "snow_night_in", $reading . "snow_night_in",
$h->{snow_night}{in} $h->{snow_night}{in}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "wind_direction", $reading . "wind_direction",
$h->{avewind}{degrees} $h->{avewind}{degrees}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "wind_direction_max", $reading . "wind_direction_max",
$h->{maxwind}{degrees} $h->{maxwind}{degrees}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "wind_speed", $reading . "wind_speed",
$h->{avewind}{kph} $h->{avewind}{kph}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "wind_speed_mph", $reading . "wind_speed_mph",
$h->{avewind}{mph} $h->{avewind}{mph}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "wind_speed_max", $reading . "wind_speed_max",
$h->{maxwind}{kph} $h->{maxwind}{kph}
); );
readingsUnitBulkUpdate( readingsBulkUpdate(
$hash, $hash,
$reading . "wind_speed_max_mph", $reading . "wind_speed_max_mph",
$h->{maxwind}{mph} $h->{maxwind}{mph}
@ -532,17 +646,17 @@ sub Wunderground_Hash2Readings($$;$) {
$reading = "fc" . $period . "_"; $reading = "fc" . $period . "_";
readingsUnitBulkUpdate( $hash, $reading . "icon$night", readingsBulkUpdate( $hash, $reading . "icon$night",
$h->{icon} ); $h->{icon} );
readingsUnitBulkUpdate( $hash, $reading . "icon_url$night", readingsBulkUpdate( $hash, $reading . "icon_url$night",
$h->{icon_url} ); $h->{icon_url} );
readingsUnitBulkUpdate( $hash, $reading . "pop$night", readingsBulkUpdate( $hash, $reading . "pop$night",
$h->{pop} ); $h->{pop} );
readingsUnitBulkUpdate( $hash, $reading . "text$night", readingsBulkUpdate( $hash, $reading . "text$night",
$h->{fcttext_metric} ); $h->{fcttext_metric} );
readingsUnitBulkUpdate( $hash, $reading . "text_f$night", readingsBulkUpdate( $hash, $reading . "text_f$night",
$h->{fcttext} ); $h->{fcttext} );
readingsUnitBulkUpdate( $hash, $reading . "title$night", readingsBulkUpdate( $hash, $reading . "title$night",
$h->{title} ); $h->{title} );
} }
@ -565,7 +679,7 @@ sub Wunderground_Hash2Readings($$;$) {
$value =~ s/^(\d+)%$/$1/; $value =~ s/^(\d+)%$/$1/;
readingsUnitBulkUpdate( $hash, $reading, $value ); readingsBulkUpdate( $hash, $reading, $value );
} }
} }
} }
@ -577,7 +691,7 @@ sub Wunderground_Hash2Readings($$;$) {
Wunderground_Hash2Readings( $hash, $_, $r . $i ); Wunderground_Hash2Readings( $hash, $_, $r . $i );
} }
else { else {
readingsUnitBulkUpdate( $hash, $r . $i, $_ ); readingsBulkUpdate( $hash, $r . $i, $_ );
} }
$i++; $i++;

View File

@ -549,6 +549,25 @@ sub activity2log($) {
return "0"; 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 # HELPER FUNCTIONS

File diff suppressed because it is too large Load Diff