mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-19 18:56:03 +00:00
EseraOneWire: initial commit with logical modules EseraAnalogInOut EseraDigitalInOut EseraMulti EseraTemp EseraCount EseraIButton
git-svn-id: https://svn.fhem.de/fhem/trunk@20592 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7e86772328
commit
848efb5d42
@ -1,6 +1,13 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
|
||||
- new: 66_EseraAnalogInOut.pm: new modul
|
||||
- new: 66_EseraDigitalInOut.pm: new modul
|
||||
- new: 66_EseraMulti.pm: new modul
|
||||
- new: 66_EseraTemp.pm: new modul
|
||||
- new: 66_EseraCount.pm: new modul
|
||||
- new: 66_EseraIButton.pm: new modul
|
||||
- new: 66_EseraOneWire.pm: new modul
|
||||
- feature: 70_SolarEdgeAPI: new readings from storageData API, overview API
|
||||
- bugfix: 73_ElectricityCalculator.pm: floating number flutter corrected
|
||||
- bugfix: 73_GasCalculator.pm: floating number flutter corrected
|
||||
|
596
fhem/FHEM/66_EseraAnalogInOut.pm
Normal file
596
fhem/FHEM/66_EseraAnalogInOut.pm
Normal file
@ -0,0 +1,596 @@
|
||||
################################################################################
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 66_EseraAnalogInOut.pm
|
||||
#
|
||||
# Copyright (C) 2018 pizmus
|
||||
#
|
||||
# This program 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This FHEM module controls analog input/output devices connected via
|
||||
# an Esera 1-wire controller and the 66_EseraOneWire module.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use SetExtensions;
|
||||
|
||||
my %SYS3Specs = (
|
||||
factor => 0.01, # factor to get from raw reading to value in given unit
|
||||
unit => "V",
|
||||
lowLimit => 0.0,
|
||||
highLimit => 10.0,
|
||||
defaultValue => 0.0
|
||||
);
|
||||
|
||||
my %DS2450Specs = (
|
||||
factor => 0.01, # factor to get from raw reading to value in given unit
|
||||
unit => "V",
|
||||
lowLimit => 0.0,
|
||||
highLimit => 0.0,
|
||||
defaultValue => 0.0
|
||||
);
|
||||
|
||||
my %Esera11202Specs = (
|
||||
factor => 0.01, # factor to get from raw reading to value in given unit
|
||||
unit => "V",
|
||||
lowLimit => 0.0,
|
||||
highLimit => 0.0,
|
||||
defaultValue => 0.0
|
||||
);
|
||||
|
||||
my %Esera11203Specs = (
|
||||
factor => 0.01, # factor to get from raw reading to value in given unit
|
||||
unit => "V",
|
||||
lowLimit => 0.0,
|
||||
highLimit => 0.0,
|
||||
defaultValue => 0.0
|
||||
);
|
||||
|
||||
my %Esera11208Specs = (
|
||||
factor => 0.01, # factor to get from raw reading to value in given unit
|
||||
unit => "V",
|
||||
lowLimit => 0.0,
|
||||
highLimit => 10.0,
|
||||
defaultValue => 0.0
|
||||
);
|
||||
|
||||
my %Esera11219Specs = (
|
||||
factor => 0.01, # factor to get from raw reading to value in given unit
|
||||
unit => "mA",
|
||||
lowLimit => 0.0,
|
||||
highLimit => 20.0,
|
||||
defaultValue => 0.0
|
||||
);
|
||||
|
||||
my %EseraAnalogInOutSpecs = (
|
||||
"SYS3" => \%SYS3Specs,
|
||||
"DS2450" => \%DS2450Specs,
|
||||
"11202" => \%Esera11202Specs,
|
||||
"11203" => \%Esera11203Specs,
|
||||
"11208" => \%Esera11208Specs,
|
||||
"11219" => \%Esera11219Specs
|
||||
);
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{Match} = "SYS3|DS2450|11202|11203|11208|11219";
|
||||
$hash->{DefFn} = "EseraAnalogInOut_Define";
|
||||
$hash->{UndefFn} = "EseraAnalogInOut_Undef";
|
||||
$hash->{ParseFn} = "EseraAnalogInOut_Parse";
|
||||
$hash->{SetFn} = "EseraAnalogInOut_Set";
|
||||
$hash->{GetFn} = "EseraAnalogInOut_Get";
|
||||
$hash->{AttrFn} = "EseraAnalogInOut_Attr";
|
||||
$hash->{AttrList} = "LowValue HighValue ".$readingFnAttributes;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split( "[ \t][ \t]*", $def);
|
||||
|
||||
my $usage = "Usage: define <name> EseraAnalogInOut <physicalDevice> <1-wire-ID> <deviceType> <lowLimit|-> <highLimit|->";
|
||||
|
||||
return $usage if(@a < 7);
|
||||
|
||||
my $devName = $a[0];
|
||||
my $type = $a[1];
|
||||
my $physicalDevice = $a[2];
|
||||
my $oneWireId = $a[3];
|
||||
my $deviceType = uc($a[4]);
|
||||
my $lowLimit = $a[5];
|
||||
my $highLimit = $a[6];
|
||||
|
||||
$hash->{STATE} = 'Initialized';
|
||||
$hash->{NAME} = $devName;
|
||||
$hash->{TYPE} = $type;
|
||||
$hash->{ONEWIREID} = $oneWireId;
|
||||
$hash->{ESERAID} = undef; # We will get this from the first reading.
|
||||
$hash->{DEVICE_TYPE} = $deviceType;
|
||||
|
||||
$modules{EseraAnalogInOut}{defptr}{$oneWireId} = $hash;
|
||||
|
||||
AssignIoPort($hash, $physicalDevice);
|
||||
|
||||
if (defined($hash->{IODev}->{NAME}))
|
||||
{
|
||||
Log3 $devName, 4, "EseraAnalogInOut ($devName) - I/O device is " . $hash->{IODev}->{NAME};
|
||||
}
|
||||
else
|
||||
{
|
||||
Log3 $devName, 1, "EseraAnalogInOut ($devName) - no I/O device";
|
||||
return $usage;
|
||||
}
|
||||
|
||||
# check and use LowLimit and HighLimit
|
||||
if (!defined($EseraAnalogInOutSpecs{$deviceType}))
|
||||
{
|
||||
Log3 $devName, 1, "EseraAnalogInOut ($devName) - unknown device type".$deviceType;
|
||||
return $usage;
|
||||
}
|
||||
|
||||
if (($lowLimit eq "-") || ($lowLimit < $EseraAnalogInOutSpecs{$deviceType}->{lowLimit}))
|
||||
{
|
||||
$lowLimit = $EseraAnalogInOutSpecs{$deviceType}->{lowLimit};
|
||||
}
|
||||
if (($highLimit eq "-") || ($highLimit > $EseraAnalogInOutSpecs{$deviceType}->{highLimit}))
|
||||
{
|
||||
$highLimit = $EseraAnalogInOutSpecs{$deviceType}->{highLimit};
|
||||
}
|
||||
$hash->{LOW_LIMIT} = $lowLimit;
|
||||
$hash->{HIGH_LIMIT} = $highLimit;
|
||||
|
||||
# program the the device type into the controller via the physical module
|
||||
if ($deviceType =~ m/^DS([0-9A-F]+)/)
|
||||
{
|
||||
# for the DS* devices types the "DS" has to be omitted
|
||||
IOWrite($hash, "assign;$oneWireId;$1");
|
||||
}
|
||||
elsif (!($deviceType =~ m/^SYS3/))
|
||||
{
|
||||
IOWrite($hash, "assign;$oneWireId;$deviceType");
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
delete( $modules{EseraAnalogInOut}{defptr}{$oneWireId} );
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_Get($@)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_setSysDigout($$$)
|
||||
{
|
||||
my ($hash, $owId, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if (($value < $hash->{LOW_LIMIT}) || ($value > $hash->{HIGH_LIMIT}))
|
||||
{
|
||||
my $message = "error: value out of range ".$value." ".$hash->{LOW_LIMIT}." ".$hash->{HIGH_LIMIT};
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# look up the ESERA ID
|
||||
my $eseraId = $hash->{ESERAID};
|
||||
if (!defined $eseraId)
|
||||
{
|
||||
my $message = "error: ESERA ID not known";
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# set value
|
||||
my $command = "set,sys,outa,".int($value / $EseraAnalogInOutSpecs{SYS3}->{factor});
|
||||
IOWrite($hash, "set;$owId;$command");
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_set11208Digout($$$)
|
||||
{
|
||||
my ($hash, $owId, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if (($value < $hash->{LOW_LIMIT}) || ($value > $hash->{HIGH_LIMIT}))
|
||||
{
|
||||
my $message = "error: value out of range ".$value." ".$hash->{LOW_LIMIT}." ".$hash->{HIGH_LIMIT};
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# look up the ESERA ID
|
||||
my $eseraId = $hash->{ESERAID};
|
||||
if (!defined $eseraId)
|
||||
{
|
||||
my $message = "error: ESERA ID not known";
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# set value
|
||||
# SET,OWD,OUTA,OWD-Nummer,Ausgangsspannung
|
||||
my $command = "set,owd,outa,".$eseraId.",".int($value / $EseraAnalogInOutSpecs{$hash->{DEVICE_TYPE}}->{factor});
|
||||
IOWrite($hash, "set;$owId;$command");
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_set11219Digout($$$)
|
||||
{
|
||||
my ($hash, $owId, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if (($value < $hash->{LOW_LIMIT}) || ($value > $hash->{HIGH_LIMIT}))
|
||||
{
|
||||
my $message = "error: value out of range ".$value." ".$hash->{LOW_LIMIT}." ".$hash->{HIGH_LIMIT};
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# look up the ESERA ID
|
||||
my $eseraId = $hash->{ESERAID};
|
||||
if (!defined $eseraId)
|
||||
{
|
||||
my $message = "error: ESERA ID not known";
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# set value
|
||||
# SET,OWD,OUTAMA,OWD-Nummer,Ausgangsstrom
|
||||
my $command = "set,owd,outama,".$eseraId.",".int($value / $EseraAnalogInOutSpecs{$hash->{DEVICE_TYPE}}->{factor});
|
||||
IOWrite($hash, "set;$owId;$command");
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_setOutput($$$)
|
||||
{
|
||||
my ($hash, $oneWireId, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if (!defined $hash->{DEVICE_TYPE})
|
||||
{
|
||||
my $message = "error: device type not known";
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
if ($hash->{DEVICE_TYPE} eq "SYS3")
|
||||
{
|
||||
Log3 $name, 5, "EseraAnalogInOut ($name) - EseraAnalogInOut_setOutput SYS3 value: $value";
|
||||
EseraAnalogInOut_setSysDigout($hash, $oneWireId, $value);
|
||||
}
|
||||
elsif ($hash->{DEVICE_TYPE} eq "11208")
|
||||
{
|
||||
Log3 $name, 5, "EseraAnalogInOut ($name) - EseraAnalogInOut_setOutput value: $value";
|
||||
EseraAnalogInOut_set11208Digout($hash, $oneWireId, $value);
|
||||
}
|
||||
elsif ($hash->{DEVICE_TYPE} eq "11219")
|
||||
{
|
||||
Log3 $name, 5, "EseraAnalogInOut ($name) - EseraAnalogInOut_setOutput value: $value";
|
||||
EseraAnalogInOut_set11219Digout($hash, $oneWireId, $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
my $message = "error: device type not supported as analog output: ".$hash->{DEVICE_TYPE};
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_Set($$)
|
||||
{
|
||||
my ( $hash, @parameters ) = @_;
|
||||
my $name = $parameters[0];
|
||||
my $what = lc($parameters[1]);
|
||||
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
my $iodev = $hash->{IODev}->{NAME};
|
||||
|
||||
my $commands = ("on off out");
|
||||
|
||||
if ($what eq "out")
|
||||
{
|
||||
if ((scalar(@parameters) != 3))
|
||||
{
|
||||
my $message = "error: unexpected number of parameters (".scalar(@parameters).")";
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
my $value = $parameters[2];
|
||||
EseraAnalogInOut_setOutput($hash, $oneWireId, $value);
|
||||
$hash->{LAST_OUT} = undef;
|
||||
}
|
||||
elsif ($what eq "on")
|
||||
{
|
||||
if ((scalar(@parameters) != 2))
|
||||
{
|
||||
my $message = "error: unexpected number of parameters (".scalar(@parameters).")";
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
my $value = AttrVal($name, "HighValue", $EseraAnalogInOutSpecs{$hash->{DEVICE_TYPE}}->{defaultValue});
|
||||
EseraAnalogInOut_setOutput($hash, $oneWireId, $value);
|
||||
$hash->{LAST_OUT} = 1;
|
||||
}
|
||||
elsif ($what eq "off")
|
||||
{
|
||||
if ((scalar(@parameters) != 2))
|
||||
{
|
||||
my $message = "error: unexpected number of parameters (".scalar(@parameters).")";
|
||||
Log3 $name, 1, "EseraAnalogInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
my $value = AttrVal($name, "LowValue", $EseraAnalogInOutSpecs{$hash->{DEVICE_TYPE}}->{defaultValue});
|
||||
EseraAnalogInOut_setOutput($hash, $oneWireId, $value);
|
||||
$hash->{LAST_OUT} = 0;
|
||||
}
|
||||
elsif ($what eq "?")
|
||||
{
|
||||
my $message = "unknown argument $what, choose one of $commands";
|
||||
return $message;
|
||||
}
|
||||
else
|
||||
{
|
||||
shift @parameters;
|
||||
shift @parameters;
|
||||
return SetExtensions($hash, $commands, $name, $what, @parameters);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_ParseForOneDevice($$$$$$)
|
||||
{
|
||||
my ($rhash, $deviceType, $oneWireId, $eseraId, $readingId, $value) = @_;
|
||||
my $rname = $rhash->{NAME};
|
||||
Log3 $rname, 4, "EseraAnalogInOut ($rname) - ParseForOneDevice: ".$rname;
|
||||
|
||||
# capture the Esera ID for later use
|
||||
$rhash->{ESERAID} = $eseraId;
|
||||
|
||||
# consistency check of device type
|
||||
if (!($rhash->{DEVICE_TYPE} eq uc($deviceType)))
|
||||
{
|
||||
Log3 $rname, 1, "EseraAnalogInOut ($rname) - unexpected device type ".$deviceType;
|
||||
|
||||
# program the the device type into the controller via the physical module
|
||||
if ($rhash->{DEVICE_TYPE} =~ m/^DS([0-9A-F]+)/)
|
||||
{
|
||||
# for the DS* devices types the "DS" has to be omitted
|
||||
IOWrite($rhash, "assign;$oneWireId;$1");
|
||||
}
|
||||
elsif (!($rhash->{DEVICE_TYPE} =~ m/^SYS3/))
|
||||
{
|
||||
IOWrite($rhash, "assign;$oneWireId;".$rhash->{DEVICE_TYPE});
|
||||
}
|
||||
}
|
||||
|
||||
if ($readingId eq "ERROR")
|
||||
{
|
||||
Log3 $rname, 1, "EseraAnalogInOut ($rname) - error message from physical device: ".$value;
|
||||
}
|
||||
elsif ($readingId eq "STATISTIC")
|
||||
{
|
||||
Log3 $rname, 1, "EseraAnalogInOut ($rname) - statistics message not supported yet: ".$value;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $nameOfReading = "";
|
||||
if (($deviceType eq "SYS3") || ($deviceType eq "11208") || ($deviceType eq "11219"))
|
||||
{
|
||||
if ($readingId == 0)
|
||||
{
|
||||
$nameOfReading .= "out";
|
||||
my $readingValue = $value * $EseraAnalogInOutSpecs{$deviceType}->{factor};
|
||||
my $reading = $readingValue." ".$EseraAnalogInOutSpecs{$deviceType}->{unit};
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $reading, 1);
|
||||
}
|
||||
}
|
||||
elsif (($deviceType eq "DS2450") || ($deviceType eq "11202") || ($deviceType eq "11203"))
|
||||
{
|
||||
if (($readingId >=1) && ($readingId <=4))
|
||||
{
|
||||
$nameOfReading .= "in".$readingId;
|
||||
my $readingValue = $value * $EseraAnalogInOutSpecs{$deviceType}->{factor};
|
||||
my $reading = $readingValue." ".$EseraAnalogInOutSpecs{$deviceType}->{unit};
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $reading, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rname;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_Parse($$)
|
||||
{
|
||||
my ($ioHash, $msg) = @_;
|
||||
my $ioName = $ioHash->{NAME};
|
||||
my $buffer = $msg;
|
||||
|
||||
# expected message format: $deviceType."_".$oneWireId."_".$eseraId."_".$readingId."_".$value
|
||||
my @fields = split(/_/, $buffer);
|
||||
if (scalar(@fields) != 5)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
my $deviceType = uc($fields[0]);
|
||||
my $oneWireId = $fields[1];
|
||||
my $eseraId = $fields[2];
|
||||
my $readingId = $fields[3];
|
||||
my $value = $fields[4];
|
||||
|
||||
# search for logical device
|
||||
my $rhash = undef;
|
||||
my @list;
|
||||
foreach my $d (keys %defs)
|
||||
{
|
||||
my $h = $defs{$d};
|
||||
my $type = $h->{TYPE};
|
||||
|
||||
if($type eq "EseraAnalogInOut")
|
||||
{
|
||||
if (defined($h->{IODev}->{NAME}))
|
||||
{
|
||||
my $ioDev = $h->{IODev}->{NAME};
|
||||
my $def = $h->{DEF};
|
||||
|
||||
# $def has the whole definition, extract the oneWireId (which is expected as 2nd parameter)
|
||||
my @parts = split(/ /, $def);
|
||||
my $oneWireIdFromDef = $parts[1];
|
||||
|
||||
if (($ioDev eq $ioName) && ($oneWireIdFromDef eq $oneWireId))
|
||||
{
|
||||
$rhash = $h;
|
||||
my $rname = EseraAnalogInOut_ParseForOneDevice($rhash, $deviceType, $oneWireId, $eseraId, $readingId, $value);
|
||||
push(@list, $rname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((scalar @list) > 0)
|
||||
{
|
||||
return @list;
|
||||
}
|
||||
elsif (exists($EseraAnalogInOutSpecs{$deviceType}))
|
||||
{
|
||||
return "UNDEFINED EseraAnalogInOut_".$ioName."_".$oneWireId." EseraAnalogInOut ".$ioName." ".$oneWireId." ".$deviceType." - -";
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraAnalogInOut_Attr(@)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=item summary Represents a 1-wire analog input/output.
|
||||
=item summary_DE Repraesentiert einen 1-wire analogen Eingang/Ausgang.
|
||||
=begin html
|
||||
|
||||
<a name="EseraAnalogInOut"></a>
|
||||
<h3>EseraAnalogInOut</h3>
|
||||
|
||||
<ul>
|
||||
This module implements a 1-wire analog input/output. It uses 66_EseraOneWire <br>
|
||||
as I/O device.<br>
|
||||
<br>
|
||||
|
||||
<a name="EseraAnalogInOut_Define"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> EseraAnalogInOut <ioDevice> <oneWireId> <deviceType> <lowLimit> <highLimit></code><br>
|
||||
<oneWireId> specifies the 1-wire ID of the analog input/output chip.<br>
|
||||
Use the "get devices" query of EseraOneWire to get a list of 1-wire IDs, <br>
|
||||
or simply rely on autocreate.<br>
|
||||
Supported values for deviceType:
|
||||
<ul>
|
||||
<li>SYS3 (analog output build into the Esera Controller 2, Note: This does not show up in the "get devices" response.)</li>
|
||||
<li>DS2450 (4x analog input)</li>
|
||||
<li>11202 (4x analog input)</li>
|
||||
<li>11203 (4x analog input)</li>
|
||||
<li>11208 (analog output, voltage)</li>
|
||||
<li>11219 (analog output, current)</li>
|
||||
</ul>
|
||||
This module knows the high and low limits of the supported devices. You might<br>
|
||||
want to further reduce the output range, e.g. to protect hardware connected to the <br>
|
||||
output from user errors. You can use the parameters <lowLimit> and <highLimit> to do<br>
|
||||
so. You can also give "-" for <lowLimit> and <highLimit>. In this case the module uses<br>
|
||||
the maximum possible output range.<br>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraAnalogInOut_Set"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
This applies to analog outputs only.
|
||||
<li>
|
||||
<b><code>set <name> out <value></code><br></b>
|
||||
Controls the analog output. <value> specifies the new value.<br>
|
||||
</li>
|
||||
<li>
|
||||
<b><code>set <name> on</code><br></b>
|
||||
Switch output to "high" value. The on value has to be specified as attribute HighValue.<br>
|
||||
</li>
|
||||
<li>
|
||||
<b><code>set <name> off</code><br></b>
|
||||
Switch output to "low" value. The on value has to be specified as attribute LowValue.<br>
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraAnalogInOut_Get"></a>
|
||||
<b>Get</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraAnalogInOut_Attr"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>LowValue (see above)</li>
|
||||
<li>HighValue (see above)</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraAnalogInOut_Readings"></a>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>in – analog input value</li>
|
||||
<li>out – analog output value</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
460
fhem/FHEM/66_EseraCount.pm
Normal file
460
fhem/FHEM/66_EseraCount.pm
Normal file
@ -0,0 +1,460 @@
|
||||
################################################################################
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 66_EseraCount.pm
|
||||
#
|
||||
# Copyright (C) 2019 pizmus
|
||||
#
|
||||
# This program 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This FHEM module supports DS2423 counters.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use SetExtensions;
|
||||
|
||||
sub
|
||||
EseraCount_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{Match} = "DS2423";
|
||||
$hash->{DefFn} = "EseraCount_Define";
|
||||
$hash->{UndefFn} = "EseraCount_Undef";
|
||||
$hash->{ParseFn} = "EseraCount_Parse";
|
||||
$hash->{SetFn} = "EseraCount_Set";
|
||||
$hash->{GetFn} = "EseraCount_Get";
|
||||
$hash->{AttrFn} = "EseraCount_Attr";
|
||||
$hash->{AttrList} = "ticksPerUnit1 ticksPerUnit2 movingAverageFactor1 movingAverageFactor2 movingAverageCount1 movingAverageCount2 $readingFnAttributes";
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split( "[ \t][ \t]*", $def);
|
||||
|
||||
return "Usage: define <name> EseraCount <physicalDevice> <1-wire-ID> <deviceType>" if(@a < 5);
|
||||
|
||||
my $devName = $a[0];
|
||||
my $type = $a[1];
|
||||
my $physicalDevice = $a[2];
|
||||
my $oneWireId = $a[3];
|
||||
my $deviceType = uc($a[4]);
|
||||
|
||||
$hash->{STATE} = 'Initialized';
|
||||
$hash->{NAME} = $devName;
|
||||
$hash->{TYPE} = $type;
|
||||
$hash->{ONEWIREID} = $oneWireId;
|
||||
$hash->{ESERAID} = undef; # We will get this from the first reading.
|
||||
$hash->{DEVICE_TYPE} = $deviceType;
|
||||
$hash->{DATE_OF_LAST_SAMPLE} = undef;
|
||||
$hash->{START_VALUE_OF_DAY_1} = 0;
|
||||
$hash->{START_VALUE_OF_DAY_2} = 0;
|
||||
$hash->{LAST_VALUE_1} = 0;
|
||||
$hash->{LAST_VALUE_2} = 0;
|
||||
|
||||
$modules{EseraCount}{defptr}{$oneWireId} = $hash;
|
||||
|
||||
AssignIoPort($hash, $physicalDevice);
|
||||
|
||||
if (defined($hash->{IODev}->{NAME}))
|
||||
{
|
||||
Log3 $devName, 4, "$devName: I/O device is " . $hash->{IODev}->{NAME};
|
||||
}
|
||||
else
|
||||
{
|
||||
Log3 $devName, 1, "$devName: no I/O device";
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
delete( $modules{EseraCount}{defptr}{$oneWireId} );
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_Get($@)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_Set($$)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_IsNewDay($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
my $timestamp = FmtDateTime(gettimeofday());
|
||||
# example: 2016-02-16 19:34:24
|
||||
|
||||
if ($timestamp =~ m/^([0-9\-]+)\s/)
|
||||
{
|
||||
my $dateString = $1;
|
||||
|
||||
if (defined $hash->{DATE_OF_LAST_SAMPLE})
|
||||
{
|
||||
if (!($hash->{DATE_OF_LAST_SAMPLE} eq $dateString))
|
||||
{
|
||||
$hash->{DATE_OF_LAST_SAMPLE} = $dateString;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$hash->{DATE_OF_LAST_SAMPLE} = $dateString;
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_MovingAverage($$$$)
|
||||
{
|
||||
my ($hash, $newValue, $averageCount, $channel) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Log3 $name, 5, "EseraCount ($name): averageCount $averageCount newValue $newValue";
|
||||
|
||||
# get array with the last samples
|
||||
my @lastSamples;
|
||||
my $ref;
|
||||
if ($channel == 1)
|
||||
{
|
||||
$ref = $hash->{LAST_VALUES_1};
|
||||
}
|
||||
else
|
||||
{
|
||||
$ref = $hash->{LAST_VALUES_2};
|
||||
}
|
||||
if (defined $ref)
|
||||
{
|
||||
@lastSamples = @$ref;
|
||||
}
|
||||
else
|
||||
{
|
||||
@lastSamples = ();
|
||||
}
|
||||
|
||||
# add new sample to front of the list
|
||||
unshift(@lastSamples, $newValue);
|
||||
|
||||
# remove oldest sample if needed
|
||||
while ((scalar @lastSamples) > $averageCount)
|
||||
{
|
||||
pop @lastSamples;
|
||||
Log3 $name, 5, "EseraCount ($name): pop once";
|
||||
}
|
||||
|
||||
# store new array in $hash
|
||||
if ($channel == 1)
|
||||
{
|
||||
$hash->{LAST_VALUES_1} = \@lastSamples;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hash->{LAST_VALUES_2} = \@lastSamples;
|
||||
}
|
||||
|
||||
# calculate the average across the array
|
||||
my $count = 0;
|
||||
my $sum = 0;
|
||||
foreach (@lastSamples)
|
||||
{
|
||||
$count += 1;
|
||||
$sum += $_;
|
||||
Log3 $name, 5, "EseraCount ($name): count $count sum $sum value $_";
|
||||
}
|
||||
|
||||
return $sum / $count;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_Parse($$)
|
||||
{
|
||||
my ($ioHash, $msg) = @_;
|
||||
my $ioName = $ioHash->{NAME};
|
||||
my $buffer = $msg;
|
||||
|
||||
# expected message format: $deviceType."_".$oneWireId."_".$eseraId."_".$readingId."_".$value
|
||||
my @fields = split(/_/, $buffer);
|
||||
if (scalar(@fields) != 5)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
my $deviceType = uc($fields[0]);
|
||||
my $oneWireId = $fields[1];
|
||||
my $eseraId = $fields[2];
|
||||
my $readingId = $fields[3];
|
||||
my $value = $fields[4];
|
||||
|
||||
# search for logical device
|
||||
my $rhash = undef;
|
||||
foreach my $d (keys %defs) {
|
||||
my $h = $defs{$d};
|
||||
my $type = $h->{TYPE};
|
||||
|
||||
if($type eq "EseraCount")
|
||||
{
|
||||
if (defined($h->{IODev}->{NAME}))
|
||||
{
|
||||
my $ioDev = $h->{IODev}->{NAME};
|
||||
my $def = $h->{DEF};
|
||||
|
||||
# $def has the whole definition, extract the oneWireId (which is expected as 2nd parameter)
|
||||
my @parts = split(/ /, $def);
|
||||
my $oneWireIdFromDef = $parts[1];
|
||||
|
||||
if (($ioDev eq $ioName) && ($oneWireIdFromDef eq $oneWireId))
|
||||
{
|
||||
$rhash = $h;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($rhash) {
|
||||
my $rname = $rhash->{NAME};
|
||||
Log3 $rname, 4, "EseraCount ($rname) - parse - device found: ".$rname;
|
||||
|
||||
# capture the Esera ID for later use
|
||||
$rhash->{ESERAID} = $eseraId;
|
||||
|
||||
# consistency check of device type
|
||||
if (!($rhash->{DEVICE_TYPE} eq uc($deviceType)))
|
||||
{
|
||||
Log3 $rname, 1, "EseraCount ($rname) - unexpected device type ".$deviceType;
|
||||
}
|
||||
|
||||
if ($readingId eq "ERROR")
|
||||
{
|
||||
Log3 $rname, 1, "EseraCount ($rname) - error message from physical device: ".$value;
|
||||
}
|
||||
elsif ($readingId eq "STATISTIC")
|
||||
{
|
||||
Log3 $rname, 1, "EseraCount ($rname) - statistics message not supported yet: ".$value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($deviceType eq "DS2423")
|
||||
{
|
||||
if (EseraCount_IsNewDay($rhash))
|
||||
{
|
||||
$rhash->{START_VALUE_OF_DAY_1} = $rhash->{LAST_VALUE_1};
|
||||
$rhash->{START_VALUE_OF_DAY_2} = $rhash->{LAST_VALUE_2};
|
||||
}
|
||||
|
||||
if ($readingId == 1)
|
||||
{
|
||||
my $ticksPerUnit = AttrVal($rname, "ticksPerUnit1", 1.0);
|
||||
readingsSingleUpdate($rhash, "count1", ($value / $ticksPerUnit), 1);
|
||||
readingsSingleUpdate($rhash, "count1Today", ($value - $rhash->{START_VALUE_OF_DAY_1}) / $ticksPerUnit, 1);
|
||||
if (defined $rhash->{LAST_VALUE_1})
|
||||
{
|
||||
my $movingAverageFactor = AttrVal($rname, "movingAverageFactor1", 1.0);
|
||||
my $averageCount = AttrVal($rname, "movingAverageCount1", 1);
|
||||
my $movingAverage = ($value - $rhash->{LAST_VALUE_1});
|
||||
my $processedMovingAverage = EseraCount_MovingAverage($rhash, $movingAverage * $movingAverageFactor, $averageCount, 1);
|
||||
readingsSingleUpdate($rhash, "count1MovingAverage", $processedMovingAverage, 1);
|
||||
}
|
||||
$rhash->{LAST_VALUE_1} = $value;
|
||||
}
|
||||
elsif ($readingId == 2)
|
||||
{
|
||||
my $ticksPerUnit = AttrVal($rname, "ticksPerUnit2", 1.0);
|
||||
readingsSingleUpdate($rhash, "count2", ($value / $ticksPerUnit), 1);
|
||||
readingsSingleUpdate($rhash, "count2Today", ($value - $rhash->{START_VALUE_OF_DAY_2}) / $ticksPerUnit, 1);
|
||||
if (defined $rhash->{LAST_VALUE_2})
|
||||
{
|
||||
my $movingAverageFactor = AttrVal($rname, "movingAverageFactor2", 1.0);
|
||||
my $averageCount = AttrVal($rname, "movingAverageCount2", 1);
|
||||
my $movingAverage = ($value - $rhash->{LAST_VALUE_2});
|
||||
my $processedMovingAverage = EseraCount_MovingAverage($rhash, $movingAverage * $movingAverageFactor, $averageCount, 2);
|
||||
readingsSingleUpdate($rhash, "count2MovingAverage", $processedMovingAverage, 1);
|
||||
}
|
||||
$rhash->{LAST_VALUE_2} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my @list;
|
||||
push(@list, $rname);
|
||||
return @list;
|
||||
}
|
||||
elsif ($deviceType eq "DS2423")
|
||||
{
|
||||
return "UNDEFINED EseraCount_".$ioName."_".$oneWireId." EseraCount ".$ioName." ".$oneWireId." ".$deviceType;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraCount_Attr($$$$)
|
||||
{
|
||||
my ($cmd, $name, $attrName, $attrValue) = @_;
|
||||
# $cmd - "del" or "set"
|
||||
# $name - device name
|
||||
# $attrName/$attrValue
|
||||
|
||||
if ($cmd eq "set") {
|
||||
if (($attrName eq "ticksPerUnit1") || ($attrName eq "ticksPerUnit2"))
|
||||
{
|
||||
if ($attrValue <= 0)
|
||||
{
|
||||
my $message = "illegal value for ticksPerUnit";
|
||||
Log3 $name, 3, "EseraCount ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
if (($attrName eq "movingAverageFactor1") || ($attrName eq "movingAverageFactor2"))
|
||||
{
|
||||
if ($attrValue <= 0)
|
||||
{
|
||||
my $message = "illegal value for movingAverageFactor";
|
||||
Log3 $name, 3, "EseraCount ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
if (($attrName eq "movingAverageCount1") || ($attrName eq "movingAverageCount2"))
|
||||
{
|
||||
if ($attrValue < 1)
|
||||
{
|
||||
my $message = "illegal value for movingAverageCount";
|
||||
Log3 $name, 3, "EseraCount ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=item summary Represents a DS2423 1-wire dual counter.
|
||||
=item summary_DE Repraesentiert einen DS2423 1-wire 2-fach Zaehler.
|
||||
=begin html
|
||||
|
||||
<a name="EseraCount"></a>
|
||||
<h3>EseraCount</h3>
|
||||
|
||||
<ul>
|
||||
This module supports DS2423 1-wire dual counters.<br>
|
||||
It uses 66_EseraOneWire as I/O device.<br>
|
||||
<br>
|
||||
|
||||
<a name="EseraCount_Define"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> EseraCount <ioDevice> <oneWireId> <deviceType></code><br>
|
||||
<oneWireId> specifies the 1-wire ID of the sensor. Use the "get devices" <br>
|
||||
query of EseraOneWire to get a list of 1-wire IDs, or simply rely on autocreate. <br>
|
||||
The only supported <deviceType> is DS2423.
|
||||
</ul>
|
||||
|
||||
<a name="EseraCount_Set"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraCount_Get"></a>
|
||||
<b>Get</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraCount_Attr"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>
|
||||
<code>ticksPerUnit1</code><br>
|
||||
<code>ticksPerUnit2</code><br>
|
||||
These attribute are applied to readings <code>count1</code> / <code>count2</code> and <br>
|
||||
<code>count1Today</code> / <code>count2Today</code>.<br>
|
||||
The default value is 1. The attribute is used to convert the raw<br>
|
||||
tick count to meaningful value with a unit.
|
||||
</li>
|
||||
<li>
|
||||
<code>movingAverageCount1</code><br>
|
||||
<code>movingAverageCount2</code><br>
|
||||
see description of reading <code>count1MovingAverage</code> and <code>count2MovingAverage</code><br>
|
||||
default: 1
|
||||
</li>
|
||||
<li>
|
||||
<code>movingAverageFactor1</code><br>
|
||||
<code>movingAverageFactor2</code><br>
|
||||
see description of reading <code>count1MovingAverage</code> and <code>count2MovingAverage</code><br>
|
||||
default: 1
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraCount_Readings"></a>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>
|
||||
<code>count1</code><br>
|
||||
<code>count2</code><br>
|
||||
The counter values for channel 1 and 2. These are the counter values with<br>
|
||||
attributes <code>ticksPerUnit1</code> and <code>ticksPerUnit2</code> applied.
|
||||
</li>
|
||||
<li>
|
||||
<code>count1Today</code><br>
|
||||
<code>count2Today</code><br>
|
||||
Similar to <code>count1</code> and <code>count2</code> but with a reset at midnight.
|
||||
</li>
|
||||
<li>
|
||||
<code>count1MovingAverage</code><br>
|
||||
<code>count2MovingAverage</code><br>
|
||||
Moving average of the last <code>movingAverageCount1</code> and <code>movingAverageCount2</code>samples, <br>
|
||||
multiplied with <code>movingAverageFactor1</code> or <code>movingAverageFactor2</code>. This reading and <br>
|
||||
the related attributes are used to derive a power value value from the S0 count of an <br>
|
||||
energy meter. Samples must have a fixed and known period. This is the case with the Esera 1-wire<br>
|
||||
controller. When selecting a value for <code>movingAverageFactor1</code> and <code>movingAverageFactor2</code> the sample <br>
|
||||
period has to be considered.<br>
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
726
fhem/FHEM/66_EseraDigitalInOut.pm
Normal file
726
fhem/FHEM/66_EseraDigitalInOut.pm
Normal file
@ -0,0 +1,726 @@
|
||||
################################################################################
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 66_EseraDigitalInOut.pm
|
||||
#
|
||||
# Copyright (C) 2018 pizmus
|
||||
#
|
||||
# This program 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This FHEM module controls a digital input and/or output device connected via
|
||||
# an Esera "1-wire Controller 1" with LAN interface and the 66_EseraOneWire
|
||||
# module.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use SetExtensions;
|
||||
|
||||
my %deviceSpecs = ("DS2408" => 8, "11220" => 8, "11228" => 8, "11229" => 8, "11216" => 8, "SYS1" => 4, "SYS2" => 5);
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{Match} = "DS2408";
|
||||
$hash->{DefFn} = "EseraDigitalInOut_Define";
|
||||
$hash->{UndefFn} = "EseraDigitalInOut_Undef";
|
||||
$hash->{ParseFn} = "EseraDigitalInOut_Parse";
|
||||
$hash->{SetFn} = "EseraDigitalInOut_Set";
|
||||
$hash->{GetFn} = "EseraDigitalInOut_Get";
|
||||
$hash->{AttrFn} = "EseraDigitalInOut_Attr";
|
||||
$hash->{AttrList} = "$readingFnAttributes";
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_calculateBits($$$$)
|
||||
{
|
||||
my ($hash, $deviceType, $rawBitPos, $rawBitCount) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $maxBitCount = $deviceSpecs{$deviceType};
|
||||
|
||||
if (!defined $maxBitCount)
|
||||
{
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - error looking up maximum bit width";
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $bitPos = 0;
|
||||
|
||||
if (!($rawBitPos eq "-"))
|
||||
{
|
||||
if (($rawBitPos >= 0) && ($rawBitPos < $maxBitCount))
|
||||
{
|
||||
$bitPos = $rawBitPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - specified bit field position is out of range";
|
||||
}
|
||||
}
|
||||
$hash->{BITPOS} = $bitPos;
|
||||
|
||||
my $bitCount = $maxBitCount - $bitPos;
|
||||
if (!($rawBitCount eq "-"))
|
||||
{
|
||||
if ($rawBitCount > $bitCount)
|
||||
{
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - specified bit field size is out of range";
|
||||
}
|
||||
else
|
||||
{
|
||||
$bitCount = $rawBitCount;
|
||||
}
|
||||
}
|
||||
$hash->{BITCOUNT} = $bitCount;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split( "[ \t][ \t]*", $def);
|
||||
|
||||
return "Usage: define <name> EseraDigitalInOut <physicalDevice> <1-wire-ID> <deviceType> (<bitPos>|-) (<bitCount>|-)" if(@a < 7);
|
||||
|
||||
my $devName = $a[0];
|
||||
my $type = $a[1];
|
||||
my $physicalDevice = $a[2];
|
||||
my $oneWireId = $a[3];
|
||||
my $deviceType = uc($a[4]);
|
||||
my $bitPos = $a[5];
|
||||
my $bitCount = $a[6];
|
||||
|
||||
$hash->{STATE} = 'Initialized';
|
||||
$hash->{NAME} = $devName;
|
||||
$hash->{TYPE} = $type;
|
||||
$hash->{ONEWIREID} = $oneWireId;
|
||||
$hash->{ESERAID} = undef; # We will get this from the first reading.
|
||||
$hash->{DEVICE_TYPE} = $deviceType;
|
||||
|
||||
my $success = EseraDigitalInOut_calculateBits($hash, $deviceType, $bitPos, $bitCount);
|
||||
if (!$success)
|
||||
{
|
||||
Log3 $devName, 1, "EseraDigitalInOut ($devName) - definition failed";
|
||||
return undef;
|
||||
}
|
||||
|
||||
$modules{EseraDigitalInOut}{defptr}{$oneWireId} = $hash;
|
||||
|
||||
AssignIoPort($hash, $physicalDevice);
|
||||
|
||||
if (defined($hash->{IODev}->{NAME}))
|
||||
{
|
||||
Log3 $devName, 4, "EseraDigitalInOut ($devName) - I/O device is " . $hash->{IODev}->{NAME};
|
||||
}
|
||||
else
|
||||
{
|
||||
Log3 $devName, 1, "EseraDigitalInOut ($devName) - no I/O device";
|
||||
}
|
||||
|
||||
# program the the device type into the controller via the physical module
|
||||
if ($deviceType =~ m/^DS([0-9A-F]+)/)
|
||||
{
|
||||
# for the DS* devices types the "DS" has to be omitted
|
||||
IOWrite($hash, "assign;$oneWireId;$1");
|
||||
}
|
||||
elsif (!($deviceType =~ m/^SYS[12]/))
|
||||
{
|
||||
IOWrite($hash, "assign;$oneWireId;$deviceType");
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
delete( $modules{EseraDigitalInOut}{defptr}{$oneWireId} );
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_Get($@)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_setDS2408digout($$$$)
|
||||
{
|
||||
my ($hash, $owId, $mask, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if ($mask < 1)
|
||||
{
|
||||
my $message = "error: at least one mask bit must be set, mask ".$mask.", value ".$value;
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
if ($mask > 255)
|
||||
{
|
||||
my $message = "error: mask is out of range";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
if (($value < 0) || ($value > 255))
|
||||
{
|
||||
my $message = "error: value out of range";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# look up the ESERA ID
|
||||
my $eseraId = $hash->{ESERAID};
|
||||
if (!defined $eseraId)
|
||||
{
|
||||
my $message = "error: ESERA ID not known";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# set values as given by mask and value
|
||||
if ($mask == 255)
|
||||
{
|
||||
# all bits are selected, use command to set all bits
|
||||
my $command = "set,owd,outh,".$eseraId.",".$value;
|
||||
IOWrite($hash, "set;$owId;$command");
|
||||
return undef;
|
||||
}
|
||||
else
|
||||
{
|
||||
# a subset of bits is selected, iterate over selected bits
|
||||
my $i;
|
||||
for ($i=0; $i<8; $i++)
|
||||
{
|
||||
if ($mask & 0x1)
|
||||
{
|
||||
my $bitValue = $value & 0x1;
|
||||
my $command = "set,owd,out,".$eseraId.",".$i.",".$bitValue;
|
||||
IOWrite($hash, "set;$owId;$command");
|
||||
}
|
||||
$mask = $mask >> 1;
|
||||
$value = $value >> 1;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_setSysDigout($$$$)
|
||||
{
|
||||
my ($hash, $owId, $mask, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if ($mask < 1)
|
||||
{
|
||||
my $message = "error: at least one mask bit must be set, mask ".$mask.", value ".$value;
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
if ($mask > 31)
|
||||
{
|
||||
my $message = "error: mask is out of range";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
if (($value < 0) || ($value > 31))
|
||||
{
|
||||
my $message = "error: value out of range";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# look up the ESERA ID
|
||||
my $eseraId = $hash->{ESERAID};
|
||||
if (!defined $eseraId)
|
||||
{
|
||||
my $message = "error: ESERA ID not known";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
# set values as given by mask and value
|
||||
if ($mask == 31)
|
||||
{
|
||||
# all bits are selected, use command to set all bits
|
||||
my $command = "set,sys,outh,".$value;
|
||||
IOWrite($hash, "set;$owId;$command");
|
||||
return undef;
|
||||
}
|
||||
else
|
||||
{
|
||||
# a subset of bits is selected, iterate over selected bits
|
||||
my $i;
|
||||
for ($i=0; $i<8; $i++)
|
||||
{
|
||||
if ($mask & 0x1)
|
||||
{
|
||||
my $bitValue = $value & 0x1;
|
||||
my $command = "set,sys,out,".($i+1).",".$bitValue;
|
||||
IOWrite($hash, "set;$owId;$command");
|
||||
}
|
||||
$mask = $mask >> 1;
|
||||
$value = $value >> 1;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_calculateBitMasksForSet($$$)
|
||||
{
|
||||
my ($hash, $mask, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $maxMask = (2**($hash->{BITCOUNT})) - 1;
|
||||
|
||||
my $adjustedMask = ($mask & $maxMask) << $hash->{BITPOS};
|
||||
my $adjustedValue = ($value & $maxMask) << $hash->{BITPOS};
|
||||
|
||||
return ($adjustedMask, $adjustedValue);
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_setOutput($$$$)
|
||||
{
|
||||
my ($hash, $oneWireId, $mask, $value) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Log3 $name, 5, "EseraDigitalInOut ($name) - EseraDigitalInOut_setOutput inputs: $oneWireId,$mask,$value";
|
||||
|
||||
if (!defined $hash->{DEVICE_TYPE})
|
||||
{
|
||||
my $message = "error: device type not known";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
if (($hash->{DEVICE_TYPE} eq "DS2408") ||
|
||||
($hash->{DEVICE_TYPE} eq "11220") ||
|
||||
($hash->{DEVICE_TYPE} eq "11228") ||
|
||||
($hash->{DEVICE_TYPE} eq "11229"))
|
||||
{
|
||||
my ($adjustedMask, $adjustedValue) = EseraDigitalInOut_calculateBitMasksForSet($hash, $mask, $value);
|
||||
|
||||
Log3 $name, 5, "EseraDigitalInOut ($name) - EseraDigitalInOut_setOutput DS2408 adjustedMask: $adjustedMask, adjustedValue: $adjustedValue";
|
||||
EseraDigitalInOut_setDS2408digout($hash, $oneWireId, $adjustedMask, $adjustedValue);
|
||||
}
|
||||
elsif ($hash->{DEVICE_TYPE} eq "SYS2")
|
||||
{
|
||||
my ($adjustedMask, $adjustedValue) = EseraDigitalInOut_calculateBitMasksForSet($hash, $mask, $value);
|
||||
|
||||
Log3 $name, 5, "EseraDigitalInOut ($name) - EseraDigitalInOut_setOutput SYS2 adjustedMask: $adjustedMask, adjustedValue: $adjustedValue";
|
||||
EseraDigitalInOut_setSysDigout($hash, $oneWireId, $adjustedMask, $adjustedValue);
|
||||
}
|
||||
elsif (($hash->{DEVICE_TYPE} eq "11216") || ($hash->{DEVICE_TYPE} eq "SYS1"))
|
||||
{
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - error: trying to set digital output but this device only has inputs";
|
||||
}
|
||||
else
|
||||
{
|
||||
my $message = "error: device type not supported: ".$hash->{DEVICE_TYPE};
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
# interpret a string entered by the user as a number
|
||||
sub
|
||||
EseraDigitalInOut_convertNumber($$)
|
||||
{
|
||||
my ($hash, $numberString) = @_;
|
||||
$numberString = lc($numberString);
|
||||
my $number = undef;
|
||||
if ($numberString =~ m/^(\d+)$/)
|
||||
{
|
||||
$number = $1;
|
||||
}
|
||||
elsif (($numberString =~ m/^0b([01]+)$/) || ($numberString =~ m/^0x([a-f0-9]+)$/))
|
||||
{
|
||||
$number = oct($numberString);
|
||||
}
|
||||
return $number;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_Set($$)
|
||||
{
|
||||
my ( $hash, @parameters ) = @_;
|
||||
my $name = $parameters[0];
|
||||
my $what = lc($parameters[1]);
|
||||
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
my $iodev = $hash->{IODev}->{NAME};
|
||||
|
||||
my $commands = ("on:noArg off:noArg out");
|
||||
|
||||
if ($what eq "out")
|
||||
{
|
||||
if ((scalar(@parameters) != 4))
|
||||
{
|
||||
my $message = "error: unexpected number of parameters (".scalar(@parameters).")";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
my $mask = EseraDigitalInOut_convertNumber($hash, $parameters[2]);
|
||||
my $value = EseraDigitalInOut_convertNumber($hash, $parameters[3]);
|
||||
EseraDigitalInOut_setOutput($hash, $oneWireId, $mask, $value);
|
||||
$hash->{LAST_OUT} = undef;
|
||||
}
|
||||
elsif ($what eq "on")
|
||||
{
|
||||
if ((scalar(@parameters) != 2))
|
||||
{
|
||||
my $message = "error: unexpected number of parameters (".scalar(@parameters).")";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
EseraDigitalInOut_setOutput($hash, $oneWireId, 0xFFFFFFFF, 0xFFFFFFFF);
|
||||
$hash->{LAST_OUT} = 1;
|
||||
}
|
||||
elsif ($what eq "off")
|
||||
{
|
||||
if ((scalar(@parameters) != 2))
|
||||
{
|
||||
my $message = "error: unexpected number of parameters (".scalar(@parameters).")";
|
||||
Log3 $name, 1, "EseraDigitalInOut ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
EseraDigitalInOut_setOutput($hash, $oneWireId, 0xFFFFFFFF, 0x00000000);
|
||||
$hash->{LAST_OUT} = 0;
|
||||
}
|
||||
elsif ($what eq "?")
|
||||
{
|
||||
my $message = "unknown argument $what, choose one of $commands";
|
||||
return $message;
|
||||
}
|
||||
else
|
||||
{
|
||||
shift @parameters;
|
||||
shift @parameters;
|
||||
return SetExtensions($hash, $commands, $name, $what, @parameters);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_getReadingValue($$$)
|
||||
{
|
||||
my ($value, $bitPos, $bitCount) = @_;
|
||||
|
||||
# The controller sends digital output state as binary mask (without leading 0b)
|
||||
my ($decimalValue) = oct("0b".$value);
|
||||
|
||||
return ($decimalValue >> $bitPos) & ((2**$bitCount)-1);
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_ParseForOneDevice($$$$$$)
|
||||
{
|
||||
my ($rhash, $deviceType, $oneWireId, $eseraId, $readingId, $value) = @_;
|
||||
my $rname = $rhash->{NAME};
|
||||
Log3 $rname, 4, "EseraDigitalInOut ($rname) - ParseForOneDevice: ".$rname;
|
||||
|
||||
# capture the Esera ID for later use
|
||||
$rhash->{ESERAID} = $eseraId;
|
||||
|
||||
# consistency check of device type
|
||||
if (!($rhash->{DEVICE_TYPE} eq uc($deviceType)))
|
||||
{
|
||||
Log3 $rname, 1, "EseraDigitalInOut ($rname) - unexpected device type ".$deviceType;
|
||||
|
||||
# program the the device type into the controller via the physical module
|
||||
if ($rhash->{DEVICE_TYPE} =~ m/^DS([0-9A-F]+)/)
|
||||
{
|
||||
# for the DS* devices types the "DS" has to be omitted
|
||||
IOWrite($rhash, "assign;$oneWireId;$1");
|
||||
}
|
||||
elsif (!($deviceType =~ m/^SYS[12]/))
|
||||
{
|
||||
IOWrite($rhash, "assign;$oneWireId;".$rhash->{DEVICE_TYPE});
|
||||
}
|
||||
}
|
||||
|
||||
if ($readingId eq "ERROR")
|
||||
{
|
||||
Log3 $rname, 1, "EseraDigitalInOut ($rname) - error message from physical device: ".$value;
|
||||
}
|
||||
elsif ($readingId eq "STATISTIC")
|
||||
{
|
||||
Log3 $rname, 1, "EseraDigitalInOut ($rname) - statistics message not supported yet: ".$value;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $nameOfReading;
|
||||
if ($deviceType eq "DS2408")
|
||||
{
|
||||
if ($readingId == 2)
|
||||
{
|
||||
$nameOfReading = "in";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
elsif ($readingId == 4)
|
||||
{
|
||||
$nameOfReading = "out";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
}
|
||||
elsif (($deviceType eq "11220") || ($deviceType eq "11228")) # 8 channel digital output with push buttons
|
||||
{
|
||||
if ($readingId == 2)
|
||||
{
|
||||
$nameOfReading = "in";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
if ($readingId == 4)
|
||||
{
|
||||
$nameOfReading = "out";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
}
|
||||
elsif ($deviceType eq "11229") # 8 channel digital output
|
||||
{
|
||||
if ($readingId == 4)
|
||||
{
|
||||
$nameOfReading = "out";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
}
|
||||
elsif ($deviceType eq "11216") # 8 channel digital input
|
||||
{
|
||||
if ($readingId == 2)
|
||||
{
|
||||
$nameOfReading = "in";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
}
|
||||
elsif ($deviceType eq "SYS2") # Controller 2 digital output
|
||||
{
|
||||
if ($readingId == 2)
|
||||
{
|
||||
$nameOfReading = "out";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
}
|
||||
elsif ($deviceType eq "SYS1") # Controller 2 digital input
|
||||
{
|
||||
if ($readingId == 2)
|
||||
{
|
||||
$nameOfReading = "in";
|
||||
my $readingValue = EseraDigitalInOut_getReadingValue($value, $rhash->{BITPOS}, $rhash->{BITCOUNT});
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $readingValue, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rname;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_Parse($$)
|
||||
{
|
||||
my ($ioHash, $msg) = @_;
|
||||
my $ioName = $ioHash->{NAME};
|
||||
my $buffer = $msg;
|
||||
|
||||
# expected message format: $deviceType."_".$oneWireId."_".$eseraId."_".$readingId."_".$value
|
||||
my @fields = split(/_/, $buffer);
|
||||
if (scalar(@fields) != 5)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
my $deviceType = uc($fields[0]);
|
||||
my $oneWireId = $fields[1];
|
||||
my $eseraId = $fields[2];
|
||||
my $readingId = $fields[3];
|
||||
my $value = $fields[4];
|
||||
|
||||
# search for logical device
|
||||
my $rhash = undef;
|
||||
my @list;
|
||||
foreach my $d (keys %defs)
|
||||
{
|
||||
my $h = $defs{$d};
|
||||
my $type = $h->{TYPE};
|
||||
|
||||
if($type eq "EseraDigitalInOut")
|
||||
{
|
||||
if (defined($h->{IODev}->{NAME}))
|
||||
{
|
||||
my $ioDev = $h->{IODev}->{NAME};
|
||||
my $def = $h->{DEF};
|
||||
|
||||
# $def has the whole definition, extract the oneWireId (which is expected as 2nd parameter)
|
||||
my @parts = split(/ /, $def);
|
||||
my $oneWireIdFromDef = $parts[1];
|
||||
|
||||
if (($ioDev eq $ioName) && ($oneWireIdFromDef eq $oneWireId))
|
||||
{
|
||||
$rhash = $h;
|
||||
my $rname = EseraDigitalInOut_ParseForOneDevice($rhash, $deviceType, $oneWireId, $eseraId, $readingId, $value);
|
||||
push(@list, $rname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((scalar @list) > 0)
|
||||
{
|
||||
return @list;
|
||||
}
|
||||
elsif (($deviceType eq "DS2408") or ($deviceType eq "11216") or
|
||||
($deviceType eq "11220") or
|
||||
($deviceType eq "11228") or ($deviceType eq "11229") or
|
||||
($deviceType eq "SYS1") or ($deviceType eq "SYS2"))
|
||||
{
|
||||
return "UNDEFINED EseraDigitalInOut_".$ioName."_".$oneWireId." EseraDigitalInOut ".$ioName." ".$oneWireId." ".$deviceType." - -";
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraDigitalInOut_Attr(@)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=item summary Represents a 1-wire digital input/output.
|
||||
=item summary_DE Repraesentiert einen 1-wire digitalen Eingang/Ausgang.
|
||||
=begin html
|
||||
|
||||
<a name="EseraDigitalInOut"></a>
|
||||
<h3>EseraDigitalInOut</h3>
|
||||
|
||||
<ul>
|
||||
This module implements a 1-wire digital input/output. It uses 66_EseraOneWire <br>
|
||||
as I/O device.<br>
|
||||
<br>
|
||||
|
||||
<a name="EseraDigitalInOut_Define"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> EseraDigitalInOut <ioDevice> <oneWireId> <deviceType> <bitPos> <bitCount></code><br>
|
||||
<oneWireId> specifies the 1-wire ID of the digital input/output chip.<br>
|
||||
Use the "get devices" query of EseraOneWire to get a list of 1-wire IDs, <br>
|
||||
or simply rely on autocreate.<br>
|
||||
Supported values for deviceType:
|
||||
<ul>
|
||||
<li>DS2408</li>
|
||||
<li>11220/11228 (Esera "Digital Out 8-Channel with push-button interface")</li>
|
||||
<li>11229 (Esera "Digital Out 8-Channel")</li>
|
||||
<li>11216 (Esera "8-Channel Digital Input DC")</li>
|
||||
<li>SYS1 (Esera Controller 2, digital input, not listed by "get devices")</li>
|
||||
<li>SYS2 (Esera Controller 2, digital output, not listed by "get devices")</li>
|
||||
</ul>
|
||||
The bitPos and bitCount parameters is used to specify a subset of bits only. <br>
|
||||
For example, the DS2408 has 8 inputs, and you can define a EseraDigitalInOut <br>
|
||||
that uses bits 4..7 (in range 0..7). In this case you specify bitPos = 4 and <br>
|
||||
bitWidth = 4.<br>
|
||||
You can also give "-" for bitPos and bitWidth. In this case the module uses<br>
|
||||
the maximum possible bit range, which is bitPos = 0 and bitWidth = 8 for DS2408.<br>
|
||||
In typical use cases the n bits of a digital input device are used to control <br>
|
||||
or observe n different things, e.g. 8 motion sensors connected to 8 digital inputs.<br>
|
||||
In this case you would define 8 EseraDigitalInOut devices, one for each motion sensor.<br>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraDigitalInOut_Set"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
<li>
|
||||
<b><code>set <name> out <bitMask> <bitValue></code><br></b>
|
||||
Controls digital outputs. The bitMask selects bits that are programmed, <br>
|
||||
and bitValue specifies the new value.<br>
|
||||
Examples: <code>set myEseraDigitalInOut out 0xf 0x3</code><br>
|
||||
In this example the four lower outputs are selected by the mask, <br>
|
||||
and they get the new value 0x3 = 0b0011.<br>
|
||||
bitMask and bitValue can be specified as hex number (0x...), binary<br>
|
||||
number (0b....) or decimal number.<br>
|
||||
Note: If all bits are selected by mask the outputs are set by a single <br>
|
||||
access to the controller. If subset of bits is selected the bits are set <br>
|
||||
by individual accesses, one after the other, as fast as the controller allows.<br>
|
||||
</li>
|
||||
<li>
|
||||
<b><code>set <name> on</code><br></b>
|
||||
Switch on all outputs.<br>
|
||||
</li>
|
||||
<li>
|
||||
<b><code>set <name> off</code><br></b>
|
||||
Switch off all outputs.<br>
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraDigitalInOut_Get"></a>
|
||||
<b>Get</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraDigitalInOut_Attr"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>no attributes</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraDigitalInOut_Readings"></a>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>in – digital input state</li>
|
||||
<li>out – digital output state</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
294
fhem/FHEM/66_EseraIButton.pm
Normal file
294
fhem/FHEM/66_EseraIButton.pm
Normal file
@ -0,0 +1,294 @@
|
||||
################################################################################
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 66_EseraIButton.pm
|
||||
#
|
||||
# Copyright (C) 2018 pizmus
|
||||
#
|
||||
# This program 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This FHEM module supports iButton devices connected via an Esera 1-wire Controller
|
||||
# and the 66_EseraOneWire module.
|
||||
# For more details please read the device specific help / commandref.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use SetExtensions;
|
||||
|
||||
sub
|
||||
EseraIButton_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{Match} = "DS2401";
|
||||
$hash->{DefFn} = "EseraIButton_Define";
|
||||
$hash->{UndefFn} = "EseraIButton_Undef";
|
||||
$hash->{ParseFn} = "EseraIButton_Parse";
|
||||
$hash->{SetFn} = "EseraIButton_Set";
|
||||
$hash->{GetFn} = "EseraIButton_Get";
|
||||
$hash->{AttrFn} = "EseraIButton_Attr";
|
||||
$hash->{AttrList} = "$readingFnAttributes";
|
||||
}
|
||||
|
||||
sub
|
||||
EseraIButton_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split( "[ \t][ \t]*", $def);
|
||||
|
||||
return "Usage: define <name> EseraIButton <physicalDevice> <1-wire-ID> <deviceType>" if(@a < 5);
|
||||
|
||||
my $devName = $a[0];
|
||||
my $type = $a[1];
|
||||
my $physicalDevice = $a[2];
|
||||
my $oneWireId = $a[3];
|
||||
my $deviceType = uc($a[4]);
|
||||
|
||||
$hash->{STATE} = 'Initialized';
|
||||
$hash->{NAME} = $devName;
|
||||
$hash->{TYPE} = $type;
|
||||
$hash->{ONEWIREID} = $oneWireId;
|
||||
$hash->{ESERAID} = undef; # We will get this from the first reading.
|
||||
$hash->{DEVICE_TYPE} = $deviceType;
|
||||
|
||||
$modules{EseraIButton}{defptr}{$oneWireId} = $hash;
|
||||
|
||||
AssignIoPort($hash, $physicalDevice);
|
||||
|
||||
if (defined($hash->{IODev}->{NAME}))
|
||||
{
|
||||
Log3 $devName, 4, "$devName: I/O device is " . $hash->{IODev}->{NAME};
|
||||
}
|
||||
else
|
||||
{
|
||||
Log3 $devName, 1, "$devName: no I/O device";
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraIButton_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
delete( $modules{EseraIButton}{defptr}{$oneWireId} );
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraIButton_Get($@)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraIButton_Set($$)
|
||||
{
|
||||
my ( $hash, @parameters ) = @_;
|
||||
my $name = $parameters[0];
|
||||
my $what = lc($parameters[1]);
|
||||
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
my $iodev = $hash->{IODev}->{NAME};
|
||||
|
||||
my $commands = ("statusRequest");
|
||||
|
||||
if ($what eq "statusRequest")
|
||||
{
|
||||
IOWrite($hash, "status;$oneWireId");
|
||||
}
|
||||
elsif ($what eq "?")
|
||||
{
|
||||
# TODO use the :noArg info
|
||||
my $message = "unknown argument $what, choose one of $commands";
|
||||
return $message;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $message = "unknown argument $what, choose one of $commands";
|
||||
Log3 $name, 1, "EseraIButton ($name) - ".$message;
|
||||
return $message;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraIButton_Parse($$)
|
||||
{
|
||||
my ($ioHash, $msg) = @_;
|
||||
my $ioName = $ioHash->{NAME};
|
||||
my $buffer = $msg;
|
||||
|
||||
# expected message format: $deviceType."_".$oneWireId."_".$eseraId."_".$readingId."_".$value
|
||||
my @fields = split(/_/, $buffer);
|
||||
if (scalar(@fields) != 5)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
my $deviceType = uc($fields[0]);
|
||||
my $oneWireId = $fields[1];
|
||||
my $eseraId = $fields[2];
|
||||
my $readingId = $fields[3];
|
||||
my $value = $fields[4];
|
||||
|
||||
# search for logical device
|
||||
my $rhash = undef;
|
||||
foreach my $d (keys %defs) {
|
||||
my $h = $defs{$d};
|
||||
my $type = $h->{TYPE};
|
||||
|
||||
if($type eq "EseraIButton")
|
||||
{
|
||||
if (defined($h->{IODev}->{NAME}))
|
||||
{
|
||||
my $ioDev = $h->{IODev}->{NAME};
|
||||
my $def = $h->{DEF};
|
||||
|
||||
# $def has the whole definition, extract the oneWireId (which is expected as 2nd parameter)
|
||||
my @parts = split(/ /, $def);
|
||||
my $oneWireIdFromDef = $parts[1];
|
||||
|
||||
if (($ioDev eq $ioName) && ($oneWireIdFromDef eq $oneWireId))
|
||||
{
|
||||
$rhash = $h;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($rhash) {
|
||||
my $rname = $rhash->{NAME};
|
||||
Log3 $rname, 4, "EseraIButton ($rname) - parse - device found: ".$rname;
|
||||
|
||||
# capture the Esera ID for later use
|
||||
$rhash->{ESERAID} = $eseraId;
|
||||
|
||||
# consistency check of device type
|
||||
if (!($rhash->{DEVICE_TYPE} eq uc($deviceType)))
|
||||
{
|
||||
Log3 $rname, 1, "EseraIButton ($rname) - unexpected device type ".$deviceType;
|
||||
}
|
||||
|
||||
if ($readingId eq "ERROR")
|
||||
{
|
||||
Log3 $rname, 1, "EseraIButton ($rname) - error message from physical device: ".$value;
|
||||
}
|
||||
elsif ($readingId eq "STATISTIC")
|
||||
{
|
||||
Log3 $rname, 1, "EseraIButton ($rname) - statistics message not supported yet: ".$value;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $nameOfReading = "status";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value, 1);
|
||||
}
|
||||
|
||||
my @list;
|
||||
push(@list, $rname);
|
||||
return @list;
|
||||
}
|
||||
elsif ($deviceType eq "DS2401") # TODO
|
||||
{
|
||||
return "UNDEFINED EseraIButton_".$ioName."_".$oneWireId." EseraIButton ".$ioName." ".$oneWireId." ".$deviceType;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraIButton_Attr(@)
|
||||
{
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=item summary Represents a 1-wire iButton device.
|
||||
=item summary_DE Repraesentiert einen 1-wire iButton.
|
||||
=begin html
|
||||
|
||||
<a name="EseraIButton"></a>
|
||||
<h3>EseraIButton</h3>
|
||||
|
||||
<ul>
|
||||
This module supports 1-wire iButton devices. It uses 66_EseraOneWire as I/O device.<br>
|
||||
Events are generated for connecting and disconnecting an iButton.<br>
|
||||
<br>
|
||||
The Esera Controller needs to know the iButton so that it can detect it quickly when it <br>
|
||||
is connected. The iButton needs to be in the list of devices which is stored in a non-volatile <br>
|
||||
memory in the controller. Initially, you need to connect a new iButton for ~10 seconds. Use the <br>
|
||||
"get devices" query of EseraOneWire to check whether the device has been detected. When it has <br>
|
||||
been detected use "set savelist" to store the current list in the controller. Repeat the same <br>
|
||||
procedure with additional iButtons. Alternatively, you can use the "Config Tool 3" software from <br>
|
||||
Esera to store iButton devices in the controller.<br>
|
||||
<br>
|
||||
It is stronly recommended to use the additional license "iButton Fast Mode" from Esera (product <br>
|
||||
number 40202). With this license the controller detects iButton devices quickly. Without that <br>
|
||||
license the controller sometimes needs quite long to detect an iButton. <br>
|
||||
<br>
|
||||
See the "Programmierhandbuch" from Esera for details.<br>
|
||||
<br>
|
||||
|
||||
<a name="EseraIButton_Define"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> EseraIButton <ioDevice> <oneWireId> <deviceType></code> <br>
|
||||
<oneWireId> specifies the 1-wire ID of the iButton.<br>
|
||||
Supported values for deviceType: DS2401<br>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraIButton_Set"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
<li>no set functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraIButton_Get"></a>
|
||||
<b>Get</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraIButton_Attr"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>no attributes</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraIButton_Readings"></a>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>status – connection status 0 or 1</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
351
fhem/FHEM/66_EseraMulti.pm
Normal file
351
fhem/FHEM/66_EseraMulti.pm
Normal file
@ -0,0 +1,351 @@
|
||||
################################################################################
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 66_EseraMulti.pm
|
||||
#
|
||||
# Copyright (C) 2018 pizmus
|
||||
#
|
||||
# This program 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This FHEM module supports an Esera multi sensor connected via
|
||||
# an Esera 1-wire Controller and the 66_EseraOneWire module.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use SetExtensions;
|
||||
|
||||
sub
|
||||
EseraMulti_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{Match} = "DS2438";
|
||||
$hash->{DefFn} = "EseraMulti_Define";
|
||||
$hash->{UndefFn} = "EseraMulti_Undef";
|
||||
$hash->{ParseFn} = "EseraMulti_Parse";
|
||||
$hash->{SetFn} = "EseraMulti_Set";
|
||||
$hash->{GetFn} = "EseraMulti_Get";
|
||||
$hash->{AttrFn} = "EseraMulti_Attr";
|
||||
$hash->{AttrList} = "$readingFnAttributes";
|
||||
}
|
||||
|
||||
sub
|
||||
EseraMulti_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split( "[ \t][ \t]*", $def);
|
||||
|
||||
return "Usage: define <name> EseraMulti <physicalDevice> <1-wire-ID> <deviceType>" if(@a < 5);
|
||||
|
||||
my $devName = $a[0];
|
||||
my $type = $a[1];
|
||||
my $physicalDevice = $a[2];
|
||||
my $oneWireId = $a[3];
|
||||
my $deviceType = uc($a[4]);
|
||||
|
||||
$hash->{STATE} = 'Initialized';
|
||||
$hash->{NAME} = $devName;
|
||||
$hash->{TYPE} = $type;
|
||||
$hash->{ONEWIREID} = $oneWireId;
|
||||
$hash->{ESERAID} = undef; # We will get this from the first reading.
|
||||
$hash->{DEVICE_TYPE} = $deviceType;
|
||||
|
||||
$modules{EseraMulti}{defptr}{$oneWireId} = $hash;
|
||||
|
||||
AssignIoPort($hash, $physicalDevice);
|
||||
|
||||
if (defined($hash->{IODev}->{NAME}))
|
||||
{
|
||||
Log3 $devName, 4, "$devName: I/O device is " . $hash->{IODev}->{NAME};
|
||||
}
|
||||
else
|
||||
{
|
||||
Log3 $devName, 1, "$devName: no I/O device";
|
||||
}
|
||||
|
||||
# program the the device type into the controller via the physical module
|
||||
if ($deviceType =~ m/^DS([0-9A-F]+)/)
|
||||
{
|
||||
# for the DS* devices types the "DS" has to be omitted
|
||||
IOWrite($hash, "assign;$oneWireId;$1");
|
||||
}
|
||||
else
|
||||
{
|
||||
IOWrite($hash, "assign;$oneWireId;$deviceType");
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraMulti_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
delete( $modules{EseraMulti}{defptr}{$oneWireId} );
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraMulti_Get($@)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraMulti_Set($$)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraMulti_Parse($$)
|
||||
{
|
||||
my ($ioHash, $msg) = @_;
|
||||
my $ioName = $ioHash->{NAME};
|
||||
my $buffer = $msg;
|
||||
|
||||
# expected message format: $deviceType."_".$oneWireId."_".$eseraId."_".$readingId."_".$value
|
||||
my @fields = split(/_/, $buffer);
|
||||
if (scalar(@fields) != 5)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
my $deviceType = uc($fields[0]);
|
||||
my $oneWireId = $fields[1];
|
||||
my $eseraId = $fields[2];
|
||||
my $readingId = $fields[3];
|
||||
my $value = $fields[4];
|
||||
|
||||
# search for logical device
|
||||
my $rhash = undef;
|
||||
foreach my $d (keys %defs) {
|
||||
my $h = $defs{$d};
|
||||
my $type = $h->{TYPE};
|
||||
|
||||
if($type eq "EseraMulti")
|
||||
{
|
||||
if (defined($h->{IODev}->{NAME}))
|
||||
{
|
||||
my $ioDev = $h->{IODev}->{NAME};
|
||||
my $def = $h->{DEF};
|
||||
|
||||
# $def has the whole definition, extract the oneWireId (which is expected as 2nd parameter)
|
||||
my @parts = split(/ /, $def);
|
||||
my $oneWireIdFromDef = $parts[1];
|
||||
|
||||
if (($ioDev eq $ioName) && ($oneWireIdFromDef eq $oneWireId))
|
||||
{
|
||||
$rhash = $h;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($rhash) {
|
||||
my $rname = $rhash->{NAME};
|
||||
Log3 $rname, 4, "EseraMulti ($rname) - parse - device found: ".$rname;
|
||||
|
||||
# capture the Esera ID for later use
|
||||
$rhash->{ESERAID} = $eseraId;
|
||||
|
||||
# consistency check of device type
|
||||
if (!($rhash->{DEVICE_TYPE} eq uc($deviceType)))
|
||||
{
|
||||
Log3 $rname, 1, "EseraMulti ($rname) - unexpected device type ".$deviceType;
|
||||
|
||||
# program the the device type into the controller via the physical module
|
||||
if ($rhash->{DEVICE_TYPE} =~ m/^DS([0-9A-F]+)/)
|
||||
{
|
||||
# for the DS* devices types the "DS" has to be omitted
|
||||
IOWrite($rhash, "assign;$oneWireId;$1");
|
||||
}
|
||||
else
|
||||
{
|
||||
IOWrite($rhash, "assign;$oneWireId;".$rhash->{DEVICE_TYPE});
|
||||
}
|
||||
}
|
||||
|
||||
if ($readingId eq "ERROR")
|
||||
{
|
||||
Log3 $rname, 1, "EseraMulti ($rname) - error message from physical device: ".$value;
|
||||
}
|
||||
elsif ($readingId eq "STATISTIC")
|
||||
{
|
||||
Log3 $rname, 1, "EseraMulti ($rname) - statistics message not supported yet: ".$value;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $nameOfReading;
|
||||
if ($deviceType eq "DS2438")
|
||||
{
|
||||
if ($readingId == 1)
|
||||
{
|
||||
$nameOfReading = "temperature";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
elsif ($readingId == 2)
|
||||
{
|
||||
$nameOfReading = "VCC";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
elsif ($readingId == 3)
|
||||
{
|
||||
$nameOfReading = "VAD";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
elsif ($readingId == 4)
|
||||
{
|
||||
$nameOfReading = "VSense";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100000.0, 1);
|
||||
}
|
||||
}
|
||||
elsif (($deviceType eq "11121") || ($deviceType eq "11132") || ($deviceType eq "11134") || ($deviceType eq "11135"))
|
||||
{
|
||||
if ($readingId == 1)
|
||||
{
|
||||
$nameOfReading = "temperature";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
elsif ($readingId == 2)
|
||||
{
|
||||
$nameOfReading = "voltage";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
elsif ($readingId == 3)
|
||||
{
|
||||
$nameOfReading = "humidity";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
elsif ($readingId == 4)
|
||||
{
|
||||
$nameOfReading = "dewpoint";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
elsif ($readingId == 5)
|
||||
{
|
||||
$nameOfReading = "brightness";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my @list;
|
||||
push(@list, $rname);
|
||||
return @list;
|
||||
}
|
||||
elsif (($deviceType eq "DS2438") || ($deviceType eq "11121") || ($deviceType eq "11132") || ($deviceType eq "11134") || ($deviceType eq "11135"))
|
||||
{
|
||||
return "UNDEFINED EseraMulti_".$ioName."_".$oneWireId." EseraMulti ".$ioName." ".$oneWireId." ".$deviceType;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraMulti_Attr(@)
|
||||
{
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=item summary Represents an Esera 1-wire multi sensor.
|
||||
=item summary_DE Repraesentiert einen Esera 1-wire Multi-Sensor.
|
||||
=begin html
|
||||
|
||||
<a name="EseraMulti"></a>
|
||||
<h3>EseraMulti</h3>
|
||||
|
||||
<ul>
|
||||
This module supports an Esera 1-wire multi sensor or a DS2438 1-wire IC.<br>
|
||||
It uses 66_EseraOneWire as I/O device.<br>
|
||||
<br>
|
||||
|
||||
<a name="EseraMulti_Define"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> EseraMulti <ioDevice> <oneWireId> <deviceType></code><br>
|
||||
<oneWireId> specifies the 1-wire ID of the sensor. Use the "get devices" <br>
|
||||
query of EseraOneWire to get a list of 1-wire IDs, or simply rely on autocreate. <br>
|
||||
Supported values for deviceType:
|
||||
<ul>
|
||||
<li>DS2438</li>
|
||||
<li>11121 (Esera product number)</li>
|
||||
<li>11132 (Esera product number, multi sensor Unterputz)</li>
|
||||
<li>11134 (Esera product number, multi sensor Aufputz)</li>
|
||||
<li>11135 (Esera product number, multi sensor Outdoor)</li>
|
||||
</ul>
|
||||
With deviceType DS2438 this device generates readings with un-interpreted data<br>
|
||||
from DS2438. This can be used with any DS2438 device, independent of an Esera <br>
|
||||
product. With deviceType 11121/11132/11134/11135 this module provides interpreted<br>
|
||||
readings like humidity or dew point.<br>
|
||||
</ul>
|
||||
|
||||
<a name="EseraMulti_Set"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraMulti_Get"></a>
|
||||
<b>Get</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraMulti_Attr"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>no attributes</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraMulti_Readings"></a>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
readings for DS2438:<br>
|
||||
<ul>
|
||||
<li>VAD</li>
|
||||
<li>VCC</li>
|
||||
<li>VSense</li>
|
||||
<li>temperature</li>
|
||||
</ul>
|
||||
readings for Esera 11121/11132/11134/11135:<br>
|
||||
<ul>
|
||||
<li>temperature</li>
|
||||
<li>humidity</li>
|
||||
<li>dewpoint</li>
|
||||
<li>brightness</li>
|
||||
<li>voltage</li>
|
||||
</ul>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
2221
fhem/FHEM/66_EseraOneWire.pm
Normal file
2221
fhem/FHEM/66_EseraOneWire.pm
Normal file
File diff suppressed because it is too large
Load Diff
260
fhem/FHEM/66_EseraTemp.pm
Normal file
260
fhem/FHEM/66_EseraTemp.pm
Normal file
@ -0,0 +1,260 @@
|
||||
################################################################################
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# 66_EseraTemp.pm
|
||||
#
|
||||
# Copyright (C) 2018 pizmus
|
||||
#
|
||||
# This program 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# This FHEM module supports a temperature sensor connected via
|
||||
# an Esera "1-wire Controller 1" with LAN interface and the 66_EseraOneWire
|
||||
# module.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use SetExtensions;
|
||||
|
||||
sub
|
||||
EseraTemp_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
$hash->{Match} = "DS1820";
|
||||
$hash->{DefFn} = "EseraTemp_Define";
|
||||
$hash->{UndefFn} = "EseraTemp_Undef";
|
||||
$hash->{ParseFn} = "EseraTemp_Parse";
|
||||
$hash->{SetFn} = "EseraTemp_Set";
|
||||
$hash->{GetFn} = "EseraTemp_Get";
|
||||
$hash->{AttrFn} = "EseraTemp_Attr";
|
||||
$hash->{AttrList} = "$readingFnAttributes";
|
||||
}
|
||||
|
||||
sub
|
||||
EseraTemp_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split( "[ \t][ \t]*", $def);
|
||||
|
||||
return "Usage: define <name> EseraTemp <physicalDevice> <1-wire-ID> <deviceType>" if(@a < 5);
|
||||
|
||||
my $devName = $a[0];
|
||||
my $type = $a[1];
|
||||
my $physicalDevice = $a[2];
|
||||
my $oneWireId = $a[3];
|
||||
my $deviceType = uc($a[4]);
|
||||
|
||||
$hash->{STATE} = 'Initialized';
|
||||
$hash->{NAME} = $devName;
|
||||
$hash->{TYPE} = $type;
|
||||
$hash->{ONEWIREID} = $oneWireId;
|
||||
$hash->{ESERAID} = undef; # We will get this from the first reading.
|
||||
$hash->{DEVICE_TYPE} = $deviceType;
|
||||
|
||||
$modules{EseraTemp}{defptr}{$oneWireId} = $hash;
|
||||
|
||||
AssignIoPort($hash, $physicalDevice);
|
||||
|
||||
if (defined($hash->{IODev}->{NAME}))
|
||||
{
|
||||
Log3 $devName, 4, "$devName: I/O device is " . $hash->{IODev}->{NAME};
|
||||
}
|
||||
else
|
||||
{
|
||||
Log3 $devName, 1, "$devName: no I/O device";
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraTemp_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $oneWireId = $hash->{ONEWIREID};
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
delete( $modules{EseraTemp}{defptr}{$oneWireId} );
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraTemp_Get($@)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraTemp_Set($$)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraTemp_Parse($$)
|
||||
{
|
||||
my ($ioHash, $msg) = @_;
|
||||
my $ioName = $ioHash->{NAME};
|
||||
my $buffer = $msg;
|
||||
|
||||
# expected message format: $deviceType."_".$oneWireId."_".$eseraId."_".$readingId."_".$value
|
||||
my @fields = split(/_/, $buffer);
|
||||
if (scalar(@fields) != 5)
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
my $deviceType = uc($fields[0]);
|
||||
my $oneWireId = $fields[1];
|
||||
my $eseraId = $fields[2];
|
||||
my $readingId = $fields[3];
|
||||
my $value = $fields[4];
|
||||
|
||||
# search for logical device
|
||||
my $rhash = undef;
|
||||
foreach my $d (keys %defs) {
|
||||
my $h = $defs{$d};
|
||||
my $type = $h->{TYPE};
|
||||
|
||||
if($type eq "EseraTemp")
|
||||
{
|
||||
if (defined($h->{IODev}->{NAME}))
|
||||
{
|
||||
my $ioDev = $h->{IODev}->{NAME};
|
||||
my $def = $h->{DEF};
|
||||
|
||||
# $def has the whole definition, extract the oneWireId (which is expected as 2nd parameter)
|
||||
my @parts = split(/ /, $def);
|
||||
my $oneWireIdFromDef = $parts[1];
|
||||
|
||||
if (($ioDev eq $ioName) && ($oneWireIdFromDef eq $oneWireId))
|
||||
{
|
||||
$rhash = $h;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($rhash) {
|
||||
my $rname = $rhash->{NAME};
|
||||
Log3 $rname, 4, "EseraTemp ($rname) - parse - device found: ".$rname;
|
||||
|
||||
# capture the Esera ID for later use
|
||||
$rhash->{ESERAID} = $eseraId;
|
||||
|
||||
# consistency check of device type
|
||||
if (!($rhash->{DEVICE_TYPE} eq uc($deviceType)))
|
||||
{
|
||||
Log3 $rname, 1, "EseraTemp ($rname) - unexpected device type ".$deviceType;
|
||||
}
|
||||
|
||||
if ($readingId eq "ERROR")
|
||||
{
|
||||
Log3 $rname, 1, "EseraTemp ($rname) - error message from physical device: ".$value;
|
||||
}
|
||||
elsif ($readingId eq "STATISTIC")
|
||||
{
|
||||
Log3 $rname, 1, "EseraTemp ($rname) - statistics message not supported yet: ".$value;
|
||||
}
|
||||
else
|
||||
{
|
||||
my $nameOfReading = "temperature";
|
||||
readingsSingleUpdate($rhash, $nameOfReading, $value / 100.0, 1);
|
||||
}
|
||||
|
||||
my @list;
|
||||
push(@list, $rname);
|
||||
return @list;
|
||||
}
|
||||
elsif ($deviceType eq "DS1820")
|
||||
{
|
||||
return "UNDEFINED EseraTemp_".$ioName."_".$oneWireId." EseraTemp ".$ioName." ".$oneWireId." ".$deviceType;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
EseraTemp_Attr(@)
|
||||
{
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=item summary Represents a 1-wire temperature sensor.
|
||||
=item summary_DE Repraesentiert einen 1-wire Temperatursensor.
|
||||
=begin html
|
||||
|
||||
<a name="EseraTemp"></a>
|
||||
<h3>EseraTemp</h3>
|
||||
|
||||
<ul>
|
||||
This module implements a 1-wire temperature sensor. It uses 66_EseraOneWire<br>
|
||||
as I/O device.<br>
|
||||
<br>
|
||||
|
||||
<a name="EseraTemp_Define"></a>
|
||||
<b>Define</b>
|
||||
<ul>
|
||||
<code>define <name> EseraTemp <ioDevice> <oneWireId> <deviceType></code> <br>
|
||||
<oneWireId> specifies the 1-wire ID of the sensor. Use the "get devices"<br>
|
||||
query of EseraOneWire to get a list of 1-wire IDs, or simply rely on autocreate.<br>
|
||||
Supported values for deviceType:<br>
|
||||
<ul>
|
||||
<li>DS1820</li>
|
||||
</ul>
|
||||
Note: Esera 11131 temperature sensor is a DS1820.
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraTemp_Set"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
<li>no set functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraTemp_Get"></a>
|
||||
<b>Get</b>
|
||||
<ul>
|
||||
<li>no get functionality</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraTemp_Attr"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>no attributes</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="EseraTemp_Readings"></a>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>temperature – temperature in degrees Celsius</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
@ -314,6 +314,13 @@ FHEM/62_EMEM.pm rudolfkoenig SlowRF
|
||||
FHEM/63_EMGZ.pm rudolfkoenig SlowRF
|
||||
FHEM/64_ESA2000.pm stromer-12 SlowRF
|
||||
FHEM/66_ECMD.pm neubert Sonstige Systeme
|
||||
FHEM/66_EseraAnalogInIout.pm pizmus 1Wire
|
||||
FHEM/66_EseraCount.pm pizmus 1Wire
|
||||
FHEM/66_EseraDigitalInOut.pm pizmus 1Wire
|
||||
FHEM/66_EseraIButton.pm pizmus 1Wire
|
||||
FHEM/66_EseraMulti.pm pizmus 1Wire
|
||||
FHEM/66_EseraOneWire.pm pizmus 1Wire
|
||||
FHEM/66_EseraTemp.pm pizmus 1Wire
|
||||
FHEM/67_ECMDDevice.pm neubert Sonstige Systeme
|
||||
FHEM/70_BOTVAC.pm vuffiraa Sonstige Systeme
|
||||
FHEM/70_BRAVIA.pm vuffiraa Multimedia
|
||||
|
Loading…
x
Reference in New Issue
Block a user