mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-15 22:26:04 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@2017 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
99829d52a4
commit
1195ea6763
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,212 +0,0 @@
|
||||
########################################################################################
|
||||
#
|
||||
# OWID.pm
|
||||
#
|
||||
# FHEM module to commmunicate with general 1-Wire ID-ROMS
|
||||
#
|
||||
# Attention: This module may communicate with the OWX module,
|
||||
# but currently not with the 1-Wire File System OWFS
|
||||
#
|
||||
# Prefixes for subroutines of this module:
|
||||
# OW = General 1-Wire routines Peter Henning)
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
#
|
||||
# Version 2.24 - October, 2012
|
||||
#
|
||||
# Setup bus device in fhem.cfg as
|
||||
#
|
||||
# define <name> OWID <FAM_ID> <ROM_ID>
|
||||
#
|
||||
# where <name> may be replaced by any name string
|
||||
#
|
||||
# <FAM_ID> is a 2 character (1 byte) 1-Wire Family ID
|
||||
#
|
||||
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
||||
# without Family ID, e.g. A2D90D000800
|
||||
#
|
||||
# get <name> id => FAM_ID.ROM_ID.CRC
|
||||
# get <name> present => 1 if device present, 0 if not
|
||||
#
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# This programm is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
########################################################################################
|
||||
package main;
|
||||
|
||||
#-- Prototypes to make komodo happy
|
||||
use vars qw{%attr %defs};
|
||||
use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
#-- declare variables
|
||||
my %gets = (
|
||||
"present" => "",
|
||||
"id" => ""
|
||||
);
|
||||
my %sets = ();
|
||||
my %updates = ();
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines are independent of the bus interface
|
||||
#
|
||||
# Prefix = OWID
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWID_Initialize
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWID_Initialize ($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
$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 loglevel:0,1,2,3,4,5 ";
|
||||
$hash->{AttrList} = $attlist;
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
#
|
||||
# OWID_Define - Implements DefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, def = definition string
|
||||
#
|
||||
#########################################################################################
|
||||
|
||||
sub OWID_Define ($$) {
|
||||
my ($hash, $def) = @_;
|
||||
|
||||
#-- define <name> OWID <FAM_ID> <ROM_ID>
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
my ($name,$fam,$id,$crc,$ret);
|
||||
|
||||
#-- default
|
||||
$name = $a[0];
|
||||
$ret = "";
|
||||
|
||||
#-- check syntax
|
||||
return "OWID: Wrong syntax, must be define <name> OWID <fam> <id>"
|
||||
if(int(@a) !=4 );
|
||||
|
||||
#-- check id
|
||||
if( $a[2] =~ m/^[0-9|a-f|A-F]{2}$/ ) {
|
||||
$fam = $a[2];
|
||||
} else {
|
||||
return "OWID: $a[0] family id $a[2] invalid, specify a 2 digit value";
|
||||
}
|
||||
if( $a[3] =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||
$id = $a[3];
|
||||
} else {
|
||||
return "OWID: $a[0] ID $a[3] invalid, specify a 12 digit value";
|
||||
}
|
||||
|
||||
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
||||
# determine CRC Code YY - only if this is a direct interface
|
||||
$crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC($fam.".".$id."00")) : "00";
|
||||
|
||||
#-- Define device internals
|
||||
$hash->{ROM_ID} = $fam.".".$id.$crc;
|
||||
$hash->{OW_ID} = $id;
|
||||
$hash->{OW_FAMILY} = $fam;
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
Log 3, "OWID: Warning, no 1-Wire I/O device found for $name."
|
||||
if(!defined($hash->{IODev}->{NAME}));
|
||||
|
||||
$modules{OWID}{defptr}{$id} = $hash;
|
||||
|
||||
$hash->{STATE} = "Defined";
|
||||
Log 3, "OWID: Device $name defined.";
|
||||
|
||||
#-- Initialization reading according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
$hash->{STATE} = "Initialized";
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWID_Get - Implements GetFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWID_Get($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
my $reading = $a[1];
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
my $value = undef;
|
||||
my $ret = "";
|
||||
my $offset;
|
||||
my $factor;
|
||||
|
||||
#-- check syntax
|
||||
return "OWID: Get argument is missing @a"
|
||||
if(int(@a) != 2);
|
||||
|
||||
#-- check argument
|
||||
return "OWID: Get with unknown argument $a[1], choose one of ".join(",", sort keys %gets)
|
||||
if(!defined($gets{$a[1]}));
|
||||
|
||||
#-- get id
|
||||
if($a[1] eq "id") {
|
||||
$value = $hash->{ROM_ID};
|
||||
return "$name.id => $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;
|
||||
return "$name.present => $value";
|
||||
}
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWID_Undef - Implements UndefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWID_Undef ($) {
|
||||
my ($hash) = @_;
|
||||
delete($modules{OWID}{defptr}{$hash->{OW_ID}});
|
||||
RemoveInternalTimer($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
File diff suppressed because it is too large
Load Diff
@ -1,850 +0,0 @@
|
||||
########################################################################################
|
||||
#
|
||||
# OWMULTI.pm
|
||||
#
|
||||
# FHEM module to commmunicate with 1-Wire chip DS2438Z - Smart Battery Monitor
|
||||
#
|
||||
# Prefixes for subroutines of this module:
|
||||
# OW = General 1-Wire routines (Martin Fischer, Peter Henning)
|
||||
# OWX = 1-Wire bus master interface (Peter Henning)
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
#
|
||||
# Version 2.24 - October, 2012
|
||||
#
|
||||
# Setup bus device in fhem.cfg as
|
||||
#
|
||||
# define <name> OWMULTI [<model>] <ROM_ID> [interval]
|
||||
#
|
||||
# where <name> may be replaced by any name string
|
||||
#
|
||||
# <model> is a 1-Wire device type. If omitted, we assume this to be an
|
||||
# DS2438
|
||||
#
|
||||
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
||||
# without Family ID, e.g. A2D90D000800
|
||||
# [interval] is an optional query interval in seconds
|
||||
#
|
||||
# get <name> id => OW_FAMILY.ROM_ID.CRC
|
||||
# get <name> present => 1 if device present, 0 if not
|
||||
# get <name> interval => query interval
|
||||
# get <name> reading => measurement value obtained from VFunction
|
||||
# get <name> temperature => temperature measurement
|
||||
# get <name> VDD => supply voltage measurement
|
||||
# get <name> V|raw => raw external voltage measurement
|
||||
#
|
||||
# set <name> interval => set period for measurement
|
||||
#
|
||||
# Additional attributes are defined in fhem.cfg
|
||||
# Note: attributes "tempXXXX" are read during every update operation.
|
||||
#
|
||||
# attr <name> event on-change/on-update = when to write an event (default= on-update)
|
||||
#
|
||||
# attr <name> tempOffset <float> = temperature offset in degree Celsius added to the raw temperature reading
|
||||
# attr <name> tempUnit <string> = unit of measurement, e.g. Celsius/Kelvin/Fahrenheit or C/K/F, default is Celsius
|
||||
# attr <name> VName <string>|<string> = name for the channel | a type description for the measured value
|
||||
# attr <name> VUnit <string>|<string> = unit of measurement for the voltage channel | its abbreviation
|
||||
# attr <name> Vfunction <string> = arbitrary functional expression involving the values VDD, V, T
|
||||
# VDD is replaced by the measured supply voltage in Volt,
|
||||
# V by the measured external voltage
|
||||
# T by the measured and corrected temperature in its unit
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# This programm is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
########################################################################################
|
||||
package main;
|
||||
|
||||
#-- Prototypes to make komodo happy
|
||||
use vars qw{%attr %defs};
|
||||
use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
#-- temperature and voltage globals - always the raw values from the device
|
||||
my $owg_temp;
|
||||
my $owg_volt;
|
||||
my $owg_vdd;
|
||||
my $owg_channel;
|
||||
|
||||
my %gets = (
|
||||
"id" => "",
|
||||
"present" => "",
|
||||
"interval" => "",
|
||||
"reading" => "",
|
||||
"temperature" => "",
|
||||
"VDD" => "",
|
||||
"V" => "",
|
||||
"raw" => "",
|
||||
);
|
||||
|
||||
my %sets = (
|
||||
"interval" => "",
|
||||
);
|
||||
|
||||
my %updates = (
|
||||
"present" => "",
|
||||
"reading" => "",
|
||||
);
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines are independent of the bus interface
|
||||
#
|
||||
# Prefix = OWMULTI
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWMULTI_Initialize
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_Initialize ($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "OWMULTI_Define";
|
||||
$hash->{UndefFn} = "OWMULTI_Undef";
|
||||
$hash->{GetFn} = "OWMULTI_Get";
|
||||
$hash->{SetFn} = "OWMULTI_Set";
|
||||
#tempOffset = a temperature offset added to the temperature reading for correction
|
||||
#tempUnit = a unit of measure: C/F/K
|
||||
$hash->{AttrList}= "IODev do_not_notify:0,1 showtime:0,1 loglevel:0,1,2,3,4,5 ".
|
||||
"event:on-update,on-change ".
|
||||
"tempOffset tempUnit:C,Celsius,F,Fahrenheit,K,Kelvin ".
|
||||
"VName VUnit VFunction";
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWMULTI_Define - Implements DefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, def = definition string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_Define ($$) {
|
||||
my ($hash, $def) = @_;
|
||||
|
||||
# define <name> OWMULTI [<model>] <id> [interval]
|
||||
# e.g.: define flow OWMULTI 525715020000 300
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
my ($name,$model,$fam,$id,$crc,$interval,$ret);
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- default
|
||||
$name = $a[0];
|
||||
$interval = 300;
|
||||
$ret = "";
|
||||
|
||||
#-- check syntax
|
||||
return "OWMULTI: Wrong syntax, must be define <name> OWMULTI [<model>] <id> [interval]"
|
||||
if(int(@a) < 2 || int(@a) > 6);
|
||||
|
||||
#-- check if this is an old style definition, e.g. <model> is missing
|
||||
my $a2 = $a[2];
|
||||
my $a3 = defined($a[3]) ? $a[3] : "";
|
||||
if( ($a2 eq "none") || ($a3 eq "none") ) {
|
||||
return "OWMULTI: ID = none is obsolete now, please redefine";
|
||||
} elsif( $a2 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||
$model = "DS2438";
|
||||
$id = $a[2];
|
||||
if(int(@a)>=4) { $interval = $a[3]; }
|
||||
Log 1, "OWMULTI: Parameter [alarminterval] is obsolete now - must be set with I/O-Device"
|
||||
if(int(@a) == 5);
|
||||
} elsif( $a3 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||
$model = $a[2];
|
||||
$id = $a[3];
|
||||
if(int(@a)>=5) { $interval = $a[4]; }
|
||||
Log 1, "OWMULTI: Parameter [alarminterval] is obsolete now - must be set with I/O-Device"
|
||||
if(int(@a) == 6);
|
||||
} else {
|
||||
return "OWMULTI: $a[0] ID $a[2] invalid, specify a 12 digit value";
|
||||
}
|
||||
|
||||
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
||||
# FF = family id follows from the model
|
||||
# YY must be determined from id
|
||||
if( $model eq "DS2438" ){
|
||||
$fam = "26";
|
||||
}else{
|
||||
return "OWMULTI: Wrong 1-Wire device model $model";
|
||||
}
|
||||
# determine CRC Code - only if this is a direct interface
|
||||
$crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC($fam.".".$id."00")) : "00";
|
||||
|
||||
#-- define device internals
|
||||
$hash->{OW_ID} = $id;
|
||||
$hash->{OW_FAMILY} = $fam;
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{ROM_ID} = $fam.".".$id.$crc;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
Log 3, "OWMULTI: Warning, no 1-Wire I/O device found for $name."
|
||||
if(!defined($hash->{IODev}->{NAME}));
|
||||
$modules{OWMULTI}{defptr}{$id} = $hash;
|
||||
$hash->{STATE} = "Defined";
|
||||
Log 3, "OWMULTI: Device $name defined.";
|
||||
|
||||
#-- Start timer for initialization in a few seconds
|
||||
InternalTimer(time()+10, "OWMULTI_InitializeDevice", $hash, 0);
|
||||
|
||||
#-- Start timer for updates
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWMULTI_GetValues", $hash, 0);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWMULTI_InitializeDevice - delayed setting of initial readings and channel names
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_InitializeDevice($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my @args;
|
||||
|
||||
#-- unit attribute defined ?
|
||||
$hash->{READINGS}{"temperature"}{UNIT} = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : "Celsius";
|
||||
$hash->{READINGS}{"temperature"}{TYPE} = "temperature";
|
||||
|
||||
#-- Initial readings temperature sensor
|
||||
$owg_temp = 0.0;
|
||||
$owg_volt = 0.0;
|
||||
$owg_vdd = 5.0;
|
||||
#-- Set channel name, channel unit for voltage channel
|
||||
my $cname = defined($attr{$name}{"VName"}) ? $attr{$name}{"VName"} : "voltage|voltage";
|
||||
my @cnama = split(/\|/,$cname);
|
||||
if( int(@cnama)!=2){
|
||||
Log 1, "OWMULTI: Incomplete channel name specification $cname. Better use $cname|<type of data>";
|
||||
push(@cnama,"unknown");
|
||||
}
|
||||
|
||||
#-- unit
|
||||
my $unit = defined($attr{$name}{"VUnit"}) ? $attr{$name}{"VUnit"} : "Volt|V";
|
||||
my @unarr= split(/\|/,$unit);
|
||||
if( int(@unarr)!=2 ){
|
||||
Log 1, "OWMULTI: Incomplete channel unit specification $unit. Better use $unit|<abbreviation>";
|
||||
push(@unarr,"");
|
||||
}
|
||||
|
||||
#-- put into readings
|
||||
$owg_channel = $cnama[0];
|
||||
$hash->{READINGS}{"$owg_channel"}{TYPE} = $cnama[1];
|
||||
$hash->{READINGS}{"$owg_channel"}{UNIT} = $unarr[0];
|
||||
$hash->{READINGS}{"$owg_channel"}{UNITABBR} = $unarr[1];
|
||||
|
||||
#-- Initialize all the display stuff
|
||||
OWMULTI_FormatValues($hash);
|
||||
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWMULTI_FormatValues - put together various format strings
|
||||
#
|
||||
# Parameter hash = hash of device addressed, fs = format string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_FormatValues($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my ($tunit,$toffset,$tfactor,$tabbr,$tval,$vfunc,$vval);
|
||||
my ($value1,$value2) = ("","");
|
||||
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- attributes defined ?
|
||||
$tunit = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : $hash->{READINGS}{"temperature"}{UNIT};
|
||||
$toffset = defined($attr{$name}{"tempOffset"}) ? $attr{$name}{"tempOffset"} : 0.0 ;
|
||||
$tfactor = 1.0;
|
||||
|
||||
if( $tunit eq "Celsius" ){
|
||||
$tabbr = "°C";
|
||||
} elsif ($tunit eq "Kelvin" ){
|
||||
$tabbr = "K";
|
||||
$toffset += "273.16"
|
||||
} elsif ($tunit eq "Fahrenheit" ){
|
||||
$tabbr = "°F";
|
||||
$toffset = ($toffset+32)/1.8;
|
||||
$tfactor = 1.8;
|
||||
} else {
|
||||
$tabbr="?";
|
||||
Log 1, "OWMULTI_FormatValues: unknown unit $tunit";
|
||||
}
|
||||
#-- these values are rather coplex to obtain, therefore save them in the hash
|
||||
$hash->{READINGS}{"temperature"}{UNIT} = $tunit;
|
||||
$hash->{READINGS}{"temperature"}{UNITABBR} = $tabbr;
|
||||
$hash->{tempf}{offset} = $toffset;
|
||||
$hash->{tempf}{factor} = $tfactor;
|
||||
|
||||
#-- correct values for proper offset, factor
|
||||
$tval = ($owg_temp + $toffset)*$tfactor;
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"temperature"}{VAL} = $tval;
|
||||
$hash->{READINGS}{"temperature"}{TIME} = $tn;
|
||||
|
||||
my $cname = defined($attr{$name}{"VName"}) ? $attr{$name}{"VName"} : "voltage|voltage";
|
||||
my @cnama = split(/\|/,$cname);
|
||||
$owg_channel=$cnama[0];
|
||||
|
||||
#-- attribute VFunction defined ?
|
||||
$vfunc = defined($attr{$name}{"VFunction"}) ? $attr{$name}{"VFunction"} : "V";
|
||||
|
||||
#-- replace by proper values
|
||||
$vfunc =~ s/VDD/\$owg_vdd/g;
|
||||
$vfunc =~ s/V/\$owg_volt/g;
|
||||
$vfunc =~ s/T/\$tval/g;
|
||||
|
||||
#-- determine the measured value from the function
|
||||
$vfunc = "\$owg_vdd = $owg_vdd; \$owg_volt = $owg_volt; \$tval = $tval; ".$vfunc;
|
||||
$vfunc = eval($vfunc);
|
||||
if( $vfunc ne "" ){
|
||||
$vval = int( $vfunc*1000 )/1000;
|
||||
} else {
|
||||
$vval = 0.0;
|
||||
}
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"$owg_channel"}{VAL} = $vval;
|
||||
$hash->{READINGS}{"$owg_channel"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"VDD"}{VAL} = $owg_vdd;
|
||||
$hash->{READINGS}{"VDD"}{TIME} = $tn;
|
||||
|
||||
#-- string buildup for return value, STATE
|
||||
$value1 .= sprintf( "%s: %5.3f %s temperature %5.3f %s VDD %5.2f V", $owg_channel, $vval,$hash->{READINGS}{"$owg_channel"}{UNITABBR},$tval,$tabbr,$owg_vdd);
|
||||
$value2 .= sprintf( "%s: %5.2f %s (T: %5.2f %s)", $owg_channel, $vval,$hash->{READINGS}{"$owg_channel"}{UNITABBR},$tval,$tabbr);
|
||||
|
||||
#-- STATE
|
||||
$hash->{STATE} = $value2;
|
||||
|
||||
return $value1;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWMULTI_Get - Implements GetFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_Get($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
my $reading = $a[1];
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
my $value = undef;
|
||||
my $ret = "";
|
||||
|
||||
#-- check syntax
|
||||
return "OWMULTI: Get argument is missing @a"
|
||||
if(int(@a) != 2);
|
||||
|
||||
#-- check argument
|
||||
return "OWMULTI: Get with unknown argument $a[1], choose one of ".join(",", sort keys %gets)
|
||||
if(!defined($gets{$a[1]}));
|
||||
|
||||
#-- get id
|
||||
if($a[1] eq "id") {
|
||||
$value = $hash->{ROM_ID};
|
||||
return "$name.id => $value";
|
||||
}
|
||||
|
||||
#-- Get other values according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- get present
|
||||
if($a[1] eq "present" ) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||
$hash->{PRESENT} = $value;
|
||||
return "$name.present => $value";
|
||||
} else {
|
||||
return "OWMULTI: Verification not yet implemented for interface $interface";
|
||||
}
|
||||
}
|
||||
|
||||
#-- get interval
|
||||
if($reading eq "interval") {
|
||||
$value = $hash->{INTERVAL};
|
||||
return "$name.interval => $value";
|
||||
}
|
||||
|
||||
#-- reset presence
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
#-- not different from getting all values ..
|
||||
$ret = OWXMULTI_GetValues($hash);
|
||||
#-- OWFS interface not yet implemented
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSMULTI_GetValues($hash);
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWMULTI: Get with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- process results
|
||||
if( defined($ret) ){
|
||||
return "OWMULTI: Could not get values from device $name, return was $ret";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
OWMULTI_FormatValues($hash);
|
||||
|
||||
#-- return the special reading
|
||||
if ($reading eq "reading") {
|
||||
return "OWMULTI: $name.reading => ".
|
||||
$hash->{READINGS}{"$owg_channel"}{VAL};
|
||||
}
|
||||
if ($reading eq "temperature") {
|
||||
return "OWMULTI: $name.temperature => ".
|
||||
$hash->{READINGS}{"temperature"}{VAL};
|
||||
}
|
||||
if ($reading eq "VDD") {
|
||||
return "OWMULTI: $name.VDD => ".
|
||||
$hash->{READINGS}{"VDD"}{VAL};
|
||||
}
|
||||
if ( ($reading eq "V")|($reading eq "raw")) {
|
||||
return "OWMULTI: $name.V => ".
|
||||
$owg_volt;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWMULTI_GetValues - Updates the readings from device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_GetValues($@) {
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $value = "";
|
||||
my $ret = "";
|
||||
|
||||
#-- restart timer for updates
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWMULTI_GetValues", $hash, 1);
|
||||
|
||||
#-- reset presence
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
#-- Get values according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
if( $interface eq "OWX" ){
|
||||
#-- max 3 tries
|
||||
for(my $try=0; $try<3; $try++){
|
||||
$ret = OWXMULTI_GetValues($hash);
|
||||
last
|
||||
if( !defined($ret) );
|
||||
}
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSTHERM_GetValues($hash);
|
||||
}else{
|
||||
Log 3, "OWMULTI: GetValues with wrong IODev type $interface";
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-- process results
|
||||
if( defined($ret) ){
|
||||
Log 3, "OWMULTI: Could not get values from device $name, reason $ret";
|
||||
return 1;
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
|
||||
#-- old state, new state
|
||||
my $oldval = $hash->{STATE};
|
||||
$value=OWMULTI_FormatValues($hash);
|
||||
my $newval = $hash->{STATE};
|
||||
#--logging depends on setting of the event-attribute
|
||||
Log 5, $value;
|
||||
my $ev = defined($attr{$name}{"event"}) ? $attr{$name}{"event"} : "on-update";
|
||||
if( ($ev eq "on-update") || (($ev eq "on-change") && ($newval ne $oldval)) ){
|
||||
$hash->{CHANGED}[0] = $value;
|
||||
DoTrigger($name, undef);
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWMULTI_Set - Set one value for device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# a = argument string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_Set($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
#-- for the selector: which values are possible
|
||||
return join(" ", sort keys %sets) if(@a == 2);
|
||||
#-- check syntax
|
||||
return "OWMULTI: Set needs one parameter"
|
||||
if(int(@a) != 3);
|
||||
#-- check argument
|
||||
return "OWMULTI: Set with unknown argument $a[1], choose one of ".join(",", sort keys %sets)
|
||||
if(!defined($sets{$a[1]}));
|
||||
|
||||
#-- define vars
|
||||
my $key = $a[1];
|
||||
my $value = $a[2];
|
||||
my $ret = undef;
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
|
||||
#-- set new timer interval
|
||||
if($key eq "interval") {
|
||||
# check value
|
||||
return "OWMULTI: Set with short interval, must be > 1"
|
||||
if(int($value) < 1);
|
||||
# update timer
|
||||
$hash->{INTERVAL} = $value;
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWMULTI_GetValues", $hash, 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-- set other values depending on interface type
|
||||
my $interface = $hash->{IODev}->{TYPE};
|
||||
my $offset = $hash->{tempf}{offset};
|
||||
my $factor = $hash->{tempf}{factor};
|
||||
|
||||
#-- find upper and lower boundaries for given offset/factor
|
||||
my $mmin = (-55+$offset)*$factor;
|
||||
my $mmax = (125+$offset)*$factor;
|
||||
return sprintf("OWMULTI: Set with wrong value $value for $key, range is [%3.1f,%3.1f]",$mmin,$mmax)
|
||||
if($value < $mmin || $value > $mmax);
|
||||
|
||||
#-- seems to be ok, put into the device
|
||||
$a[2] = int($value/$factor-$offset);
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXMULTI_SetValues($hash,@a);
|
||||
#-- OWFS interface not yet implemented
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSTHERM_SetValues($hash,@a);
|
||||
# return $ret
|
||||
# if(defined($ret));
|
||||
} else {
|
||||
return "OWMULTI: Set with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- process results - we have to reread the device
|
||||
$hash->{PRESENT} = 1;
|
||||
OWMULTI_GetValues($hash);
|
||||
OWMULTI_FormatValues($hash);
|
||||
Log 4, "OWMULTI: Set $hash->{NAME} $key $value";
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWMULTI_Undef - Implements UndefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWMULTI_Undef ($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
delete($modules{OWMULTI}{defptr}{$hash->{OW_ID}});
|
||||
RemoveInternalTimer($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines in alphabetical order are only for a 1-Wire bus connected
|
||||
# directly to the FHEM server
|
||||
#
|
||||
# Prefix = OWXMULTI
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWXMULTI_GetValues - Get reading from one device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXMULTI_GetValues($) {
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
my ($i,$j,$k,$res,$res2);
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
#-- switch the device to current measurement off, VDD only
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command
|
||||
if( OWX_Complex($master,$owx_dev,"\x4E\x00\x08",0) eq 0 ){
|
||||
return "$owx_dev write status failed";
|
||||
}
|
||||
|
||||
#-- copy scratchpad to register
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the copy scratchpad command
|
||||
if( OWX_Complex($master,$owx_dev,"\x48\x00",0) eq 0){
|
||||
return "$owx_dev copy scratchpad failed";
|
||||
}
|
||||
|
||||
#-- initiate temperature conversion
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the start conversion command
|
||||
if( OWX_Complex($master,$owx_dev,"\x44",0) eq 0 ){
|
||||
return "$owx_dev temperature conversion failed";
|
||||
}
|
||||
#-- conversion needs some 10 ms !
|
||||
select(undef,undef,undef,0.012);
|
||||
|
||||
#-- initiate voltage conversion
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the start conversion command
|
||||
if( OWX_Complex($master,$owx_dev,"\xB4",0) eq 0 ){
|
||||
return "$owx_dev voltage conversion failed";
|
||||
}
|
||||
#-- conversion needs some 4 ms !
|
||||
select(undef,undef,undef,0.006);
|
||||
|
||||
#-- from memory to scratchpad
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the recall memory command
|
||||
if( OWX_Complex($master,$owx_dev,"\xB8\x00",0) eq 0 ){
|
||||
return "$owx_dev recall memory failed";
|
||||
}
|
||||
#-- copy needs some 10 ms !
|
||||
select(undef,undef,undef,0.012);
|
||||
|
||||
#-- NOW ask the specific device
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the read scratchpad command \xBE
|
||||
#-- reading 9 + 2 + 9 data bytes = 20 bytes
|
||||
$res=OWX_Complex($master,$owx_dev,"\xBE\x00",9);
|
||||
#Log 1,"OWXMULTI: data length from reading device is ".length($res)." bytes";
|
||||
#-- process results
|
||||
if( $res eq 0 ){
|
||||
return "$owx_dev not accessible in 2nd step";
|
||||
}
|
||||
|
||||
# $res2 = "====> OWXMULTI Received ";
|
||||
# for(my $i=0;$i<length($res);$i++){
|
||||
# my $j=int(ord(substr($res,$i,1))/16);
|
||||
# my $k=ord(substr($res,$i,1))%16;
|
||||
# $res2.=sprintf "0x%1x%1x ",$j,$k;
|
||||
# }
|
||||
# Log 1, $res2;
|
||||
|
||||
#-- process results
|
||||
my @data=split(//,$res);
|
||||
return "invalid data length, ".int(@data)." bytes"
|
||||
if (@data != 20);
|
||||
return "conversion not complete or data invalid"
|
||||
if ((ord($data[11]) & 112)!=0);
|
||||
#return "invalid CRC"
|
||||
# if (OWX_CRC8(substr($res,10,8),$data[18])==0);
|
||||
|
||||
#-- this must be different for the different device types
|
||||
# family = 26 => DS2438
|
||||
|
||||
#-- temperature
|
||||
my $lsb = ord($data[12]);
|
||||
my $msb = ord($data[13]) & 127;
|
||||
my $sign = ord($data[13]) & 128;
|
||||
|
||||
#-- test with -55 degrees
|
||||
#$lsb = 0;
|
||||
#$sign = 1;
|
||||
#$msb = 73;
|
||||
|
||||
#-- 2's complement form = signed bytes
|
||||
$owg_temp = $msb+ $lsb/256;
|
||||
if( $sign !=0 ){
|
||||
$owg_temp = -128+$owg_temp;
|
||||
}
|
||||
|
||||
#-- voltage
|
||||
$lsb = ord($data[14]);
|
||||
$msb = ord($data[15]) & 3;
|
||||
|
||||
#-- test with 5V
|
||||
#$lsb = 244;
|
||||
#$msb = 1;
|
||||
|
||||
#-- supply voltage
|
||||
$owg_vdd = ($msb*256+ $lsb)/100;
|
||||
|
||||
#-- switch the device to current measurement off, V external only
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command
|
||||
if( OWX_Complex($master,$owx_dev,"\x4E\x00\x00",0) eq 0 ){
|
||||
return "$owx_dev write status failed";
|
||||
}
|
||||
|
||||
#-- copy scratchpad to register
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the copy scratchpad command
|
||||
if( OWX_Complex($master,$owx_dev,"\x48\x00",0) eq 0){
|
||||
return "$owx_dev copy scratchpad failed";
|
||||
}
|
||||
|
||||
#-- initiate voltage conversion
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the start conversion command
|
||||
if( OWX_Complex($master,$owx_dev,"\xB4",0) eq 0 ){
|
||||
return "$owx_dev voltage conversion failed";
|
||||
}
|
||||
#-- conversion needs some 4 ms !
|
||||
select(undef,undef,undef,0.006);
|
||||
|
||||
#-- from memory to scratchpad
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the recall memory command
|
||||
if( OWX_Complex($master,$owx_dev,"\xB8\x00",0) eq 0 ){
|
||||
return "$owx_dev recall memory failed";
|
||||
}
|
||||
#-- copy needs some 10 ms !
|
||||
select(undef,undef,undef,0.012);
|
||||
|
||||
#-- NOW ask the specific device
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the read scratchpad command \xBE
|
||||
#-- reading 9 + 2 + 9 data bytes = 20 bytes
|
||||
$res=OWX_Complex($master,$owx_dev,"\xBE\x00",9);
|
||||
#Log 1,"OWXMULTI: data length from reading device is ".length($res)." bytes";
|
||||
#-- process results
|
||||
if( $res eq 0 ){
|
||||
return "$owx_dev not accessible in 2nd step";
|
||||
}
|
||||
|
||||
# $res2 = "====> OWXMULTI Received ";
|
||||
# for(my $i=0;$i<length($res);$i++){
|
||||
# my $j=int(ord(substr($res,$i,1))/16);
|
||||
# my $k=ord(substr($res,$i,1))%16;
|
||||
# $res2.=sprintf "0x%1x%1x ",$j,$k;
|
||||
# }
|
||||
# Log 1, $res2;
|
||||
|
||||
#-- process results
|
||||
@data=split(//,$res);
|
||||
return "invalid data length, ".int(@data)." bytes"
|
||||
if (@data != 20);
|
||||
return "conversion not complete or data invalid"
|
||||
if ((ord($data[11]) & 112)!=0);
|
||||
#return "invalid CRC"
|
||||
# if (OWX_CRC8(substr($res,10,8),$data[18])==0);
|
||||
|
||||
#-- this must be different for the different device types
|
||||
# family = 26 => DS2438
|
||||
|
||||
#-- voltage
|
||||
$lsb = ord($data[14]);
|
||||
$msb = ord($data[15]) & 3;
|
||||
|
||||
#-- test with 7.2 V
|
||||
#$lsb = 208;
|
||||
#$msb = 2;
|
||||
|
||||
#-- external voltage
|
||||
$owg_volt = ($msb*256+ $lsb)/100;
|
||||
|
||||
return undef;
|
||||
|
||||
#} else {
|
||||
# return "OWXMULTI: Unknown device family $hash->{OW_FAMILY}\n";
|
||||
#}
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWXMULTI_SetValues - Implements SetFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXMULTI_SetValues($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
#-- define vars
|
||||
my $key = $a[1];
|
||||
my $value = $a[2];
|
||||
|
||||
OWX_Reset($master);
|
||||
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E,
|
||||
# followed by the write EEPROM command \x48
|
||||
#
|
||||
# so far writing the EEPROM does not work properly.
|
||||
# 1. \x48 directly appended to the write scratchpad command => command ok, no effect on EEPROM
|
||||
# 2. \x48 appended to match ROM => command not ok.
|
||||
# 3. \x48 sent by WriteBytePower after match ROM => command ok, no effect on EEPROM
|
||||
|
||||
my $select=sprintf("\x4E%c%c\x48",0,0);
|
||||
my $res=OWX_Complex($master,$owx_dev,$select,0);
|
||||
|
||||
if( $res eq 0 ){
|
||||
return "OWXMULTI: Device $owx_dev not accessible";
|
||||
}
|
||||
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
@ -1,894 +0,0 @@
|
||||
########################################################################################
|
||||
#
|
||||
# OWSWITCH.pm
|
||||
#
|
||||
# FHEM module to commmunicate with 1-Wire adressable switches DS2413, DS206, DS2408
|
||||
#
|
||||
# Attention: This module may communicate with the OWX module,
|
||||
# but currently not with the 1-Wire File System OWFS
|
||||
#
|
||||
# TODO: Kanalattribute ändern zur Laufzeit.
|
||||
#
|
||||
#
|
||||
# Prefixes for subroutines of this module:
|
||||
# OW = General 1-Wire routines Peter Henning)
|
||||
# OWX = 1-Wire bus master interface (Peter Henning)
|
||||
# OWFS = 1-Wire file system (??)
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
#
|
||||
# Version 2.24 - October, 2012
|
||||
#
|
||||
# Setup bus device in fhem.cfg as
|
||||
#
|
||||
# define <name> OWSWITCH [<model>] <ROM_ID> [interval]
|
||||
#
|
||||
# where <name> may be replaced by any name string
|
||||
#
|
||||
# <model> is a 1-Wire device type. If omitted, we assume this to be an
|
||||
# DS2413. Allowed values are DS2413, DS2406
|
||||
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
||||
# without Family ID, e.g. A2D90D000800
|
||||
# [interval] is an optional query interval in seconds
|
||||
#
|
||||
# get <name> id => FAM_ID.ROM_ID.CRC
|
||||
# get <name> present => 1 if device present, 0 if not
|
||||
# get <name> interval => query interval
|
||||
# get <name> input <channel-name> => state for channel (name A, B or defined channel name)
|
||||
# note: this value reflects the measured value, not necessarily the one set as
|
||||
# output state, because the output transistors are open collector switches. A measured
|
||||
# state of 1 = OFF therefore corresponds to an output state of 1 = OFF, but a measured
|
||||
# state of 0 = ON can also be due to an external shortening of the output.
|
||||
# get <name> gpio => values for channels
|
||||
#
|
||||
# set <name> interval => set period for measurement
|
||||
# set <name> output <channel-name> ON|OFF => set value for channel (name A, B or defined channel name)
|
||||
# note: 1 = OFF, 0 = ON in normal usage. See also the note above
|
||||
# set <name> gpio value => set values for channels (3 = both OFF, 1 = B ON 2 = A ON 0 = both ON)
|
||||
# set <name> init yes => re-initialize device
|
||||
#
|
||||
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
|
||||
# Note: attributes are read only during initialization procedure - later changes are not used.
|
||||
#
|
||||
# attr <name> event on-change/on-update = when to write an event (default= on-update)
|
||||
#
|
||||
# attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value
|
||||
# attr <name> <channel>Unit <string>|<string> = values to display in state variable for on|off condition
|
||||
# attr <name> <channel>stateS <string> = character string denoting external shortening condition
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# This programm is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
########################################################################################
|
||||
package main;
|
||||
|
||||
#-- Prototypes to make komodo happy
|
||||
use vars qw{%attr %defs};
|
||||
use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
#-- channel name - fixed is the first array, variable the second
|
||||
my @owg_fixed = ("A","B","C","D","E","F","G","H");
|
||||
my @owg_channel;
|
||||
#-- channel values - always the raw input resp. output values from the device
|
||||
my @owg_val;
|
||||
my @owg_vax;
|
||||
|
||||
my %gets = (
|
||||
"id" => "",
|
||||
"present" => "",
|
||||
"interval" => "",
|
||||
"input" => "",
|
||||
"gpio" => ""
|
||||
);
|
||||
|
||||
my %sets = (
|
||||
"interval" => "",
|
||||
"output" => "",
|
||||
"gpio" => "",
|
||||
"init" => ""
|
||||
);
|
||||
|
||||
my %updates = (
|
||||
"present" => "",
|
||||
"gpio" => ""
|
||||
);
|
||||
|
||||
my %cnumber = (
|
||||
"DS2413" => 2,
|
||||
"DS2406" => 2,
|
||||
"DS2408" => 8
|
||||
);
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines are independent of the bus interface
|
||||
#
|
||||
# Prefix = OWSWITCH
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWSWITCH_Initialize
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWSWITCH_Initialize ($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "OWSWITCH_Define";
|
||||
$hash->{UndefFn} = "OWSWITCH_Undef";
|
||||
$hash->{GetFn} = "OWSWITCH_Get";
|
||||
$hash->{SetFn} = "OWSWITCH_Set";
|
||||
|
||||
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2413,DS2406,DS2408 loglevel:0,1,2,3,4,5 ".
|
||||
"event:on-update,on-change";
|
||||
|
||||
#TODO: correct number of channels
|
||||
|
||||
for( my $i=0;$i<8;$i++ ){
|
||||
$attlist .= " ".$owg_fixed[$i]."Name";
|
||||
$attlist .= " ".$owg_fixed[$i]."Unit";
|
||||
$attlist .= " ".$owg_fixed[$i]."stateS";
|
||||
}
|
||||
$hash->{AttrList} = $attlist;
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
#
|
||||
# OWSWITCH_Define - Implements DefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, def = definition string
|
||||
#
|
||||
#########################################################################################
|
||||
|
||||
sub OWSWITCH_Define ($$) {
|
||||
my ($hash, $def) = @_;
|
||||
|
||||
# define <name> OWSWITCH [<model>] <id> [interval]
|
||||
# e.g.: define flow OWSWITCH 525715020000 300
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
my ($name,$model,$fam,$id,$crc,$interval,$scale,$ret);
|
||||
|
||||
#-- default
|
||||
$name = $a[0];
|
||||
$interval = 300;
|
||||
$scale = "";
|
||||
$ret = "";
|
||||
|
||||
#-- check syntax
|
||||
return "OWSWITCH: Wrong syntax, must be define <name> OWSWITCH [<model>] <id> [interval]"
|
||||
if(int(@a) < 2 || int(@a) > 5);
|
||||
|
||||
#-- check if this is an old style definition, e.g. <model> is missing
|
||||
my $a2 = $a[2];
|
||||
my $a3 = defined($a[3]) ? $a[3] : "";
|
||||
if( $a2 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||
$model = "DS2413";
|
||||
$id = $a[2];
|
||||
if(int(@a)>=4) { $interval = $a[3]; }
|
||||
} elsif( $a3 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||
$model = $a[2];
|
||||
$id = $a[3];
|
||||
if(int(@a)>=5) { $interval = $a[4]; }
|
||||
} else {
|
||||
return "OWSWITCH: $a[0] ID $a[2] invalid, specify a 12 digit value";
|
||||
}
|
||||
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
||||
# FF = family id follows from the model
|
||||
# YY must be determined from id
|
||||
if( $model eq "DS2413" ){
|
||||
$fam = "3A";
|
||||
CommandAttr (undef,"$name model DS2413");
|
||||
}elsif( $model eq "DS2406" ){
|
||||
$fam = "12";
|
||||
CommandAttr (undef,"$name model DS2406");
|
||||
}elsif( $model eq "DS2408" ){
|
||||
$fam = "29";
|
||||
CommandAttr (undef,"$name model DS2408");
|
||||
}else{
|
||||
return "OWSWITCH: Wrong 1-Wire device model $model";
|
||||
}
|
||||
|
||||
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
||||
# determine CRC Code - only if this is a direct interface
|
||||
$crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC($fam.".".$id."00")) : "00";
|
||||
|
||||
#-- Define device internals
|
||||
$hash->{ROM_ID} = $fam.".".$id.$crc;
|
||||
$hash->{OW_ID} = $id;
|
||||
$hash->{OW_FAMILY} = $fam;
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
Log 3, "OWSWITCH: Warning, no 1-Wire I/O device found for $name."
|
||||
if(!defined($hash->{IODev}->{NAME}));
|
||||
$modules{OWSWITCH}{defptr}{$id} = $hash;
|
||||
$hash->{STATE} = "Defined";
|
||||
Log 3, "OWSWITCH: Device $name defined.";
|
||||
|
||||
#-- Initialization reading according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- Start timer for initialization in a few seconds
|
||||
InternalTimer(time()+1, "OWSWITCH_InitializeDevice", $hash, 0);
|
||||
|
||||
#-- Start timer for updates
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWSWITCH_GetValues", $hash, 0);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWSWITCH_InitializeDevice - delayed setting of initial readings and channel names
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWSWITCH_InitializeDevice($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
#-- Set channel names, channel units
|
||||
for( my $i=0;$i<$cnumber{$attr{$name}{"model"}} ;$i++) {
|
||||
#-- Initial readings OFF
|
||||
$owg_val[$i] = 1;
|
||||
$owg_vax[$i] = 1;
|
||||
#-- name
|
||||
my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i]."|onoff";
|
||||
my @cnama = split(/\|/,$cname);
|
||||
if( int(@cnama)!=2){
|
||||
Log 1, "OWSWITCH: Incomplete channel name specification $cname. Better use $cname|<type of data>";
|
||||
push(@cnama,"unknown");
|
||||
}
|
||||
|
||||
#-- unit
|
||||
my $unit = defined($attr{$name}{$owg_fixed[$i]."Unit"}) ? $attr{$name}{$owg_fixed[$i]."Unit"} : "ON|OFF";
|
||||
my @unarr= split(/\|/,$unit);
|
||||
if( int(@unarr)!=2 ){
|
||||
Log 1, "OWSWITCH: Wrong channel unit specification $unit, replaced by ON|OFF";
|
||||
$unit="ON|OFF";
|
||||
}
|
||||
|
||||
#-- put into readings
|
||||
$owg_channel[$i] = $cnama[0];
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{TYPE} = $cnama[1];
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{UNIT} = $unit;
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR} = $unit;
|
||||
}
|
||||
|
||||
#-- set status according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- OWX interface
|
||||
if( !defined($interface) ){
|
||||
return "OWSWITCH: Interface missing";
|
||||
} elsif( $interface eq "OWX" ){
|
||||
#-- OWFS interface
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSAD_GetPage($hash,"reading");
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWSWITCH: InitializeDevice with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- Initialize all the display stuff
|
||||
OWSWITCH_FormatValues($hash);
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWSWITCH_FormatValues - put together various format strings
|
||||
#
|
||||
# Parameter hash = hash of device addressed, fs = format string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWSWITCH_FormatValues($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my ($offset,$factor,$vval,$vvax,$vstr,$cname,@cnama,@unarr);
|
||||
my ($value1,$value2,$value3) = ("","","");
|
||||
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- formats for output
|
||||
for (my $i=0;$i<$cnumber{$attr{$name}{"model"}};$i++){
|
||||
$cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i];
|
||||
@cnama = split(/\|/,$cname);
|
||||
$owg_channel[$i]=$cnama[0];
|
||||
|
||||
#-- input state is 0 = ON or 1 = OFF
|
||||
$vval = $owg_val[$i];
|
||||
#-- output state is 0 = ON or 1 = OFF
|
||||
$vvax = $owg_vax[$i];
|
||||
|
||||
#-- string buildup for return value and STATE
|
||||
@unarr= split(/\|/,$hash->{READINGS}{"$owg_channel[$i]"}{UNIT});
|
||||
$cname = defined($attr{$name}{$owg_fixed[$i]."stateS"}) ? $attr{$name}{$owg_fixed[$i]."stateS"} : "<span style=\"color:red\">☇</span>";
|
||||
$vstr = $unarr[$vval];
|
||||
$vstr .= $cname if( ($vval == 0) && ($vvax == 1) );
|
||||
$vstr = "ERR" if( ($vval == 1) && ($vvax == 0) );
|
||||
|
||||
$value1 .= sprintf( "%s: %s", $owg_channel[$i], $vstr);
|
||||
$value2 .= sprintf( "%s: %s ", $owg_channel[$i], $vstr);
|
||||
$value3 .= sprintf( "%s: " , $owg_channel[$i]);
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vstr;
|
||||
$hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn;
|
||||
|
||||
#-- insert comma
|
||||
if( $i<$cnumber{$attr{$name}{"model"}}-1 ){
|
||||
$value1 .= " ";
|
||||
$value2 .= ", ";
|
||||
$value3 .= ", ";
|
||||
}
|
||||
}
|
||||
#-- STATE
|
||||
$hash->{STATE} = $value2;
|
||||
|
||||
return $value1;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWSWITCH_Get - Implements GetFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWSWITCH_Get($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
my $reading = $a[1];
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
my ($value,$value2,$value3) = (undef,undef,undef);
|
||||
my $ret = "";
|
||||
my $offset;
|
||||
my $factor;
|
||||
my $page;
|
||||
|
||||
#-- check syntax
|
||||
return "OWSWITCH: Get argument is missing @a"
|
||||
if(int(@a) < 2);
|
||||
|
||||
#-- check argument
|
||||
return "OWSWITCH: Get with unknown argument $a[1], choose one of ".join(",", sort keys %gets)
|
||||
if(!defined($gets{$a[1]}));
|
||||
|
||||
#-- get id
|
||||
if($a[1] eq "id") {
|
||||
$value = $hash->{ROM_ID};
|
||||
return "$name.id => $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;
|
||||
return "$name.present => $value";
|
||||
}
|
||||
|
||||
#-- get interval
|
||||
if($a[1] eq "interval") {
|
||||
$value = $hash->{INTERVAL};
|
||||
return "$name.interval => $value";
|
||||
}
|
||||
|
||||
#-- reset presence
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
#-- get values according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- get single state
|
||||
# TODO: WAS passiert, wenn channel name noch falsch ist ?
|
||||
if( $reading eq "input" ){
|
||||
return "OWSWITCH: get needs parameter when reading input: <channel>"
|
||||
if( int(@a)<2 );
|
||||
my $fnd=undef;
|
||||
for (my $i=0;$i<$cnumber{$attr{$name}{"model"}};$i++){
|
||||
if( ($a[2] eq $owg_channel[$i]) || ($a[2] eq $owg_fixed[$i]) ){
|
||||
$fnd=$i;
|
||||
last;
|
||||
}
|
||||
}
|
||||
return "OWSWITCH: invalid output address, must be A,B,... or defined channel name"
|
||||
if( !defined($fnd) );
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_GetState($hash);
|
||||
#-- OWFS interface
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSSWITCH_GetPage($hash,"reading");
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWSWITCH: Get with wrong IODev type $interface";
|
||||
}
|
||||
#-- process results
|
||||
OWSWITCH_FormatValues($hash);
|
||||
my @states = split(/,/,$hash->{STATE});
|
||||
|
||||
return $a[2]." = ".$states[$fnd];
|
||||
|
||||
#-- get all states
|
||||
}elsif( $reading eq "gpio" ){
|
||||
return "OWSWITCH: get needs no parameter when reading gpio"
|
||||
if( int(@a)==1 );
|
||||
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_GetState($hash);
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSAD_GetValues($hash);
|
||||
}else{
|
||||
return "OWSWITCH: GetValues with wrong IODev type $interface";
|
||||
}
|
||||
}
|
||||
#-- process results
|
||||
if( defined($ret) ){
|
||||
return "OWSWITCH: Could not get values from device $name";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
return "OWSWITCH: $name.$reading => ".OWSWITCH_FormatValues($hash);
|
||||
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWSWITCH_GetValues - Updates the reading from one device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWSWITCH_GetValues($) {
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
my $value = "";
|
||||
my $ret = "";
|
||||
my $offset;
|
||||
my $factor;
|
||||
|
||||
#-- restart timer for updates
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWSWITCH_GetValues", $hash, 1);
|
||||
|
||||
#-- reset presence
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
#-- Get readings according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_GetState($hash);
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSSWITCH_GetValues($hash);
|
||||
}else{
|
||||
return "OWSWITCH: GetValues with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- process results
|
||||
if( defined($ret) ){
|
||||
return "OWSWITCH: Could not get values from device $name";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
#-- old state, new state
|
||||
my $oldval = $hash->{STATE};
|
||||
$value=OWSWITCH_FormatValues($hash);
|
||||
my $newval = $hash->{STATE};
|
||||
#--logging depends on setting of the event-attribute
|
||||
Log 5, $value;
|
||||
my $ev = defined($attr{$name}{"event"}) ? $attr{$name}{"event"} : "on-update";
|
||||
if( ($ev eq "on-update") || (($ev eq "on-change") && ($newval ne $oldval)) ){
|
||||
$hash->{CHANGED}[0] = $value;
|
||||
DoTrigger($name, undef);
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWSWITCH_Set - Set one value for device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWSWITCH_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(" ", sort keys %sets);
|
||||
return $newkeys ;
|
||||
}
|
||||
|
||||
#-- check argument
|
||||
if( !defined($sets{$a[1]}) ){
|
||||
return "OWSWITCH: Set with unknown argument $a[1]";
|
||||
}
|
||||
|
||||
#-- define vars
|
||||
my $ret = undef;
|
||||
my $channel = undef;
|
||||
my $channo = undef;
|
||||
my $condx;
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
|
||||
#-- reset the device
|
||||
if($key eq "init") {
|
||||
return "OWCOUNT: init needs parameter 'yes'"
|
||||
if($value ne "yes");
|
||||
OWSWITCH_InitializeDevice($hash);
|
||||
return "OWCOUNT: Re-initialized device";
|
||||
}
|
||||
|
||||
#-- set new timer interval
|
||||
if($key eq "interval") {
|
||||
# check value
|
||||
return "OWSWITCH: Set with short interval, must be > 1"
|
||||
if(int($value) < 1);
|
||||
# update timer
|
||||
$hash->{INTERVAL} = $value;
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWSWITCH_GetValues", $hash, 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#-- Set readings according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- set single state
|
||||
# TODO: WAS passiert, wenn channel name noch falsch ist ?
|
||||
if( $key eq "output" ){
|
||||
return "OWSWITCH: get needs parameter when writing output: <channel>"
|
||||
if( int(@a)<2 );
|
||||
#-- find out which channel we have
|
||||
my $fnd=undef;
|
||||
for (my $i=0;$i<$cnumber{$attr{$name}{"model"}};$i++){
|
||||
if( ($a[2] eq $owg_channel[$i]) || ($a[2] eq $owg_fixed[$i]) ){
|
||||
$fnd=$i;
|
||||
last;
|
||||
}
|
||||
}
|
||||
return "OWSWITCH: invalid output address, must be A,B,... or defined channel name"
|
||||
if( !defined($fnd) );
|
||||
#-- prepare gpio value
|
||||
my $nval;
|
||||
if( lc($a[3]) eq "on" ){
|
||||
$nval = 0;
|
||||
}elsif( lc($a[3]) eq "off" ){
|
||||
$nval = 1;
|
||||
}else{
|
||||
return "OWSWITCH: Wrong data value $a[3], must be ON or OFF";
|
||||
}
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_GetState($hash);
|
||||
$value = 0;
|
||||
#-- vax or val ?
|
||||
for (my $i=0;$i<$cnumber{$attr{$name}{"model"}};$i++){
|
||||
$value += ($owg_vax[$i]<<$i)
|
||||
if( $i != $fnd );
|
||||
$value += ($nval<<$i)
|
||||
if( $i == $fnd );
|
||||
}
|
||||
$ret = OWXSWITCH_SetState($hash,$value);
|
||||
#-- OWFS interface
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSAD_GetPage($hash,"reading");
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWSWITCH: Get with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- set state
|
||||
}elsif( $key eq "gpio" ){
|
||||
#-- check value and write to device
|
||||
return "OWSWITCH: Set with wrong value for gpio port, must be 0 <= gpio <= ".(1 << $cnumber{$attr{$name}{"model"}} - 1)
|
||||
if( ! ((int($value) >= 0) && (int($value) <= (1 << $cnumber{$attr{$name}{"model"}} -1 ))) );
|
||||
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_SetState($hash,int($value));
|
||||
#}elsif( $interface eq "OWFS" ){
|
||||
# $ret = OWFSSWITCH_GetValues($hash);
|
||||
}else{
|
||||
return "OWSWITCH: GetValues with wrong IODev type $interface";
|
||||
}
|
||||
}
|
||||
|
||||
#-- process results - we have to reread the device
|
||||
$hash->{PRESENT} = 1;
|
||||
OWSWITCH_GetValues($hash);
|
||||
#OWSWITCH_FormatValues($hash);
|
||||
Log 4, "OWSWITCH: Set $hash->{NAME} $key $value";
|
||||
#$hash->{CHANGED}[0] = $value;
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWSWITCH_Undef - Implements UndefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWSWITCH_Undef ($) {
|
||||
my ($hash) = @_;
|
||||
delete($modules{OWSWITCH}{defptr}{$hash->{OW_ID}});
|
||||
RemoveInternalTimer($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines in alphabetical order are only for a 1-Wire bus connected
|
||||
# via OWFS
|
||||
#
|
||||
# Prefix = OWFSSWITCH
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines in alphabetical order are only for a 1-Wire bus connected
|
||||
# directly to the FHEM server
|
||||
#
|
||||
# Prefix = OWXSWITCH
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWXAD_GetState - Get gpio ports from device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXSWITCH_GetState($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my ($select, $res, $res2, $res3, @data);
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $owx_rnf = substr($owx_dev,3,12);
|
||||
my $owx_f = substr($owx_dev,0,2);
|
||||
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
#-- family = 3A => DS2413
|
||||
if( $hash->{OW_FAMILY} eq "3A" ) {
|
||||
#=============== get gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the read gpio command
|
||||
# \xF5 plus 2 empty bytes
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- read the data
|
||||
$res=OWX_Complex($master,$owx_dev,"\xF5",2);
|
||||
if( $res eq 0 ){
|
||||
return "OWXSWITCH: Device $owx_dev not accessible in reading";
|
||||
}
|
||||
#-- family = 12 => DS2406
|
||||
}elsif( $hash->{OW_FAMILY} eq "12" ) {
|
||||
#=============== get gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the access channel command
|
||||
# \xF5 plus the two byte channel control and the value
|
||||
$select=sprintf("\xF5\xDC\xFF");
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- read the data
|
||||
$res=OWX_Complex($master,$owx_dev,$select,1);
|
||||
if( $res eq 0 ){
|
||||
return "OWXSWITCH: Device $owx_dev not accessible in writing";
|
||||
}
|
||||
#-- family = 29 => DS2408
|
||||
}elsif( $hash->{OW_FAMILY} eq "29" ) {
|
||||
#=============== get gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the read PIO rtegisters command
|
||||
# \xF5 plus the two byte channel target address
|
||||
#-- reading 9 + 3 + 10 data bytes = 22 bytes
|
||||
$select=sprintf("\xF0\x88\x00");
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- read the data
|
||||
$res=OWX_Complex($master,$owx_dev,$select,10);
|
||||
if( $res eq 0 ){
|
||||
return "OWXSWITCH: Device $owx_dev not accessible in writing";
|
||||
}
|
||||
} else {
|
||||
return "OWXSWITCH: Unknown device family $hash->{OW_FAMILY}\n";
|
||||
}
|
||||
|
||||
#-- process results
|
||||
@data=split(//,substr($res,10));
|
||||
#return "invalid data length"
|
||||
# if (@data != 22);
|
||||
#return "invalid data"
|
||||
# if (ord($data[17])<=0);
|
||||
#return "invalid CRC"
|
||||
# if (OWX_CRC8(substr($res,10,8),$data[18])==0);
|
||||
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
|
||||
# note: value 1 corresponds to OFF, 0 to ON normally
|
||||
# note: val = input value, vax = output value
|
||||
#-- family = 3A => DS2413
|
||||
if( $hash->{OW_FAMILY} eq "3A" ) {
|
||||
$owg_val[0] = ord($data[0]) & 1;
|
||||
$owg_vax[0] = (ord($data[0])>>1) & 1;
|
||||
$owg_val[1] = (ord($data[0])>>2) & 1;
|
||||
$owg_vax[1] = (ord($data[0])>>3) & 1;
|
||||
|
||||
#-- family = 12 => DS2406
|
||||
}elsif( $hash->{OW_FAMILY} eq "12" ) {
|
||||
$owg_val[0] = (ord($data[2])>>2) & 1;
|
||||
$owg_vax[0] = ord($data[2]) & 1;
|
||||
$owg_val[1] = (ord($data[2])>>3) & 1;
|
||||
$owg_vax[1] = (ord($data[2])>>1) & 1;
|
||||
#-- family = 29 => DS2408
|
||||
}elsif( $hash->{OW_FAMILY} eq "29" ) {
|
||||
for(my $i=0;$i<8;$i++){
|
||||
$owg_val[$i] = (ord($data[2])>>$i) & 1;
|
||||
$owg_vax[$i] = (ord($data[3])>>$i) & 1;
|
||||
}
|
||||
}
|
||||
return undef
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXSWITCH_SetPage - Set gpio ports of device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# value = integer value for device outputs
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXSWITCH_SetState($$) {
|
||||
|
||||
my ($hash,$value) = @_;
|
||||
|
||||
|
||||
my ($select, $res, $res2, @data);
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $owx_rnf = substr($owx_dev,3,12);
|
||||
my $owx_f = substr($owx_dev,0,2);
|
||||
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
#-- family = 3A => DS2413
|
||||
if( $hash->{OW_FAMILY} eq "3A" ) {
|
||||
#=============== set gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the write gpio command
|
||||
# \x5A plus the value byte and its complement
|
||||
$select=sprintf("\x5A%c%c",252+$value,3-$value);
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- read the data
|
||||
$res=OWX_Complex($master,$owx_dev,$select,1);
|
||||
if( $res eq 0 ){
|
||||
return "OWXSWITCH: Device $owx_dev not accessible in writing";
|
||||
}
|
||||
#-- family = 12 => DS2406
|
||||
}elsif( $hash->{OW_FAMILY} eq "12" ) {
|
||||
#=============== set gpio values ===============================
|
||||
# Writing the output state via the access channel command does
|
||||
# not work contrary to documentation. Using the write status command
|
||||
#-- issue the match ROM command \x55 and the read status command
|
||||
# \xAA at address TA1 = \x07 TA2 = \x00
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- read the data
|
||||
$res = OWX_Complex($master,$owx_dev,"\xAA\x07\x00",1);
|
||||
my $stat = substr($res,10,1);
|
||||
my $statneu = ( $stat & 159 ) | (($value<<5) & 96) ;
|
||||
#-- issue the match ROM command \x55 and the write status command
|
||||
# \x55 at address TA1 = \x07 TA2 = \x00
|
||||
#
|
||||
$select=sprintf("\x55\x07\x00%c",$statneu);
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- read the data
|
||||
$res=OWX_Complex($master,$owx_dev,$select,2);
|
||||
if( $res eq 0 ){
|
||||
return "OWXSWITCH: Device $owx_dev not accessible in writing";
|
||||
}
|
||||
$owg_val[0] = $value % 2;
|
||||
$owg_vax[0] = $owg_val[0];
|
||||
$owg_val[1] = int($value / 2);
|
||||
$owg_vax[1] = $owg_val[1];
|
||||
#-- family = 29 => DS2408
|
||||
}elsif( $hash->{OW_FAMILY} eq "29" ) {
|
||||
#=============== set gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the write gpio command
|
||||
# \x5A plus the value byte and its complement
|
||||
$select=sprintf("\x5A%c%c",$value,255-$value);
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
#-- read the data
|
||||
$res=OWX_Complex($master,$owx_dev,$select,1);
|
||||
if( $res eq 0 ){
|
||||
return "OWXSWITCH: Device $owx_dev not accessible in writing";
|
||||
}
|
||||
|
||||
} else {
|
||||
return "OWXSWITCH: Unknown device family $hash->{OW_FAMILY}\n";
|
||||
}
|
||||
#-- reset the bus
|
||||
OWX_Reset($master);
|
||||
|
||||
#-- process results
|
||||
@data=split(//,substr($res,10));
|
||||
|
||||
#-- family = 3A => DS2413
|
||||
if( $hash->{OW_FAMILY} eq "3A" ) {
|
||||
if( $data[2] ne "\xAA"){
|
||||
return "OWXSWITCH: State could not be set for device $owx_dev";
|
||||
}
|
||||
#-- family = 12 => DS2406
|
||||
}elsif( $hash->{OW_FAMILY} eq "12" ) {
|
||||
#-- very crude check - should be CRC
|
||||
if( int(@data) != 5){
|
||||
return "OWXSWITCH: State could not be set for device $owx_dev";
|
||||
}
|
||||
#-- family = 29 => DS2408
|
||||
}elsif( $hash->{OW_FAMILY} eq "29" ) {
|
||||
if( $data[2] ne "\xAA"){
|
||||
return "OWXSWITCH: State could not be set for device $owx_dev";
|
||||
}
|
||||
}
|
||||
return undef
|
||||
|
||||
}
|
||||
|
||||
1;
|
@ -1,815 +0,0 @@
|
||||
########################################################################################
|
||||
#
|
||||
# OWTHERM.pm
|
||||
#
|
||||
# FHEM module to commmunicate with 1-Wire temperature sensors DS1820, DS18S20, DS18B20, DS1822
|
||||
#
|
||||
# Attention: This module may communicate with the OWX module,
|
||||
# and also with the 1-Wire File System OWFS
|
||||
#
|
||||
# Prefixes for subroutines of this module:
|
||||
# OW = General 1-Wire routines (Martin Fischer, Peter Henning)
|
||||
# OWFS = 1-Wire file system (Martin Fischer)
|
||||
# OWX = 1-Wire bus master interface (Peter Henning)
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning, 2012
|
||||
# Martin Fischer, 2011
|
||||
#
|
||||
# Version 2.24 - October, 2012
|
||||
#
|
||||
# Setup bus device in fhem.cfg as
|
||||
#
|
||||
# define <name> OWTHERM [<model>] <ROM_ID> [interval]
|
||||
#
|
||||
# where <name> may be replaced by any name string
|
||||
#
|
||||
# <model> is a 1-Wire device type. If omitted, we assume this to be an
|
||||
# DS1820 temperature sensor
|
||||
# Currently allowed values are DS1820, DS18B20, DS1822
|
||||
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
||||
# without Family ID, e.g. A2D90D000800
|
||||
# [interval] is an optional query interval in seconds
|
||||
#
|
||||
# get <name> id => OW_FAMILY.ROM_ID.CRC
|
||||
# get <name> present => 1 if device present, 0 if not
|
||||
# get <name> interval => query interval
|
||||
# get <name> temperature => temperature measurement
|
||||
# get <name> alarm => alarm temperature settings
|
||||
#
|
||||
# set <name> interval => set period for measurement
|
||||
# set <name> tempLow => lower alarm temperature setting
|
||||
# set <name> tempHigh => higher alarm temperature setting
|
||||
#
|
||||
# Additional attributes are defined in fhem.cfg
|
||||
# Note: attributes "tempXXXX" are read during every update operation.
|
||||
#
|
||||
# attr <name> event on-change/on-update = when to write an event (default= on-update)
|
||||
#
|
||||
# attr <name> stateAL "<string>" = character string for denoting low alarm condition, default is red down triangle
|
||||
# attr <name> stateAH "<string>" = character string for denoting high alarm condition, default is red up triangle
|
||||
# attr <name> tempOffset <float> = temperature offset in degree Celsius added to the raw temperature reading
|
||||
# attr <name> tempUnit <string> = unit of measurement, e.g. Celsius/Kelvin/Fahrenheit or C/K/F, default is Celsius
|
||||
# attr <name> tempLow <float> = value for low alarm
|
||||
# attr <name> tempHigh <float> = value for high alarm
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# This programm is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
########################################################################################
|
||||
package main;
|
||||
|
||||
#-- Prototypes to make komodo happy
|
||||
use vars qw{%attr %defs};
|
||||
use strict;
|
||||
use warnings;
|
||||
sub Log($$);
|
||||
|
||||
#-- temperature globals - always the raw values from the device
|
||||
my $owg_temp = 0;
|
||||
my $owg_th = 0;
|
||||
my $owg_tl = 0;
|
||||
|
||||
#-- variables for display strings
|
||||
my $stateal;
|
||||
my $stateah;
|
||||
|
||||
my %gets = (
|
||||
"id" => "",
|
||||
"present" => "",
|
||||
"interval" => "",
|
||||
"temperature" => "",
|
||||
"alarm" => ""
|
||||
);
|
||||
|
||||
my %sets = (
|
||||
"interval" => "",
|
||||
"tempHigh" => "",
|
||||
"tempLow" => ""
|
||||
);
|
||||
|
||||
my %updates = (
|
||||
"present" => "",
|
||||
"temperature" => "",
|
||||
"alarm" => ""
|
||||
);
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines are independent of the bus interface
|
||||
#
|
||||
# Prefix = OWTHERM
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWTHERM_Initialize
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_Initialize ($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "OWTHERM_Define";
|
||||
$hash->{UndefFn} = "OWTHERM_Undef";
|
||||
$hash->{GetFn} = "OWTHERM_Get";
|
||||
$hash->{SetFn} = "OWTHERM_Set";
|
||||
#tempOffset = a temperature offset added to the temperature reading for correction
|
||||
#tempUnit = a unit of measure: C/F/K
|
||||
$hash->{AttrList}= "IODev do_not_notify:0,1 showtime:0,1 loglevel:0,1,2,3,4,5 ".
|
||||
"event:on-update,on-change ".
|
||||
"stateAL stateAH ".
|
||||
"tempOffset tempUnit:C,Celsius,F,Fahrenheit,K,Kelvin ".
|
||||
"tempLow tempHigh";
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTHERM_Define - Implements DefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, def = definition string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_Define ($$) {
|
||||
my ($hash, $def) = @_;
|
||||
|
||||
# define <name> OWTHERM [<model>] <id> [interval]
|
||||
# e.g.: define flow OWTHERM 525715020000 300
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
my ($name,$model,$fam,$id,$crc,$interval,$ret);
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- default
|
||||
$name = $a[0];
|
||||
$interval = 300;
|
||||
$ret = "";
|
||||
|
||||
#-- check syntax
|
||||
return "OWTHERM: Wrong syntax, must be define <name> OWTHERM [<model>] <id> [interval]"
|
||||
if(int(@a) < 2 || int(@a) > 6);
|
||||
|
||||
#-- check if this is an old style definition, e.g. <model> is missing
|
||||
my $a2 = $a[2];
|
||||
my $a3 = defined($a[3]) ? $a[3] : "";
|
||||
if( ($a2 eq "none") || ($a3 eq "none") ) {
|
||||
return "OWTHERM: ID = none is obsolete now, please redefine";
|
||||
} elsif( $a2 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||
$model = "DS1820";
|
||||
$id = $a[2];
|
||||
if(int(@a)>=4) { $interval = $a[3]; }
|
||||
Log 1, "OWTHERM: Parameter [alarminterval] is obsolete now - must be set with I/O-Device"
|
||||
if(int(@a) == 5);
|
||||
} elsif( $a3 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||
$model = $a[2];
|
||||
$id = $a[3];
|
||||
if(int(@a)>=5) { $interval = $a[4]; }
|
||||
Log 1, "OWTHERM: Parameter [alarminterval] is obsolete now - must be set with I/O-Device"
|
||||
if(int(@a) == 6);
|
||||
} else {
|
||||
return "OWTHERM: $a[0] ID $a[2] invalid, specify a 12 digit value";
|
||||
}
|
||||
|
||||
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
||||
# FF = family id follows from the model
|
||||
# YY must be determined from id
|
||||
if( $model eq "DS1820" ){
|
||||
$fam = "10";
|
||||
}elsif( $model eq "DS1822" ){
|
||||
$fam = "22";
|
||||
}elsif( $model eq "DS18B20" ){
|
||||
$fam = "28";
|
||||
}else{
|
||||
return "OWTHERM: Wrong 1-Wire device model $model";
|
||||
}
|
||||
# determine CRC Code - only if this is a direct interface
|
||||
$crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC($fam.".".$id."00")) : "00";
|
||||
|
||||
#-- define device internals
|
||||
$hash->{ALARM} = 0;
|
||||
$hash->{OW_ID} = $id;
|
||||
$hash->{OW_FAMILY} = $fam;
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{ROM_ID} = $fam.".".$id.$crc;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
Log 3, "OWTHERM: Warning, no 1-Wire I/O device found for $name."
|
||||
if(!defined($hash->{IODev}->{NAME}));
|
||||
$modules{OWTHERM}{defptr}{$id} = $hash;
|
||||
$hash->{STATE} = "Defined";
|
||||
Log 3, "OWTHERM: Device $name defined.";
|
||||
|
||||
#-- Start timer for initialization in a few seconds
|
||||
InternalTimer(time()+10, "OWTHERM_InitializeDevice", $hash, 0);
|
||||
|
||||
#-- Start timer for updates
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWTHERM_GetValues", $hash, 0);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTHERM_InitializeDevice - delayed setting of initial readings and channel names
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_InitializeDevice($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my @args;
|
||||
|
||||
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "<span style=\"color:red\">▾</span>";
|
||||
$stateah = defined($attr{$name}{stateAH}) ? $attr{$name}{stateAH} : "<span style=\"color:red\">▴</span>";
|
||||
|
||||
#-- unit attribute defined ?
|
||||
$hash->{READINGS}{"temperature"}{UNIT} = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : "Celsius";
|
||||
$hash->{READINGS}{"temperature"}{TYPE} = "temperature";
|
||||
|
||||
#-- Initial readings temperature sensor
|
||||
$owg_temp = 0.0;
|
||||
$owg_tl = defined($attr{$name}{"tempLow"}) ? $attr{$name}{"tempLow"} : 0.0;
|
||||
$owg_th = defined($attr{$name}{"tempHigh"}) ? $attr{$name}{"tempHigh"} : 100.0;
|
||||
#-- Initialize all the display stuff
|
||||
OWTHERM_FormatValues($hash);
|
||||
#-- alarm
|
||||
@args = ($name,"tempLow",$owg_tl);
|
||||
OWTHERM_Set($hash,@args);
|
||||
@args = ($name,"tempHigh",$owg_th);
|
||||
OWTHERM_Set($hash,@args);
|
||||
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTHERM_FormatValues - put together various format strings
|
||||
#
|
||||
# Parameter hash = hash of device addressed, fs = format string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_FormatValues($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my ($unit,$offset,$factor,$abbr,$vval,$vlow,$vhigh,$statef);
|
||||
my ($value1,$value2,$value3) = ("","","");
|
||||
|
||||
my $tn = TimeNow();
|
||||
|
||||
#-- attributes defined ?
|
||||
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "<span style=\"color:red\">▾</span>";
|
||||
$stateah = defined($attr{$name}{stateAH}) ? $attr{$name}{stateAH} : "<span style=\"color:red\">▴</span>";
|
||||
$unit = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : $hash->{READINGS}{"temperature"}{UNIT};
|
||||
$offset = defined($attr{$name}{"tempOffset"}) ? $attr{$name}{"tempOffset"} : 0.0 ;
|
||||
$factor = 1.0;
|
||||
|
||||
if( $unit eq "Celsius" ){
|
||||
$abbr = "°C";
|
||||
} elsif ($unit eq "Kelvin" ){
|
||||
$abbr = "K";
|
||||
$offset += "273.16"
|
||||
} elsif ($unit eq "Fahrenheit" ){
|
||||
$abbr = "°F";
|
||||
$offset = ($offset+32)/1.8;
|
||||
$factor = 1.8;
|
||||
} else {
|
||||
$abbr="?";
|
||||
Log 1, "OWTHERM_FormatValues: unknown unit $unit";
|
||||
}
|
||||
#-- these values are rather coplex to obtain, therefore save them in the hash
|
||||
$hash->{READINGS}{"temperature"}{UNIT} = $unit;
|
||||
$hash->{READINGS}{"temperature"}{UNITABBR} = $abbr;
|
||||
$hash->{tempf}{offset} = $offset;
|
||||
$hash->{tempf}{factor} = $factor;
|
||||
|
||||
#-- correct values for proper offset, factor
|
||||
$vval = ($owg_temp + $offset)*$factor;
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"temperature"}{VAL} = $vval;
|
||||
$hash->{READINGS}{"temperature"}{TIME} = $tn;
|
||||
|
||||
#-- correct alarm values for proper offset, factor
|
||||
$vlow = ($owg_tl + $offset)*$factor;
|
||||
$vhigh = ($owg_th + $offset)*$factor;
|
||||
|
||||
#-- put into READINGS
|
||||
$hash->{READINGS}{"tempLow"}{VAL} = $vlow;
|
||||
$hash->{READINGS}{"tempLow"}{TIME} = $tn;
|
||||
$hash->{READINGS}{"tempHigh"}{VAL} = $vhigh;
|
||||
$hash->{READINGS}{"tempHigh"}{TIME} = $tn;
|
||||
|
||||
#-- formats for output
|
||||
$statef = "%5.2f ".$abbr;
|
||||
$value1 = "temperature: ".sprintf($statef,$vval);
|
||||
$value2 = sprintf($statef,$vval);
|
||||
$hash->{ALARM} = 1;
|
||||
|
||||
#-- Test for alarm condition
|
||||
if( ($vval <= $vlow) && ( $vval >= $vhigh ) ){
|
||||
$value2 .= " ".$stateal.$stateah;
|
||||
$value3 .= " ".$stateal.$stateah;
|
||||
}elsif( $vval <= $vlow ){
|
||||
$value2 .= " ".$stateal;
|
||||
$value3 .= " ".$stateal;
|
||||
}elsif( $vval >= $vhigh ){
|
||||
$value2 .= " ".$stateah;
|
||||
$value3 .= " ".$stateah;
|
||||
} else {
|
||||
$hash->{ALARM} = 0;
|
||||
}
|
||||
|
||||
#-- STATE
|
||||
$hash->{STATE} = $value2;
|
||||
#-- alarm
|
||||
#$hash->{READINGS}{alarms}{VAL} = $value3;
|
||||
#$hash->{READINGS}{alarms}{TIME} = $tn;
|
||||
return $value1;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTHERM_Get - Implements GetFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed, a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_Get($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
my $reading = $a[1];
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
my $value = undef;
|
||||
my $ret = "";
|
||||
|
||||
#-- check syntax
|
||||
return "OWTHERM: Get argument is missing @a"
|
||||
if(int(@a) != 2);
|
||||
|
||||
#-- check argument
|
||||
return "OWTHERM: Get with unknown argument $a[1], choose one of ".join(",", sort keys %gets)
|
||||
if(!defined($gets{$a[1]}));
|
||||
|
||||
#-- get id
|
||||
if($a[1] eq "id") {
|
||||
$value = $hash->{ROM_ID};
|
||||
return "$name.id => $value";
|
||||
}
|
||||
|
||||
#-- Get other values according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
|
||||
#-- get present
|
||||
if($a[1] eq "present" ) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||
$hash->{PRESENT} = $value;
|
||||
return "$name.present => $value";
|
||||
} else {
|
||||
return "OWTHERM: Verification not yet implemented for interface $interface";
|
||||
}
|
||||
}
|
||||
|
||||
#-- get interval
|
||||
if($reading eq "interval") {
|
||||
$value = $hash->{INTERVAL};
|
||||
return "$name.interval => $value";
|
||||
}
|
||||
|
||||
#-- reset presence
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
#-- not different from getting all values ..
|
||||
$ret = OWXTHERM_GetValues($hash);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWFS" ){
|
||||
$ret = OWFSTHERM_GetValues($hash);
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWTHERM: Get with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- process results
|
||||
if( defined($ret) ){
|
||||
return "OWTHERM: Could not get values from device $name, return was $ret";
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
OWTHERM_FormatValues($hash);
|
||||
|
||||
#-- return the special reading
|
||||
if ($reading eq "temperature") {
|
||||
return "OWTHERM: $name.temperature => ".
|
||||
$hash->{READINGS}{"temperature"}{VAL};
|
||||
} elsif ($reading eq "alarm") {
|
||||
return "OWTHERM: $name.alarm => L ".$hash->{READINGS}{"tempLow"}{VAL}.
|
||||
" H ".$hash->{READINGS}{"tempHigh"}{VAL};
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWTHERM_GetValues - Updates the readings from device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_GetValues($@) {
|
||||
my $hash = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $value = "";
|
||||
my $ret = "";
|
||||
|
||||
#-- restart timer for updates
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWTHERM_GetValues", $hash, 1);
|
||||
|
||||
#-- reset presence
|
||||
$hash->{PRESENT} = 0;
|
||||
|
||||
#-- Get values according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
if( $interface eq "OWX" ){
|
||||
#-- max 3 tries
|
||||
for(my $try=0; $try<3; $try++){
|
||||
$ret = OWXTHERM_GetValues($hash);
|
||||
last
|
||||
if( !defined($ret) );
|
||||
}
|
||||
}elsif( $interface eq "OWFS" ){
|
||||
$ret = OWFSTHERM_GetValues($hash);
|
||||
}else{
|
||||
Log 3, "OWTHERM: GetValues with wrong IODev type $interface";
|
||||
return 1;
|
||||
}
|
||||
|
||||
#-- process results
|
||||
if( defined($ret) ){
|
||||
Log 3, "OWTHERM: Could not get values from device $name, reason $ret";
|
||||
return 1;
|
||||
}
|
||||
$hash->{PRESENT} = 1;
|
||||
|
||||
#-- old state, new state
|
||||
my $oldval = $hash->{STATE};
|
||||
$value=OWTHERM_FormatValues($hash);
|
||||
my $newval = $hash->{STATE};
|
||||
#--logging depends on setting of the event-attribute
|
||||
Log 5, $value;
|
||||
my $ev = defined($attr{$name}{"event"}) ? $attr{$name}{"event"} : "on-update";
|
||||
if( ($ev eq "on-update") || (($ev eq "on-change") && ($newval ne $oldval)) ){
|
||||
$hash->{CHANGED}[0] = $value;
|
||||
DoTrigger($name, undef);
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWTHERM_Set - Set one value for device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# a = argument string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_Set($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
#-- for the selector: which values are possible
|
||||
return join(" ", sort keys %sets) if(@a == 2);
|
||||
#-- check syntax
|
||||
return "OWTHERM: Set needs one parameter"
|
||||
if(int(@a) != 3);
|
||||
#-- check argument
|
||||
return "OWTHERM: Set with unknown argument $a[1], choose one of ".join(",", sort keys %sets)
|
||||
if(!defined($sets{$a[1]}));
|
||||
|
||||
#-- define vars
|
||||
my $key = $a[1];
|
||||
my $value = $a[2];
|
||||
my $ret = undef;
|
||||
my $name = $hash->{NAME};
|
||||
my $model = $hash->{OW_MODEL};
|
||||
|
||||
#-- set new timer interval
|
||||
if($key eq "interval") {
|
||||
# check value
|
||||
return "OWTHERM: Set with short interval, must be > 1"
|
||||
if(int($value) < 1);
|
||||
# update timer
|
||||
$hash->{INTERVAL} = $value;
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWTHERM_GetValues", $hash, 1);
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-- set other values depending on interface type
|
||||
my $interface = $hash->{IODev}->{TYPE};
|
||||
my $offset = $hash->{tempf}{offset};
|
||||
my $factor = $hash->{tempf}{factor};
|
||||
|
||||
#-- find upper and lower boundaries for given offset/factor
|
||||
my $mmin = (-55+$offset)*$factor;
|
||||
my $mmax = (125+$offset)*$factor;
|
||||
return sprintf("OWTHERM: Set with wrong value $value for $key, range is [%3.1f,%3.1f]",$mmin,$mmax)
|
||||
if($value < $mmin || $value > $mmax);
|
||||
|
||||
#-- seems to be ok, put into the device
|
||||
$a[2] = int($value/$factor-$offset);
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXTHERM_SetValues($hash,@a);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWFS" ){
|
||||
$ret = OWFSTHERM_SetValues($hash,@a);
|
||||
return $ret
|
||||
if(defined($ret));
|
||||
} else {
|
||||
return "OWTHERM: Set with wrong IODev type $interface";
|
||||
}
|
||||
|
||||
#-- process results - we have to reread the device
|
||||
$hash->{PRESENT} = 1;
|
||||
OWTHERM_GetValues($hash);
|
||||
OWTHERM_FormatValues($hash);
|
||||
Log 4, "OWTHERM: Set $hash->{NAME} $key $value";
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWTHERM_Undef - Implements UndefFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWTHERM_Undef ($) {
|
||||
my ($hash) = @_;
|
||||
|
||||
delete($modules{OWTHERM}{defptr}{$hash->{OW_ID}});
|
||||
RemoveInternalTimer($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines in alphabetical order are only for a 1-Wire bus connected
|
||||
# via OWFS
|
||||
#
|
||||
# Prefix = OWFSTHERM
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWFSTHERM_GetValues - Get reading from one device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWFSTHERM_GetValues($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
my $ret = OW::get("/uncached/".$hash->{OW_FAMILY}.".".$hash->{OW_ID}."/temperature");
|
||||
if( defined($ret) ) {
|
||||
$hash->{PRESENT} = 1;
|
||||
$owg_temp = $ret;
|
||||
$owg_th = OW::get("/uncached/".$hash->{OW_FAMILY}.".".$hash->{OW_ID}."/temphigh");
|
||||
$owg_tl = OW::get("/uncached/".$hash->{OW_FAMILY}.".".$hash->{OW_ID}."/templow");
|
||||
} else {
|
||||
$hash->{PRESENT} = 0;
|
||||
$owg_temp = 0.0;
|
||||
$owg_th = 0.0;
|
||||
$owg_tl = 0.0;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWFSTHERM_SetValues - Implements SetFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWFSTHERM_SetValues($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
#-- define vars
|
||||
my $key = lc($a[1]);
|
||||
my $value = $a[2];
|
||||
|
||||
return OW::put($hash->{OW_FAMILY}.".".$hash->{OW_ID}."/$key",$value);
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# The following subroutines in alphabetical order are only for a 1-Wire bus connected
|
||||
# directly to the FHEM server
|
||||
#
|
||||
# Prefix = OWXTHERM
|
||||
#
|
||||
########################################################################################
|
||||
#
|
||||
# OWXTHERM_GetValues - Get reading from one device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXTHERM_GetValues($) {
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
#-- For default, perform the conversion NOT now
|
||||
my $con=1;
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
#-- check, if the conversion has been called before - only on devices with real power
|
||||
if( defined($attr{$hash->{IODev}->{NAME}}{buspower}) && ( $attr{$hash->{IODev}->{NAME}}{buspower} eq "real") ){
|
||||
$con=0;
|
||||
}
|
||||
|
||||
#-- if the conversion has not been called before
|
||||
if( $con==1 ){
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the start conversion command
|
||||
if( OWX_Complex($master,$owx_dev,"\x44",0) eq 0 ){
|
||||
return "$owx_dev not accessible";
|
||||
}
|
||||
#-- conversion needs some 950 ms - but we may also do it in shorter time !
|
||||
select(undef,undef,undef,1.0);
|
||||
}
|
||||
|
||||
#-- NOW ask the specific device
|
||||
OWX_Reset($master);
|
||||
#-- issue the match ROM command \x55 and the read scratchpad command \xBE
|
||||
#-- reading 9 + 1 + 8 data bytes and 1 CRC byte = 19 bytes
|
||||
my $res=OWX_Complex($master,$owx_dev,"\xBE",9);
|
||||
#Log 1,"OWXTHERM: data length from reading device is ".length($res)." bytes";
|
||||
#-- process results
|
||||
if( $res eq 0 ){
|
||||
return "$owx_dev not accessible in 2nd step";
|
||||
}
|
||||
|
||||
#-- process results
|
||||
my @data=split(//,$res);
|
||||
return "invalid data length, ".int(@data)." bytes"
|
||||
if (@data != 19);
|
||||
return "invalid data"
|
||||
if (ord($data[17])<=0);
|
||||
return "invalid CRC"
|
||||
if (OWX_CRC8(substr($res,10,8),$data[18])==0);
|
||||
|
||||
#-- this must be different for the different device types
|
||||
# family = 10 => DS1820, DS18S20
|
||||
if( $hash->{OW_FAMILY} eq "10" ) {
|
||||
|
||||
my $count_remain = ord($data[16]);
|
||||
my $count_perc = ord($data[17]);
|
||||
my $delta = -0.25 + ($count_perc - $count_remain)/$count_perc;
|
||||
|
||||
my $lsb = ord($data[10]);
|
||||
my $msb = 0;
|
||||
my $sign = ord($data[11]) & 255;
|
||||
|
||||
#-- test with -25 degrees
|
||||
#$lsb = 12*16+14;
|
||||
#$sign = 1;
|
||||
#$delta = 0;
|
||||
|
||||
#-- 2's complement form = signed bytes
|
||||
$owg_temp = int($lsb/2) + $delta;
|
||||
if( $sign !=0 ){
|
||||
$owg_temp = -128+$owg_temp;
|
||||
}
|
||||
|
||||
$owg_th = ord($data[12]) > 127 ? 128-ord($data[12]) : ord($data[12]);
|
||||
$owg_tl = ord($data[13]) > 127 ? 128-ord($data[13]) : ord($data[13]);
|
||||
|
||||
return undef;
|
||||
|
||||
} elsif ( ($hash->{OW_FAMILY} eq "22") || ($hash->{OW_FAMILY} eq "28") ) {
|
||||
|
||||
my $lsb = ord($data[10]);
|
||||
my $msb = ord($data[11]) & 7;
|
||||
my $sign = ord($data[11]) & 248;
|
||||
|
||||
#-- test with -55 degrees
|
||||
#$lsb = 9*16;
|
||||
#$sign = 1;
|
||||
#$msb = 7;
|
||||
|
||||
#-- 2's complement form = signed bytes
|
||||
$owg_temp = $msb*16+ $lsb/16;
|
||||
if( $sign !=0 ){
|
||||
$owg_temp = -128+$owg_temp;
|
||||
}
|
||||
$owg_th = ord($data[12]) > 127 ? 128-ord($data[12]) : ord($data[12]);
|
||||
$owg_tl = ord($data[13]) > 127 ? 128-ord($data[13]) : ord($data[13]);
|
||||
|
||||
return undef;
|
||||
|
||||
} else {
|
||||
return "OWXTHERM: Unknown device family $hash->{OW_FAMILY}\n";
|
||||
}
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
# OWXTHERM_SetValues - Implements SetFn function
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# a = argument array
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXTHERM_SetValues($@) {
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
#-- define vars
|
||||
my $key = $a[1];
|
||||
my $value = $a[2];
|
||||
$owg_tl = $value if( $key eq "tempLow" );
|
||||
$owg_th = $value if( $key eq "tempHigh" );
|
||||
|
||||
#-- put into 2's complement formed (signed byte)
|
||||
my $tlp = $owg_tl < 0 ? 128 - $owg_tl : $owg_tl;
|
||||
my $thp = $owg_th < 0 ? 128 - $owg_th : $owg_th;
|
||||
|
||||
OWX_Reset($master);
|
||||
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E,
|
||||
# followed by the write EEPROM command \x48
|
||||
#
|
||||
# so far writing the EEPROM does not work properly.
|
||||
# 1. \x48 directly appended to the write scratchpad command => command ok, no effect on EEPROM
|
||||
# 2. \x48 appended to match ROM => command not ok.
|
||||
# 3. \x48 sent by WriteBytePower after match ROM => command ok, no effect on EEPROM
|
||||
|
||||
my $select=sprintf("\x4E%c%c\x48",$thp,$tlp);
|
||||
my $res=OWX_Complex($master,$owx_dev,$select,0);
|
||||
|
||||
if( $res eq 0 ){
|
||||
return "OWXTHERM: Device $owx_dev not accessible";
|
||||
}
|
||||
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
Binary file not shown.
Before Width: | Height: | Size: 88 KiB |
Binary file not shown.
Before Width: | Height: | Size: 211 KiB |
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
Binary file not shown.
Before Width: | Height: | Size: 28 KiB |
Binary file not shown.
Before Width: | Height: | Size: 40 KiB |
@ -1,786 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<a name="OWX"></a>
|
||||
<h3>OWX</h3>
|
||||
<ul> FHEM module to commmunicate with 1-Wire bus devices <ul>
|
||||
<li>via an active DS2480/DS2482/DS2490/DS9097U bus master interface attached to an
|
||||
USB port or </li>
|
||||
<li>via a passive DS9097 interface attached to an USB port or</li>
|
||||
<li>via a network-attached CUNO or through a COC on the RaspBerry Pi</li>
|
||||
</ul> Internally these interfaces are vastly different, read the corresponding <a
|
||||
href="http://fhemwiki.de/wiki/Interfaces_f%C3%BCr_1-Wire"> Wiki pages </a>
|
||||
<br />
|
||||
<br />
|
||||
<b>Example</b><br />
|
||||
<ul>
|
||||
<code>define OWio1 OWX /dev/ttyUSB1</code>
|
||||
<br />
|
||||
<code>define OWio2 OWX COC</code>
|
||||
<br />
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWXdefine">
|
||||
<b>Define</b></a>
|
||||
<ul>
|
||||
<code>define <name> OWX <serial-device></code> or <br />
|
||||
<code>define <name> OWX <cuno/coc-device></code>
|
||||
<br /><br /> Define a 1-Wire interface to communicate with a 1-Wire bus.<br />
|
||||
<br />
|
||||
<li>
|
||||
<code><serial-device></code> The serial device (e.g. USB port) to which
|
||||
the 1-Wire bus is attached.</li>
|
||||
<li>
|
||||
<code><cuno-device></code> The previously defined CUNO to which the 1-Wire
|
||||
bus is attached. </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWXset">
|
||||
<b>Set</b></a>
|
||||
<ul>
|
||||
<li><a name="owx_interval">
|
||||
<code>set <name> interval <value></code>
|
||||
</a>
|
||||
<br /><br /> sets the time period in seconds for "kicking" the 1-Wire bus
|
||||
(default is 300 seconds). This means: <ul>
|
||||
<li>With 1-Wire bus interfaces that do not supply power to the 1-Wire bus
|
||||
(attr buspower parasitic), the 1-Wire bus is reset at these intervals. </li>
|
||||
<li>With 1-Wire bus interfaces that supply power to the 1-Wire bus (attr
|
||||
buspower = real), all temperature measurement devices on the bus receive
|
||||
the command to start a temperature conversion (saves a lot of time when
|
||||
reading) </li>
|
||||
<li>With 1-Wire bus interfaces that contain a busmaster chip, the response
|
||||
to a reset pulse contains information about alarms.</li>
|
||||
</ul><br />
|
||||
</li>
|
||||
<li><a name="owx_followAlarms">
|
||||
<code>set <name> followAlarms on|off</code>
|
||||
</a>
|
||||
<br /><br /> instructs the module to start an alarm search in case a reset pulse
|
||||
discovers any 1-Wire device which has the alarm flag set. </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWXget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owx_alarms"></a>
|
||||
<code>get <name> alarms</code>
|
||||
<br /><br /> performs an "alarm search" for devices on the 1-Wire bus and, if
|
||||
found, generates an event in the log (not with CUNO). </li>
|
||||
<br />
|
||||
<li><a name="owx_devices"></a>
|
||||
<code>get <name> devices</code>
|
||||
<br /><br /> redicovers all devices on the 1-Wire bus. If a device found has a
|
||||
previous definition, this is automatically used. If a device is found but has no
|
||||
definition, it is autocreated. If a defined device is not on the 1-Wire bus, it
|
||||
is autodeleted. </li>
|
||||
<br />
|
||||
<br />
|
||||
</ul>
|
||||
<a name="OWXattr">
|
||||
<b>Attributes</b></a>
|
||||
<ul>
|
||||
<li><a name="OWXbuspower"><code>attr <name> buspower real|parasitic</code></a>
|
||||
<br />tells FHEM whether power is supplied to the 1-Wire bus or not.</li>
|
||||
<li>Standard attributes alias, comment, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>, <a href="#webCmd">webCmd</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
<a name="OWAD"></a>
|
||||
<h3>OWAD</h3>
|
||||
<ul>FHEM module to commmunicate with 1-Wire A/D converters<br /><br /> Note:<br /> This
|
||||
1-Wire module so far works only with the OWX interface module. Please define an <a
|
||||
href="#OWX">OWX</a> device first. <br />
|
||||
<br /><b>Example</b><br />
|
||||
<ul>
|
||||
<code>define OWX_AD OWAD 724610000000 45</code>
|
||||
<br />
|
||||
<code>attr OWX_AD DAlarm high</code>
|
||||
<br />
|
||||
<code>attr OWX_AD DFactor 31.907097</code>
|
||||
<br />
|
||||
<code>attr OWX_AD DHigh 50.0</code>
|
||||
<br />
|
||||
<code>attr OWX_AD DName relHumidity|humidity</code>
|
||||
<br />
|
||||
<code>attr OWX_AD DOffset -0.8088</code>
|
||||
<br />
|
||||
<code>attr OWX_AD DUnit percent|%</code>
|
||||
<br />
|
||||
</ul><br />
|
||||
<a name="OWADdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> OWAD [<model>] <id> [<interval>]</code>
|
||||
<br /><br /> Define a 1-Wire A/D converter.<br /><br />
|
||||
<li>
|
||||
<code>[<model>]</code><br /> Defines the A/D converter model (and thus
|
||||
1-Wire family id), currently the following values are permitted: <ul>
|
||||
<li>model DS2450 with family id 20 (default if the model parameter is
|
||||
omitted)</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<code><id></code>
|
||||
<br />12-character unique ROM id of the converter device without family id and
|
||||
CRC code </li>
|
||||
<li>
|
||||
<code><interval></code>
|
||||
<br />Measurement interval in seconds. The default is 300 seconds. </li>
|
||||
<br />
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWADset">
|
||||
<b>Set</b></a>
|
||||
<ul>
|
||||
<li><a name="owad_interval">
|
||||
<code>set <name> interval <int></code></a><br /> Measurement
|
||||
interval in seconds. The default is 300 seconds. </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWADget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owad_id">
|
||||
<code>get <name> id</code></a>
|
||||
<br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
|
||||
<li><a name="owad_present">
|
||||
<code>get <name> present</code>
|
||||
</a>
|
||||
<br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
|
||||
<li><a name="owad_interval2">
|
||||
<code>get <name> interval</code></a><br />Returns measurement interval
|
||||
in seconds. </li>
|
||||
<li><a name="owad_reading">
|
||||
<code>get <name> reading</code></a><br />Obtain the measuement values. </li>
|
||||
<li><a name="owad_alarm">
|
||||
<code>get <name> alarm</code></a><br />Obtain the alarm values. </li>
|
||||
<li><a name="owad_status">
|
||||
<code>get <name> status</code></a><br />Obtain the i/o status values.
|
||||
</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWADattr">
|
||||
<b>Attributes</b></a>
|
||||
<ul>
|
||||
<li><a name="owad_stateAL0"><code>attr <name> stateAL0
|
||||
<string></code></a>
|
||||
<br />character string for denoting low normal condition, default is green down
|
||||
triangle, e.g. the code <span
|
||||
style="color:green">&#x25BE;</span> leading to the sign <span
|
||||
style="color:green">▾</span>
|
||||
</li>
|
||||
<li><a name="owad_stateAH0"><code>attr <name> stateAH0
|
||||
<string></code></a>
|
||||
<br />character string for denoting high alarm condition, default is green
|
||||
upward triangle, e.g. the code <span
|
||||
style="color:green">&#x25B4;</span> leading to the sign <span
|
||||
style="color:green">▴</span>
|
||||
</li>
|
||||
<li><a name="owad_stateAL1"><code>attr <name> stateAL1
|
||||
<string></code></a>
|
||||
<br />character string for denoting low alarm condition, default is red down
|
||||
triangle, e.g. the code <span style="color:red">&#x25BE;</span>
|
||||
leading to the sign <span style="color:red">▾</span></li>
|
||||
<li><a name="owad_stateAH1"><code>attr <name> stateAH1
|
||||
<string></code></a>
|
||||
<br />character string for denoting high alarm condition, default is red upward
|
||||
triangle, e.g. the code <span style="color:red">&#x25B4;</span>
|
||||
leading to the sign <span style="color:red">▴</span>
|
||||
</li>
|
||||
</ul> For each of the following attributes, the channel identification A,B,C,D may be
|
||||
used. <ul>
|
||||
<li><a name="owad_cname"><code>attr <name> <channel>Name
|
||||
<string>|<string></code></a>
|
||||
<br />name for the channel | a type description for the measured value. </li>
|
||||
<li><a name="owad_cunit"><code>attr <name> <channel>Unit
|
||||
<string>|<string></code></a>
|
||||
<br />unit of measurement for this channel | its abbreviation. </li>
|
||||
<li><a name="owad_coffset"><code>attr <name> <channel>Offset
|
||||
<float></code></a>
|
||||
<br />offset added to the reading in this channel. </li>
|
||||
<li><a name="owad_cfactor"><code>attr <name> <channel>Factor
|
||||
<float></code></a>
|
||||
<br />factor multiplied to (reading+offset) in this channel. </li>
|
||||
<li><a name="owad_calarm"><code>attr <name> <channel>Alarm
|
||||
<string></code></a>
|
||||
<br />alarm setting in this channel, either both, low, high or none (default). </li>
|
||||
<li><a name="owad_clow"><code>attr <name> <channel>Low
|
||||
<float></code></a>
|
||||
<br />measurement value (on the scale determined by offset and factor) for low
|
||||
alarm. </li>
|
||||
<li><a name="owad_chigh"><code>attr <name> <channel>High
|
||||
<float></code></a>
|
||||
<br />measurement value (on the scale determined by offset and factor) for high
|
||||
alarm. </li>
|
||||
<li><a name="owad_event"><code>attr <name> event on-change|on-update
|
||||
</code></a>This attribte work similarly, but not identically to the standard event-on-update-change/event-on-update-reading attribute.
|
||||
<ul><li><code>event on-update</code> (default) will write a notify/FileLog event any time a measurement is received.</li>
|
||||
<li><code>event on-change</code> will write a notify/FileLog event only when a measurement is different from the previous one.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Standard attributes alias, comment, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>, <a href="#webCmd">webCmd</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
<a name="OWCOUNT"></a>
|
||||
<h3>OWCOUNT</h3>
|
||||
<ul>FHEM module to commmunicate with 1-Wire Counter/RAM DS2423 #<br /><br /> Note:<br />
|
||||
This 1-Wire module so far works only with the OWX interface module. Please define an <a
|
||||
href="#OWX">OWX</a> device first. <br />
|
||||
<br /><b>Example</b><br />
|
||||
<ul>
|
||||
<code>define OWX_C OWCOUNT DS2423 CE780F000000 300</code>
|
||||
<br />
|
||||
<code>attr OWX_C AName Water|volume</code>
|
||||
<br />
|
||||
<code>attr OWX_C AUnit liters|l</code>
|
||||
<br />
|
||||
<code>attr OWX_CAMode daily</code>
|
||||
<br />
|
||||
</ul><br />
|
||||
<a name="OWCOUNTdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> OWCOUNT [<model>] <id>
|
||||
[<interval>]</code>
|
||||
<br /><br /> Define a 1-Wire counter.<br /><br />
|
||||
<li>
|
||||
<code>[<model>]</code><br /> Defines the counter model (and thus 1-Wire
|
||||
family id), currently the following values are permitted: <ul>
|
||||
<li>model DS2423 with family id 1D (default if the model parameter is
|
||||
omitted)</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<code><id></code>
|
||||
<br />12-character unique ROM id of the converter device without family id and
|
||||
CRC code </li>
|
||||
<li>
|
||||
<code><interval></code>
|
||||
<br />Measurement interval in seconds. The default is 300 seconds. </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWCOUNTset">
|
||||
<b>Set</b></a>
|
||||
<ul>
|
||||
<li><a name="owcount_interval">
|
||||
<code>set <name> interval <int></code></a><br /> Measurement
|
||||
interval in seconds. The default is 300 seconds. </li>
|
||||
<li><a name="owcount_memory">
|
||||
<code>set <name> memory <page></code></a><br />Write 32 bytes to
|
||||
memory page 0..13 </li>
|
||||
<li><a name="owcount_midnight">
|
||||
<code>set <name> midnight <channel-name></code></a><br />Write
|
||||
the day's starting value for counter <channel> (A, B or named channel, see
|
||||
below)</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWCOUNTget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owcount_id">
|
||||
<code>get <name> id</code></a>
|
||||
<br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
|
||||
<li><a name="owcount_present">
|
||||
<code>get <name> present</code>
|
||||
</a>
|
||||
<br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
|
||||
<li><a name="owcount_interval2">
|
||||
<code>get <name> interval</code></a><br />Returns measurement interval
|
||||
in seconds. </li>
|
||||
<li><a name="owcount_memory2">
|
||||
<code>get <name> memory <page></code></a><br />Obtain 32 bytes
|
||||
from memory page 0..13 </li>
|
||||
<li><a name="owcount_midnight2">
|
||||
<code>get <name> midnight <channel-name></code></a><br />Obtain
|
||||
the day's starting value for counter <channel> (A, B or named channel, see
|
||||
below)</li>
|
||||
<li><a name="owcount_counter">
|
||||
<code>get <name> counter <channel-name></code></a><br />Obtain
|
||||
the current value for counter <channel> (A, B or named channel, see
|
||||
below)</li>
|
||||
<li><a name="owcount_counters">
|
||||
<code>get <name> counters</code></a><br />Obtain the current value
|
||||
both counters</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWCOUNTattr">
|
||||
<b>Attributes</b></a>
|
||||
<ul>For each of the following attributes, the channel identification A,B may be used.
|
||||
<li><a name="owcount_cname"><code>attr <name> <channel>Name
|
||||
<string>|<string></code></a>
|
||||
<br />name for the channel | a type description for the measured value. </li>
|
||||
<li><a name="owcount_cunit"><code>attr <name> <channel>Unit
|
||||
<string>|<string></code></a>
|
||||
<br />unit of measurement for this channel | its abbreviation. </li>
|
||||
<li><a name="owcount_coffset"><code>attr <name> <channel>Offset
|
||||
<float></code></a>
|
||||
<br />offset added to the reading in this channel. </li>
|
||||
<li><a name="owcount_cfactor"><code>attr <name> <channel>Factor
|
||||
<float></code></a>
|
||||
<br />factor multiplied to (reading+offset) in this channel. </li>
|
||||
<li><a name="owcount_cmode"><code>attr <name> <channel>Mode daily |
|
||||
normal</code></a>
|
||||
<br />factor multiplied to (reading+offset) in this channel. </li>
|
||||
<li><a name="owcount_event"><code>attr <name> event on-change|on-update
|
||||
</code></a>This attribte work similarly, but not identically to the standard event-on-update-change/event-on-update-reading attribute.
|
||||
<ul><li><code>event on-update</code> (default) will write a notify/FileLog event any time a measurement is received.</li>
|
||||
<li><code>event on-change</code> will write a notify/FileLog event only when a measurement is different from the previous one.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Standard attributes alias, comment, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>, <a href="#webCmd">webCmd</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
<a name="OWID"></a>
|
||||
<h3>OWID</h3>
|
||||
<ul>FHEM module for 1-Wire devices that know only their unique ROM ID<br />
|
||||
<br />Note:<br /> This 1-Wire module so far works only with the OWX interface module.
|
||||
Please define an <a href="#OWX">OWX</a> device first. <br />
|
||||
<br /><b>Example</b><br />
|
||||
<ul>
|
||||
<code>define ROM1 OWX_ID OWCOUNT CE780F000000</code>
|
||||
<br />
|
||||
</ul><br />
|
||||
<a name="OWIDdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> OWID <id> </code>
|
||||
<br /><br /> Define a 1-Wire device.<br /><br />
|
||||
<li>
|
||||
<code><id></code>
|
||||
<br />12-character unique ROM id of the converter device without family id and
|
||||
CRC code </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWIDget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owid_id">
|
||||
<code>get <name> id</code></a>
|
||||
<br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
|
||||
<li><a name="owid_present">
|
||||
<code>get <name> present</code>
|
||||
</a>
|
||||
<br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
|
||||
</ul>
|
||||
<br />
|
||||
</ul>
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
<a name="OWLCD"></a>
|
||||
<h3>OWLCD</h3>
|
||||
<ul>FHEM module to commmunicate with the <a
|
||||
href="http://www.louisswart.co.za/1-Wire_Overview.html">1-Wire LCD controller</a>
|
||||
from Louis Swart (1-Wire family id FF). See also the corresponding <a
|
||||
href="http://fhemwiki.de/wiki/1-Wire_Textdisplay">Wiki page.</a><br /><br />
|
||||
Note:<br /> This 1-Wire module so far works only with the OWX interface module. Please
|
||||
define an <a href="#OWX">OWX</a> device first. <br />
|
||||
<br /><b>Example</b><br />
|
||||
<ul>
|
||||
<code>define OWX_LCD OWLCD 9F0700000100</code>
|
||||
<br />
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWLCDdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> OWLCD <id></code>
|
||||
<br /><br /> Define a 1-Wire LCD device.<br /><br />
|
||||
<li>
|
||||
<code><id></code>
|
||||
<br />12-character unique ROM id of the converter device without family id and
|
||||
CRC code </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWLCDset">
|
||||
<b>Set</b></a>
|
||||
<ul>
|
||||
<li><a name="owlcd_icon">
|
||||
<code>set <name> icon <int> on|off|blink</code></a><br /> Set
|
||||
one of the icons 0..14 on, off or blinking</li>
|
||||
<li><a name="owlcd_icon2">
|
||||
<code>set <name> icon 15 0..6</code></a><br /> Set icon 15 to one of
|
||||
its values</li>
|
||||
<li><a name="owlcd_icon3">
|
||||
<code>set <name> icon none</code></a><br /> Set all icons off</li>
|
||||
<li><a name="owlcd_line">
|
||||
<code>set <name> line <int> <string></code></a><br />
|
||||
Write LCD line 0..3 with some content </li>
|
||||
<li><a name="owlcd_memory">
|
||||
<code>set <name> memory <page>
|
||||
<string></code></a><br />Write memory page 0..6</li>
|
||||
<li><a name="owlcd_gpio">
|
||||
<code>set <name> gpio <value></code></a><br />Write state for
|
||||
all three gpio pins (value = 0..7, for each bit 0=ON, 1=OFF)</li>
|
||||
<li><a name="owlcd_bl">
|
||||
<code>set <name> backlight ON|OFF</code></a><br />Switch backlight on
|
||||
or off</li>
|
||||
<li><a name="owlcd_lcd">
|
||||
<code>set <name> lcd ON|OFF</code></a><br />Switch LCD power on or
|
||||
off</li>
|
||||
<li><a name="owlcd_gpio">
|
||||
<code>set <name> reset</code></a><br />Reset the display</li>
|
||||
<li><a name="owlcd_gpio">
|
||||
<code>set <name> test</code></a><br />Test the display</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="owlcdget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owlcd_id">
|
||||
<code>get <name> id</code></a>
|
||||
<br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
|
||||
<li><a name="owlcd_present">
|
||||
<code>get <name> present</code>
|
||||
</a>
|
||||
<br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
|
||||
<li><a name="owlcd_memory2">
|
||||
<code>get <name> memory <page></code></a><br />Read memory page
|
||||
0..6 </li>
|
||||
<li><a name="owlcd_gpio">
|
||||
<code>get <name> gpio</code></a><br />Obtain state of all four input
|
||||
channels (15 = all off, 0 = all on)</li>
|
||||
<li><a name="owlcd_counter">
|
||||
<code>get <name> gpio</code></a><br />Obtain state of all four input
|
||||
counters (4 x 16 Bit)</li>
|
||||
<li><a name="owlcd_version">
|
||||
<code>get <name> version</code></a><br />Obtain firmware version of
|
||||
the controller</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="owlcdattr">
|
||||
<b>Attributes</b></a>
|
||||
<ul>
|
||||
<li>Standard attributes alias, comment, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>, <a href="#webCmd">webCmd</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
<a name="OWMULTI"></a>
|
||||
<h3>OWMULTI</h3>
|
||||
<ul>FHEM module to commmunicate with 1-Wire multi-sensors, currently the DS2438 smart battery monitor<br /><br /> Note:<br /> This
|
||||
1-Wire module so far works only with the OWX interface module. Please define an <a
|
||||
href="#OWX">OWX</a> device first. <br />
|
||||
<br /><b>Example</b><br />
|
||||
<ul>
|
||||
<code>define OWX_M OWMULTI 7C5034010000 45</code>
|
||||
<br />
|
||||
<code>attr OWX_M VName relHumidity|humidity</code>
|
||||
<br />
|
||||
<code>attr OWX_M VUnit percent|%</code>
|
||||
<br />
|
||||
<code>attr OWX_M VFunction (161.29 * V / VDD - 25.8065)/(1.0546 - 0.00216 * T)</code>
|
||||
<br />
|
||||
</ul><br />
|
||||
<a name="OWMULTIdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> OWMULTI [<model>] <id> [<interval>]</code>
|
||||
<br /><br /> Define a 1-Wire multi-sensor<br /><br />
|
||||
<li>
|
||||
<code>[<model>]</code><br /> Defines the sensor model (and thus
|
||||
1-Wire family id), currently the following values are permitted: <ul>
|
||||
<li>model DS2438 with family id 26 (default if the model parameter is
|
||||
omitted). Measured is a temperature value, an external voltage and the current supply voltage</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<code><id></code>
|
||||
<br />12-character unique ROM id of the converter device without family id and
|
||||
CRC code </li>
|
||||
<li>
|
||||
<code><interval></code>
|
||||
<br />Measurement interval in seconds. The default is 300 seconds. </li>
|
||||
<br />
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWMULTIset">
|
||||
<b>Set</b></a>
|
||||
<ul>
|
||||
<li><a name="owmulti_interval">
|
||||
<code>set <name> interval <int></code></a><br /> Measurement
|
||||
interval in seconds. The default is 300 seconds. </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWMULTIget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owmulti_id">
|
||||
<code>get <name> id</code></a>
|
||||
<br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
|
||||
<li><a name="owmulti_present">
|
||||
<code>get <name> present</code>
|
||||
</a>
|
||||
<br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
|
||||
<li><a name="owmulti_interval2">
|
||||
<code>get <name> interval</code></a><br />Returns measurement interval
|
||||
in seconds. </li>
|
||||
<li><a name="owmulti_reading">
|
||||
<code>get <name> reading</code></a><br />Obtain the measurement value from VFunction. </li>
|
||||
<li><a name="owmulti_temperature">
|
||||
<code>get <name> temperature</code></a><br />Obtain the temperature value. </li>
|
||||
<li><a name="owmulti_vdd">
|
||||
<code>get <name> VDD</code></a><br />Obtain the current supply voltage.
|
||||
</li>
|
||||
<li><a name="owmulti_raw">
|
||||
<code>get <name> V</code> or <code>get <name> raw</code></a><br />Obtain the raw external voltage measurement.
|
||||
</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWMULTIattr">
|
||||
<b>Attributes</b></a>
|
||||
<ul>
|
||||
<li><a name="owmulti_vname"><code>attr <name> VName
|
||||
<string>|<string></code></a>
|
||||
<br />name for the channel | a type description for the measured value. </li>
|
||||
<li><a name="owmulti_vunit"><code>attr <name> VUnit
|
||||
<string>|<string></code></a>
|
||||
<br />unit of measurement for this channel | its abbreviation. </li>
|
||||
<li><a name="owmulti_vfunction"><code>attr <name> VFunction
|
||||
<string></code></a>
|
||||
<br />arbitrary functional expression involving the values VDD, V, T. Example see above.
|
||||
<ul>
|
||||
<li>VDD is replaced by the measured supply voltage in Volt,</li>
|
||||
<li> V by the measured external voltage,</li>
|
||||
<li>T by the measured and corrected temperature in its unit</li>
|
||||
</ul></li>
|
||||
<li><a name="owmulti_tempOffset"><code>attr <name> tempOffset
|
||||
<float></code>
|
||||
</a>
|
||||
<br />temperature offset in °C added to the raw temperature reading. </li>
|
||||
<li><a name="owmulti_tempUnit"><code>attr <name> tempUnit
|
||||
Celsius|Kelvin|Fahrenheit|C|K|F</code>
|
||||
</a>
|
||||
<br />unit of measurement (temperature scale), default is Celsius = °C </li>
|
||||
<li><a name="owmulti_event"><code>attr <name> event on-change|on-update
|
||||
</code></a>This attribte work similarly, but not identically to the standard event-on-update-change/event-on-update-reading attribute.
|
||||
<ul><li><code>event on-update</code> (default) will write a notify/FileLog event any time a measurement is received.</li>
|
||||
<li><code>event on-change</code> will write a notify/FileLog event only when a measurement is different from the previous one.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Standard attributes alias, comment, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>, <a href="#webCmd">webCmd</a></li>
|
||||
|
||||
</ul>
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
<a name="OWSWITCH"></a>
|
||||
<h3>OWSWITCH</h3>
|
||||
<ul>FHEM module to commmunicate with 1-Wire Programmable Switches <br /><br /> Note:<br />
|
||||
This 1-Wire module so far works only with the OWX interface module. Please define an <a
|
||||
href="#OWX">OWX</a> device first. <br />
|
||||
<br /><b>Example</b><br />
|
||||
<ul>
|
||||
<code>define OWX_S OWSWITCH DS2413 B5D502000000 60</code>
|
||||
<br />
|
||||
<code>attr OWX_S AName Lampe|light</code>
|
||||
<br />
|
||||
<code>attr OWX_S AUnit AN|AUS</code>
|
||||
<br />
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWSWITCHdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> OWSWITCH [<model>] <id>
|
||||
[<interval>]</code>
|
||||
<br /><br /> Define a 1-Wire switch.<br /><br />
|
||||
<li>
|
||||
<code>[<model>]</code><br /> Defines the switch model (and thus 1-Wire
|
||||
family id), currently the following values are permitted: <ul>
|
||||
<li>model DS2413 with family id 3A (default if the model parameter is
|
||||
omitted). 2 Channel switch with onboard memory</li>
|
||||
<li>model DS2406 with family id 12. 2 Channel switch </li>
|
||||
<li>model DS2406 with family id 29. 8 Channel switch</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<code><id></code>
|
||||
<br />12-character unique ROM id of the converter device without family id and
|
||||
CRC code </li>
|
||||
<li>
|
||||
<code><interval></code>
|
||||
<br />Measurement interval in seconds. The default is 300 seconds. </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWSWITCHset">
|
||||
<b>Set</b></a>
|
||||
<ul>
|
||||
<li><a name="owswitch_interval">
|
||||
<code>set <name> interval <int></code></a><br /> Measurement
|
||||
interval in seconds. The default is 300 seconds. </li>
|
||||
<li><a name="owswitch_output">
|
||||
<code>set <name> output <channel-name> ON |
|
||||
OFF</code></a><br />Set value for channel (A,B,... or defined channel name). 1 = OFF, 0 = ON in normal usage.
|
||||
See also the note above</li>
|
||||
<li><a name="owswitch_gpio">
|
||||
<code>set <name> gpio <value></code></a><br />Set values for channels (For 2 channels: 3 = A and B OFF, 1 = B ON 2 = A ON 0 = both ON)</li>
|
||||
<li><a name="owswitch_init">
|
||||
<code>set <name> init yes</code></a><br /> Re-initialize the device</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWSWITCHget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owswitch_id">
|
||||
<code>get <name> id</code></a>
|
||||
<br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
|
||||
<li><a name="owswitch_present">
|
||||
<code>get <name> present</code>
|
||||
</a>
|
||||
<br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
|
||||
<li><a name="owswitch_interval2">
|
||||
<code>get <name> interval</code></a><br />Returns measurement interval
|
||||
in seconds. </li>
|
||||
<li><a name="owswitch_input">
|
||||
<code>get <name> input <channel-name></code></a><br />
|
||||
state for channel (A,B, ... or defined channel name)
|
||||
This value reflects the measured value, not necessarily the one set as
|
||||
output state, because the output transistors are open collector switches. A measured
|
||||
state of 1 = OFF therefore corresponds to an output state of 1 = OFF, but a measured
|
||||
state of 0 = ON can also be due to an external shortening of the output.</li>
|
||||
<li><a name="owswitch_gpio">
|
||||
<code>get <name> gpio</code></a><br />Obtain state of all
|
||||
channels</li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWSWITCHattr">
|
||||
<b>Attributes</b></a> For each of the following attributes, the channel
|
||||
identification A,B,... may be used. <ul>
|
||||
<li><a name="owswitch_cname"><code>attr <name> <channel>Name
|
||||
<string>|<string></code></a>
|
||||
<br />name for the channel | a type description for the measured value. </li>
|
||||
<li><a name="owswitch_cunit"><code>attr <name> <channel>Unit
|
||||
<string>|<string></code></a>
|
||||
<br />display for on | off condition </li>
|
||||
<li><a name="owswitch_event"><code>attr <name> event on-change|on-update
|
||||
</code></a>This attribte work similarly, but not identically to the standard event-on-update-change/event-on-update-reading attribute.
|
||||
<ul><li><code>event on-update</code> (default) will write a notify/FileLog event any time a measurement is received.</li>
|
||||
<li><code>event on-change</code> will write a notify/FileLog event only when a measurement is different from the previous one.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Standard attributes alias, comment, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>, <a href="#webCmd">webCmd</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
<!--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
|
||||
<a name="OWTHERM"></a>
|
||||
<h3>OWTHERM</h3>
|
||||
<ul>FHEM module to commmunicate with 1-Wire bus digital thermometer devices<br /><br />
|
||||
Note:<br /> This is the only 1-Wire module which so far works with both the OWFS and the
|
||||
OWX interface module. Please define an <a href="#OWFS">OWFS</a> device or an <a
|
||||
href="#OWX">OWX</a> device first. <br />
|
||||
<br /><b>Example</b><br />
|
||||
<ul>
|
||||
<code>define OWX_T OWTHERM DS18B20 E8D09B030000 300</code>
|
||||
<br />
|
||||
<code>attr OWX_T tempUnit Kelvin</code>
|
||||
<br />
|
||||
</ul><br />
|
||||
<a name="OWTHERMdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> OWTHERM [<model>] <id>
|
||||
[<interval>]</code>
|
||||
<br /><br /> Define a 1-Wire digital thermometer device.<br /><br />
|
||||
<li>
|
||||
<code>[<model>]</code><br /> Defines the thermometer model (and thus
|
||||
1-Wire family id) currently the following values are permitted: <ul>
|
||||
<li>model DS1820 with family id 10 (default if the model parameter is
|
||||
omitted)</li>
|
||||
<li>model DS1822 with family id 22</li>
|
||||
<li>model DS18B20 with family id 28</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<code><id></code>
|
||||
<br />12-character unique ROM id of the thermometer device without family id and
|
||||
CRC code </li>
|
||||
<li>
|
||||
<code><interval></code>
|
||||
<br /> Temperature measurement interval in seconds. The default is 300 seconds. </li>
|
||||
<br /> Example: <br />
|
||||
<code>define Temp1 OWTHERM 14B598010800 300 </code><br />
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWTHERMset">
|
||||
<b>Set</b></a>
|
||||
<ul>
|
||||
<li><a name="owtherm_interval">
|
||||
<code>set <name> interval <int></code></a><br /> Temperature
|
||||
measurement intervall in seconds. The default is 300 seconds.</li>
|
||||
<li><a name="owtherm_tempHigh">
|
||||
<code>set <name> tempHigh <float></code></a>
|
||||
<br /> The high alarm temperature (on the temperature scale chosen by the
|
||||
attribute value) </li>
|
||||
<li><a name="owtherm_tempLow">
|
||||
<code>set <name> tempLow <float></code></a>
|
||||
<br /> The low alarm temperature (on the temperature scale chosen by the
|
||||
attribute value) </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWTHERMget">
|
||||
<b>Get</b></a>
|
||||
<ul>
|
||||
<li><a name="owtherm_id">
|
||||
<code>get <name> id</code></a>
|
||||
<br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
|
||||
<li><a name="owtherm_present">
|
||||
<code>get <name> present</code></a>
|
||||
<br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
|
||||
<li><a name="owtherm_interval2">
|
||||
<code>get <name> interval</code></a><br />Returns temperature
|
||||
measurement interval in seconds.</li>
|
||||
<li><a name="owtherm_temperature">
|
||||
<code>get <name> temperature</code></a><br />Obtain the temperature. </li>
|
||||
<li><a name="owtherm_alarm">
|
||||
<code>get <name> alarm</code></a><br />Obtain the alarm temperature
|
||||
values. </li>
|
||||
</ul>
|
||||
<br />
|
||||
<a name="OWTHERMattr">
|
||||
<b>Attributes</b></a>
|
||||
<ul>
|
||||
<li><a name="owtherm_stateAL"><code>attr <name> stateAL <string></code>
|
||||
</a>
|
||||
<br />character string for denoting low alarm condition, default is red down
|
||||
triangle, e.g. the code <span style="color:red">&#x25BE;</span>
|
||||
leading to the sign <span style="color:red">▾</span>
|
||||
</li>
|
||||
<li><a name="owtherm_stateAH"><code>attr <name> stateAH <string></code>
|
||||
</a>
|
||||
<br />character string for denoting high alarm condition, default is red upward
|
||||
triangle, e.g. the code <span style="color:red">&#x25B4;</span>
|
||||
leading to the sign <span style="color:red">▴</span>
|
||||
</li>
|
||||
<li><a name="owtherm_tempOffset"><code>attr <name> tempOffset
|
||||
<float></code>
|
||||
</a>
|
||||
<br />temperature offset in °C added to the raw temperature reading. </li>
|
||||
<li><a name="owtherm_tempUnit"><code>attr <name> tempUnit
|
||||
Celsius|Kelvin|Fahrenheit|C|K|F</code>
|
||||
</a>
|
||||
<br />unit of measurement (temperature scale), default is Celsius = °C </li>
|
||||
<li><a name="owtherm_tempHigh2">
|
||||
<code>attr <name> tempHigh <float></code>
|
||||
</a>
|
||||
<br /> high alarm temperature (on the temperature scale chosen by the attribute
|
||||
value). </li>
|
||||
<li><a name="owtherm_tempLow2">
|
||||
<code>attr <name> tempLow <float></code>
|
||||
</a>
|
||||
<br /> low alarm temperature (on the temperature scale chosen by the attribute
|
||||
value). </li>
|
||||
<li><a name="owtherm_event"><code>attr <name> event on-change|on-update
|
||||
</code></a>This attribte work similarly, but not identically to the standard event-on-update-change/event-on-update-reading attribute.
|
||||
<ul><li><code>event on-update</code> (default) will write a notify/FileLog event any time a measurement is received.</li>
|
||||
<li><code>event on-change</code> will write a notify/FileLog event only when a measurement is different from the previous one.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Standard attributes alias, comment, <a href="#eventMap">eventMap</a>, <a href="#loglevel">loglevel</a>, <a href="#webCmd">webCmd</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user