mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
added UV sensors to TRX_WEATHER, on-till and on-timer for TRX_LIGHT
git-svn-id: https://svn.fhem.de/fhem/trunk@2335 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
00ff83e6d3
commit
4167903958
@ -35,6 +35,8 @@
|
||||
- feature: added support for KD101 smoke sensor (also set alert and pair) in TRX_SECURITY using RFXtrx433 (Willi Herzig)
|
||||
- change: changed dewpoint to work with event-on-change-reading and technoline TX3TH (Willi Herzig)
|
||||
- feature: new command fheminfo. Shows system informations. (M. Fischer)
|
||||
- feature: added support for UV sensors in TRX_LIGHT using RFXtrx433 (Willi Herzig)
|
||||
- feature: added on-till and on-timer for set in TRX_LIGHT using RFXtrx433 (Willi Herzig)
|
||||
|
||||
- 2012-10-28 (5.3)
|
||||
- feature: added functions trim, ltrim, rtrim, UntoggleDirect,
|
||||
|
@ -53,7 +53,7 @@ TRX_Initialize($)
|
||||
$hash->{Clients} =
|
||||
":TRX_WEATHER:TRX_SECURITY:TRX_LIGHT:";
|
||||
my %mc = (
|
||||
"1:TRX_WEATHER" => "^..(50|51|52|54|55|56|5a|5d).*",
|
||||
"1:TRX_WEATHER" => "^..(50|51|52|54|55|56|57|5a|5d).*",
|
||||
"2:TRX_SECURITY" => "^..(20).*",
|
||||
"3:TRX_LIGHT" => "^..(10|11|12).*",
|
||||
"4:TRX_ELSE" => "^...*",
|
||||
|
@ -31,7 +31,6 @@
|
||||
# 4: log unknown protocols
|
||||
# 5: log decoding hexlines for debugging
|
||||
#
|
||||
# $Id$
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
@ -122,6 +121,53 @@ TRX_LIGHT_SetState($$$$)
|
||||
return undef;
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
TRX_LIGHT_Do_On_Till($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
return "Timespec (HH:MM[:SS]) needed for the on-till command" if(@a != 3);
|
||||
|
||||
my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($a[2]);
|
||||
return $err if($err);
|
||||
|
||||
my @lt = localtime;
|
||||
my $hms_till = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
|
||||
my $hms_now = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
|
||||
if($hms_now ge $hms_till) {
|
||||
Log 4, "on-till: won't switch as now ($hms_now) is later than $hms_till";
|
||||
return "";
|
||||
}
|
||||
|
||||
my $tname = $hash->{NAME} . "_timer";
|
||||
CommandDelete(undef, $tname) if($defs{$tname});
|
||||
my @b = ($a[0], "on");
|
||||
TRX_LIGHT_Set($hash, @b);
|
||||
CommandDefine(undef, "$tname at $hms_till set $a[0] off");
|
||||
|
||||
}
|
||||
|
||||
|
||||
#############################
|
||||
sub
|
||||
TRX_LIGHT_Do_On_For_Timer($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
return "Timespec (HH:MM[:SS]) needed for the on-for-timer command" if(@a != 3);
|
||||
|
||||
my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($a[2]);
|
||||
return $err if($err);
|
||||
|
||||
my $hms_for_timer = sprintf("+%02d:%02d:%02d", $hr, $min, $sec);
|
||||
|
||||
my $tname = $hash->{NAME} . "_timer";
|
||||
CommandDelete(undef, $tname) if($defs{$tname});
|
||||
my @b = ($a[0], "on");
|
||||
TRX_LIGHT_Set($hash, @b);
|
||||
CommandDefine(undef, "$tname at $hms_for_timer set $a[0] off");
|
||||
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
TRX_LIGHT_Set($@)
|
||||
@ -138,6 +184,12 @@ TRX_LIGHT_Set($@)
|
||||
my $command = $a[1];
|
||||
my $level;
|
||||
|
||||
# special for on-till
|
||||
return TRX_LIGHT_Do_On_Till($hash, @a) if($command eq "on-till");
|
||||
|
||||
# special for on-for-timer
|
||||
return TRX_LIGHT_Do_On_For_Timer($hash, @a) if($command eq "on-for-timer");
|
||||
|
||||
if ($na == 3) {
|
||||
$level = $a[2];
|
||||
} else {
|
||||
@ -153,7 +205,8 @@ TRX_LIGHT_Set($@)
|
||||
|
||||
if ( lc($hash->{TRX_LIGHT_devicelog}) eq "window" || lc($hash->{TRX_LIGHT_devicelog}) eq "door" ||
|
||||
lc($hash->{TRX_LIGHT_devicelog}) eq "motion" ||
|
||||
lc($hash->{TRX_LIGHT_devicelog}) eq "lightsensor" || lc($hash->{TRX_LIGHT_devicelog}) eq "photosensor"
|
||||
lc($hash->{TRX_LIGHT_devicelog}) eq "lightsensor" || lc($hash->{TRX_LIGHT_devicelog}) eq "photosensor" ||
|
||||
lc($hash->{TRX_LIGHT_devicelog}) eq "lock"
|
||||
) {
|
||||
return "No set implemented for $device_type";
|
||||
}
|
||||
@ -176,7 +229,8 @@ TRX_LIGHT_Set($@)
|
||||
if ($device_type eq "AC" || $device_type eq "HOMEEASY" || $device_type eq "ANSLUT") {
|
||||
$l =~ s/ level / level:slider,0,1,15 /;
|
||||
}
|
||||
my $error = "Unknown command $command, choose one of $l";
|
||||
#my $error = "Unknown command $command, choose one of $l";
|
||||
my $error = "Unknown command $command, choose one of $l "."on-till on-for-timer";
|
||||
|
||||
Log 4, $error;
|
||||
return $error;
|
||||
@ -471,6 +525,8 @@ sub TRX_LIGHT_parse_X10 {
|
||||
$command = ($command eq "on") ? "alert" : "normal" ;
|
||||
} elsif (lc($def->{TRX_LIGHT_devicelog}) eq "lightsensor" || lc($def->{TRX_LIGHT_devicelog}) eq "photosensor") {
|
||||
$command = ($command eq "on") ? "dark" : "bright" ;
|
||||
} elsif (lc($def->{TRX_LIGHT_devicelog}) eq "lock") {
|
||||
$command = ($command eq "on") ? "Closed" : "Open" ;
|
||||
}
|
||||
|
||||
readingsBeginUpdate($def);
|
||||
@ -640,10 +696,27 @@ KlikAanKlikUit, NEXA, CHACON, HomeEasy UK. <br> You need to define an RFXtrx433
|
||||
all_on # only for X10, ARC, EMW200, AC, HOMEEASY, ANSLUT
|
||||
chime # only for ARC
|
||||
level <levelnum> # only AC, HOMEEASY, ANSLUT: set level to <levelnum> (range: 0=0% to 15=100%)
|
||||
on-till # Special, see the note
|
||||
on-for-timer # Special, see the note
|
||||
</pre>
|
||||
Example: <br>
|
||||
<code>set Steckdose on</code>
|
||||
<br>
|
||||
<br>
|
||||
Notes:
|
||||
<ul>
|
||||
<li><code>on-till</code> requires an absolute time in the "at" format
|
||||
(HH:MM:SS, HH:MM) or { <perl code> }, where the perl code
|
||||
returns a time specification).
|
||||
If the current time is greater than the specified time, then the
|
||||
command is ignored, else an "on" command is generated, and for the
|
||||
given "till-time" an off command is scheduleld via the at command.
|
||||
</li>
|
||||
<li><code>on-for-timer</code> requires a relative time in the "at" format
|
||||
(HH:MM:SS, HH:MM) or { <perl code> }, where the perl code
|
||||
returns a time specification).
|
||||
</li>
|
||||
</ul>
|
||||
</ul><br>
|
||||
|
||||
<a name="TRX_LIGHTget"></a>
|
||||
|
@ -43,7 +43,12 @@
|
||||
# * "WGR800_A" is WGR800
|
||||
# * "WGR918" is STR918, WGR918
|
||||
# * "TFA_WIND" is TFA
|
||||
# * "WDS500" is UPM WDS500
|
||||
# * "WDS500" is UPM WDS500u
|
||||
#
|
||||
# UV Sensors:
|
||||
# "UVN128" is Oregon UVN128, UV138
|
||||
# "UVN800" is Oregon UVN800
|
||||
# "TFA_UV" is TFA_UV-Sensor
|
||||
#
|
||||
# Energy Sensors:
|
||||
# * "CM160" is OWL CM119, CM160
|
||||
@ -94,7 +99,7 @@ TRX_WEATHER_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{Match} = "^..(50|51|52|54|55|56|5a|5d).*";
|
||||
$hash->{Match} = "^..(50|51|52|54|55|56|57|5a|5d).*";
|
||||
$hash->{DefFn} = "TRX_WEATHER_Define";
|
||||
$hash->{UndefFn} = "TRX_WEATHER_Undef";
|
||||
$hash->{ParseFn} = "TRX_WEATHER_Parse";
|
||||
@ -160,6 +165,8 @@ my %types =
|
||||
0x550b => { part => 'RAIN', method => \&TRX_WEATHER_common_rain, },
|
||||
# WIND
|
||||
0x5610 => { part => 'WIND', method => \&TRX_WEATHER_common_anemometer, },
|
||||
# UV
|
||||
0x5709 => { part => 'UV', method => \&TRX_WEATHER_common_uv, },
|
||||
# Energy usage sensors
|
||||
0x5A11 => { part => 'ENERGY', method => \&TRX_WEATHER_common_energy, },
|
||||
# WEIGHT
|
||||
@ -656,6 +663,82 @@ sub TRX_WEATHER_common_rain {
|
||||
return @res;
|
||||
}
|
||||
|
||||
my @uv_str =
|
||||
(
|
||||
qw/low low low/, # 0 - 2
|
||||
qw/medium medium medium/, # 3 - 5
|
||||
qw/high high/, # 6 - 7
|
||||
'very high', 'very high', 'very high', # 8 - 10
|
||||
);
|
||||
|
||||
sub TRX_WEATHER_uv_string {
|
||||
$uv_str[$_[0]] || 'dangerous';
|
||||
}
|
||||
|
||||
# -----------------------------
|
||||
sub TRX_WEATHER_common_uv {
|
||||
my $type = shift;
|
||||
my $longids = shift;
|
||||
my $bytes = shift;
|
||||
|
||||
my $subtype = sprintf "%02x", $bytes->[1];
|
||||
#Log 1,"subtype=$subtype";
|
||||
my $dev_type;
|
||||
|
||||
my %devname =
|
||||
( # HEXSTRING => "NAME"
|
||||
0x01 => "UVN128", # Oregon UVN128, UV138
|
||||
0x02 => "UVN800", # Oregon UVN800
|
||||
0x03 => "TFA_UV", # TFA_UV-Sensor
|
||||
);
|
||||
|
||||
if (exists $devname{$bytes->[1]}) {
|
||||
$dev_type = $devname{$bytes->[1]};
|
||||
} else {
|
||||
Log 1,"RFX_WEATHER: common_uv error undefined subtype=$subtype";
|
||||
my @res = ();
|
||||
return @res;
|
||||
}
|
||||
|
||||
#my $seqnbr = sprintf "%02x", $bytes->[2];
|
||||
#Log 1,"seqnbr=$seqnbr";
|
||||
|
||||
my $dev_str = $dev_type;
|
||||
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
|
||||
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
|
||||
}
|
||||
if ($bytes->[4] > 0) {
|
||||
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
|
||||
}
|
||||
#Log 1,"dev_str=$dev_str";
|
||||
|
||||
my @res = ();
|
||||
|
||||
# hexline debugging
|
||||
if ($TRX_HEX_debug) {
|
||||
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
|
||||
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
|
||||
}
|
||||
|
||||
my $uv = $bytes->[5]/10; # UV
|
||||
my $risk = TRX_WEATHER_uv_string(int($uv));
|
||||
|
||||
push @res, {
|
||||
device => $dev_str,
|
||||
type => 'uv',
|
||||
current => $uv,
|
||||
risk => $risk,
|
||||
units => '',
|
||||
};
|
||||
|
||||
|
||||
if ($dev_type eq "TFA_UV") {
|
||||
TRX_WEATHER_temperature($bytes, $dev_str, \@res, 6);
|
||||
}
|
||||
TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 8);
|
||||
return @res;
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------
|
||||
#
|
||||
sub TRX_WEATHER_common_energy {
|
||||
|
Loading…
Reference in New Issue
Block a user