mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
82_M232Voltage by Boris
git-svn-id: https://svn.fhem.de/fhem/trunk@133 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
2190c5ba47
commit
99a1a793de
@ -367,7 +367,8 @@
|
|||||||
- feature: HMS100CO (by Peter)
|
- feature: HMS100CO (by Peter)
|
||||||
- feature: EMGZ (by Peter)
|
- feature: EMGZ (by Peter)
|
||||||
- feature: Generate warning if too many commands were sent in the last hour
|
- feature: Generate warning if too many commands were sent in the last hour
|
||||||
- doc: linux.html: Introduction (Peter S.)
|
- doc: linux.html: Introduction (Peter S.)
|
||||||
|
- feature: contrib/82_M232Voltage.pm (by Boris, 24.12)
|
||||||
|
|
||||||
- TODO
|
- TODO
|
||||||
emem -2.5kW / getDevData for emwz -1
|
emem -2.5kW / getDevData for emwz -1
|
||||||
|
@ -22,7 +22,7 @@ M232_Initialize($)
|
|||||||
|
|
||||||
# Provider
|
# Provider
|
||||||
$hash->{WriteFn} = "M232_Write";
|
$hash->{WriteFn} = "M232_Write";
|
||||||
$hash->{Clients} = ":M232Counter:";
|
$hash->{Clients} = ":M232Counter:M232Voltage:";
|
||||||
|
|
||||||
# Consumer
|
# Consumer
|
||||||
$hash->{DefFn} = "M232_Define";
|
$hash->{DefFn} = "M232_Define";
|
||||||
|
116
fhem/FHEM/82_M232Voltage.pm
Normal file
116
fhem/FHEM/82_M232Voltage.pm
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
#
|
||||||
|
#
|
||||||
|
# 82_M232Voltage.pm
|
||||||
|
# written by Dr. Boris Neubert 2007-12-24
|
||||||
|
# e-mail: omega at online dot de
|
||||||
|
#
|
||||||
|
##############################################
|
||||||
|
package main;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
|
||||||
|
sub M232Voltage_Get($@);
|
||||||
|
sub M232Voltage_Define($$);
|
||||||
|
sub M232Voltage_GetStatus($);
|
||||||
|
|
||||||
|
###################################
|
||||||
|
sub
|
||||||
|
M232Voltage_Initialize($)
|
||||||
|
{
|
||||||
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
$hash->{GetFn} = "M232Voltage_Get";
|
||||||
|
$hash->{DefFn} = "M232Voltage_Define";
|
||||||
|
|
||||||
|
$hash->{AttrList} = "dummy:1,0 model;M232Voltage loglevel:0,1,2,3,4,5";
|
||||||
|
}
|
||||||
|
|
||||||
|
###################################
|
||||||
|
sub
|
||||||
|
M232Voltage_GetStatus($)
|
||||||
|
{
|
||||||
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
if(!$hash->{LOCAL}) {
|
||||||
|
InternalTimer(gettimeofday()+60, "M232Voltage_GetStatus", $hash, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $d = IOWrite($hash, "a" . $hash->{INPUT});
|
||||||
|
if(!defined($d)) {
|
||||||
|
my $msg = "M232Voltage $name read error";
|
||||||
|
Log GetLogLevel($name,2), $msg;
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $tn = TimeNow();
|
||||||
|
my $value= (hex substr($d,0,3))*5.00/1024.0 * $hash->{FACTOR};
|
||||||
|
|
||||||
|
$hash->{READINGS}{value}{TIME} = $tn;
|
||||||
|
$hash->{READINGS}{value}{VAL} = $value;
|
||||||
|
|
||||||
|
$hash->{CHANGED}[0]= "value: $value";
|
||||||
|
|
||||||
|
if(!$hash->{LOCAL}) {
|
||||||
|
DoTrigger($name, undef) if($init_done);
|
||||||
|
}
|
||||||
|
|
||||||
|
$hash->{STATE} = $value;
|
||||||
|
Log GetLogLevel($name,4), "M232Voltage $name: $value $hash->{UNIT}";
|
||||||
|
|
||||||
|
return $hash->{STATE};
|
||||||
|
}
|
||||||
|
|
||||||
|
###################################
|
||||||
|
sub
|
||||||
|
M232Voltage_Get($@)
|
||||||
|
{
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
|
return "argument is missing" if(int(@a) != 2);
|
||||||
|
|
||||||
|
my $msg;
|
||||||
|
|
||||||
|
if($a[1] ne "status") {
|
||||||
|
return "unknown get value, valid is status";
|
||||||
|
}
|
||||||
|
$hash->{LOCAL} = 1;
|
||||||
|
my $v = M232Voltage_GetStatus($hash);
|
||||||
|
delete $hash->{LOCAL};
|
||||||
|
|
||||||
|
return "$a[0] $a[1] => $v";
|
||||||
|
}
|
||||||
|
|
||||||
|
#############################
|
||||||
|
sub
|
||||||
|
M232Voltage_Define($$)
|
||||||
|
{
|
||||||
|
my ($hash, $def) = @_;
|
||||||
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
|
return "syntax: define <name> M232Voltage an0..an5 [unit [factor]]"
|
||||||
|
if(int(@a) < 3 && int(@a) > 5);
|
||||||
|
|
||||||
|
my $reading= $a[2];
|
||||||
|
return "$reading is not an analog input, valid: an0..an5"
|
||||||
|
if($reading !~ /^an[0-5]$/) ;
|
||||||
|
|
||||||
|
my $unit= ((int(@a) > 3) ? $a[3] : "volts");
|
||||||
|
my $factor= ((int(@a) > 4) ? $a[4] : 1.0);
|
||||||
|
|
||||||
|
$hash->{INPUT}= substr($reading,2);
|
||||||
|
$hash->{UNIT}= $unit;
|
||||||
|
$hash->{FACTOR}= $factor;
|
||||||
|
|
||||||
|
AssignIoPort($hash);
|
||||||
|
|
||||||
|
if(!$hash->{LOCAL}) {
|
||||||
|
InternalTimer(gettimeofday()+60, "M232Voltage_GetStatus", $hash, 0);
|
||||||
|
}
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -822,6 +822,29 @@ split in multiple lines<br><br>
|
|||||||
<br>
|
<br>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<a name="M232Voltage"></a>
|
||||||
|
<h4>Type M232Voltage</h4>
|
||||||
|
<ul>
|
||||||
|
<code>define <name> M232Voltage [an0..an5] [unit [factor]]</code>
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
Define as many M232Voltages as you like for a M232 device. Defining a
|
||||||
|
M232Voltage will schedule an internal task, which reads the status of the
|
||||||
|
analog input every minute, and triggers notify/filelog commands.
|
||||||
|
<code>unit</code> is the unit name, <code>factor</code> is used to
|
||||||
|
calibrate the reading of the analog input.<br><br>
|
||||||
|
|
||||||
|
Note: the unit defaults to the string "volts", but it must be specified
|
||||||
|
if you wish to set the factor, which defaults to 1.0. <br><br>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
<ul>
|
||||||
|
<code>define volt M232Voltage an0</code><br>
|
||||||
|
<code>define brightness M232Voltage an5 lx 200.0</code><br>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
<a name="SCIVT"></a>
|
<a name="SCIVT"></a>
|
||||||
<h4>Type SCIVT</h4>
|
<h4>Type SCIVT</h4>
|
||||||
|
Loading…
Reference in New Issue
Block a user