diff --git a/FHEM/21_OWID.pm b/FHEM/21_OWID.pm
index f226d444d..248e64189 100644
--- a/FHEM/21_OWID.pm
+++ b/FHEM/21_OWID.pm
@@ -19,6 +19,8 @@
# is a 12 character (6 byte) 1-Wire ROM ID
# without Family ID, e.g. A2D90D000800
#
+# set interval => set query interval for checking presence
+#
# get id => FAM_ID.ROM_ID.CRC
# get present => 1 if device present, 0 if not
#
@@ -51,10 +53,15 @@ sub Log($$);
#-- declare variables
my %gets = (
"present" => "",
+ "interval" => "",
"id" => ""
);
-my %sets = ();
-my %updates = ();
+my %sets = (
+ "interval" => ""
+);
+my %updates = (
+ "present" => ""
+);
########################################################################################
#
@@ -76,8 +83,9 @@ sub OWID_Initialize ($) {
$hash->{DefFn} = "OWID_Define";
$hash->{UndefFn} = "OWID_Undef";
$hash->{GetFn} = "OWID_Get";
- $hash->{SetFn} = undef;
- my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model loglevel:0,1,2,3,4,5 ";
+ $hash->{SetFn} = "OWID_Set";
+ my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model loglevel:0,1,2,3,4,5 ".
+ $readingFnAttributes;
$hash->{AttrList} = $attlist;
}
@@ -95,23 +103,26 @@ sub OWID_Define ($$) {
#-- define OWID
my @a = split("[ \t][ \t]*", $def);
- my ($name,$fam,$id,$crc,$ret);
+ my ($name,$interval,$fam,$id,$crc,$ret);
#-- default
$name = $a[0];
+ $interval = 300;
$ret = "";
#-- check syntax
- return "OWID: Wrong syntax, must be define OWID "
+ return "OWID: Wrong syntax, must be define OWID [interval]"
if(int(@a) !=4 );
#-- check id
if( ($a[2] =~ m/^[0-9|a-f|A-F]{2}$/) && ($a[3] =~ m/^[0-9|a-f|A-F]{12}$/)) {
$fam = $a[2];
$id = $a[3];
+ if(int(@a)>=5) { $interval = $a[4]; }
} elsif( $a[2] =~ m/^0-9|a-f|A-F]{2}\.[0-9|a-f|A-F]{12}$/ ) {
$fam = substr($a[2],0,2);
$id = substr($a[2],3);
+ if(int(@a)>=4) { $interval = $a[3]; }
} else {
return "OWID: $def is invalid, specify a 2 digit 12 digit or 2.12 digit value";
}
@@ -125,6 +136,7 @@ sub OWID_Define ($$) {
$hash->{OW_ID} = $id;
$hash->{OW_FAMILY} = $fam;
$hash->{PRESENT} = 0;
+ $hash->{INTERVAL} = $interval;
#-- Couple to I/O device
AssignIoPort($hash);
@@ -141,6 +153,10 @@ sub OWID_Define ($$) {
#-- Initialization reading according to interface type
my $interface= $hash->{IODev}->{TYPE};
+
+ #-- Start timer for updates
+ InternalTimer(time()+5+$hash->{INTERVAL}, "OWID_GetValues", $hash, 0);
+
#--
readingsSingleUpdate($hash,"state","Initialized",1);
return undef;
@@ -179,16 +195,103 @@ sub OWID_Get($@) {
return "$name.id => $value";
}
+ #-- get interval
+ if($a[1] eq "interval") {
+ $value = $hash->{INTERVAL};
+ return "$name.interval => $value";
+ }
+
#-- get present
if($a[1] eq "present") {
#-- hash of the busmaster
my $master = $hash->{IODev};
$value = OWX_Verify($master,$hash->{ROM_ID});
$hash->{PRESENT} = $value;
+ if( $value == 0 ){
+ readingsSingleUpdate($hash,"state","not present",1);
+ } else {
+ readingsSingleUpdate($hash,"state","present",1);
+ }
return "$name.present => $value";
}
}
+
+########################################################################################
+#
+# OWID_GetValues - Updates the reading from one device
+#
+# Parameter hash = hash of device addressed
+########################################################################################
+
+sub OWID_GetValues($) {
+ my $hash = shift;
+
+ my $name = $hash->{NAME};
+ my $value = "";
+ my $ret = "";
+ my $offset;
+ my $factor;
+
+ #-- restart timer for updates
+ RemoveInternalTimer($hash);
+ InternalTimer(time()+$hash->{INTERVAL}, "OWID_GetValues", $hash, 1);
+
+ #-- hash of the busmaster
+ my $master = $hash->{IODev};
+ $value = OWX_Verify($master,$hash->{ROM_ID});
+ $hash->{PRESENT} = $value;
+ if( $value == 0 ){
+ readingsSingleUpdate($hash,"state","not present",1);
+ } else {
+ readingsSingleUpdate($hash,"state","present",1);
+ }
+}
+
+#######################################################################################
+#
+# OWID_Set - Set one value for device
+#
+# Parameter hash = hash of device addressed
+# a = argument array
+#
+########################################################################################
+
+sub OWID_Set($@) {
+ my ($hash, @a) = @_;
+
+ my $key = $a[1];
+ my $value = $a[2];
+
+ #-- for the selector: which values are possible
+ if (@a == 2){
+ my $newkeys = join(" ", keys %sets);
+ return $newkeys ;
+ }
+
+ #-- check syntax
+ return "OWID: Set needs at least one parameter"
+ if( int(@a)<3 );
+ #-- check argument
+ if( !defined($sets{$a[1]}) ){
+ return "OWID: Set with unknown argument $a[1]";
+ }
+
+ my $name = $hash->{NAME};
+
+ #-- set new timer interval
+ if($key eq "interval") {
+ # check value
+ return "OWID: Set with short interval, must be > 1"
+ if(int($value) < 1);
+ # update timer
+ $hash->{INTERVAL} = $value;
+ RemoveInternalTimer($hash);
+ InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWID_GetValues", $hash, 1);
+ return undef;
+ }
+}
+
########################################################################################
#
# OWID_Undef - Implements UndefFn function
@@ -216,14 +319,14 @@ sub OWID_Undef ($) {
Please define an OWX device or OWServer device first.
Example
- define ROM1 OWX_ID OWCOUNT 09.CE780F000000
+ define ROM1 OWX_ID OWCOUNT 09.CE780F000000 10
Define
- define <name> OWID <fam> <id>
or
- define <name> OWID <fam>.<id>
+ define <name> OWID <fam> <id> [<interval>]
or
+ define <name> OWID <fam>.<id> [<interval>]
Define a 1-Wire device.
@@ -236,6 +339,17 @@ sub OWID_Undef ($) {
12-character unique ROM id of the converter device without family id and CRC
code
+ -
+
<interval>
+
Interval in seconds for checking the presence of the device. The default is 300 seconds.
+
+
+
+ Set
+