2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

10_IT: send EV1527 command for switch, change some log level

git-svn-id: https://svn.fhem.de/fhem/trunk@13196 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
bjoernh 2017-01-22 20:27:22 +00:00
parent 3d3708129a
commit 54a52520ec
2 changed files with 123 additions and 38 deletions

View File

@ -1,5 +1,6 @@
# 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.
- update: 10_IT: send EV1527 command for switch, change some log level
- change: 98_powerMap: default value for reading pM_power was renamed to
pM_consumption to circumvent overlapping of commonly
used reading 'power' where it is normally used as

View File

@ -13,6 +13,7 @@ package main;
use strict;
use warnings;
#use Data::Dumper qw(Dumper);
use SetExtensions;
@ -120,7 +121,7 @@ IT_Initialize($)
$hash->{UndefFn} = "IT_Undef";
$hash->{ParseFn} = "IT_Parse";
$hash->{AttrFn} = "IT_Attr";
$hash->{AttrList} = "IODev ITfrequency ITrepetition ITclock switch_rfmode:1,0 do_not_notify:1,0 ignore:0,1 protocol:V1,V3,HE_EU,SBC_FreeTec,HE800 unit group dummy:1,0 " .
$hash->{AttrList} = "IODev ITfrequency ITrepetition ITclock switch_rfmode:1,0 do_not_notify:1,0 ignore:0,1 protocol:V1,V3,HE_EU,SBC_FreeTec,HE800 SIGNALduinoProtocolId userV1setCodes unit group dummy:1,0 " .
"$readingFnAttributes " .
"model:".join(",", sort keys %models);
@ -182,6 +183,14 @@ IT_Set($@)
my $list = "";
$list .= "off:noArg on:noArg " if( AttrVal($name, "model", "") ne "itremote" );
if ($hash->{userV1setCodes}) {
if ($hash->{READINGS}{protocol}{VAL} eq "EV1527" || $hash->{READINGS}{protocol}{VAL} eq "V1") {
foreach my $setCode (keys %{$hash->{userV1setCodes}}) {
$list .= "$setCode:noArg ";
}
}
}
my $c = $it_c2b{$a[0]};
@ -222,9 +231,6 @@ IT_Set($@)
}
$list = (join(" ", sort keys %it_c2b) . " dim:slider,0,6.25,100")
if( AttrVal($name, "model", "") eq "itdimmer" );
} elsif ($hash->{READINGS}{protocol}{VAL} eq "EV1527") { # EV1527
#Log3 $hash, 2, "Set ignored for EV1527 (1527X) devices";
return "";
} elsif ($hash->{READINGS}{protocol}{VAL} eq "HE800") {
$c = $it_c2b_he800{$a[0]};
if($na > 1 && $a[0] eq "dim") {
@ -252,11 +258,16 @@ IT_Set($@)
my $io = $hash->{IODev};
my $v = $name ." ". join(" ", @a);
## Log that we are going to switch InterTechno
Log3 $hash, 2, "$io->{NAME} IT_set: $v";
Log3 $hash, 3, "$io->{NAME} IT_set: $v";
my (undef, $cmd) = split(" ", $v, 2); # Not interested in the name...
# Look for all devices with the same code, and set state, timestamp
my $code = "$hash->{XMIT}";
my $code;
if ($hash->{READINGS}{protocol}{VAL} eq "EV1527") { # beim EV1527 darf der code nicht aus dem $hash->{XMIT} geholt werden
$code = "$hash->{CODE}{1}";
} else {
$code = "$hash->{XMIT}";
}
foreach my $n (keys %{ $modules{IT}{defptr}{$code} }) {
my $lh = $modules{IT}{defptr}{$code}{$n};
@ -340,7 +351,7 @@ IT_Set($@)
#CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", $message));
$message = $attr{$name}{"ITclock"};
CallFn($io->{NAME}, "SetFn", $io, ($hash->{NAME}, "ITClock", $message));
Log3 $hash, 2, "IT set ITclock: $message for $io->{NAME}";
Log3 $hash, 3, "IT set ITclock: $message for $io->{NAME}";
}
## Do we need to change ITrepetition ??
@ -358,7 +369,7 @@ IT_Set($@)
my $f0 = sprintf("%02x", $f % 256);
my $arg = sprintf("%.3f", (hex($f2)*65536+hex($f1)*256+hex($f0))/65536*26);
Log3 $hash, 2, "Setting ITfrequency (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz";
Log3 $hash, 3, "Setting ITfrequency (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz";
CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", "if$f2$f1$f0"));
}
}
@ -545,7 +556,18 @@ IT_Set($@)
$message = "ish".uc($bin);
}
} else {
$message = "is".uc($hash->{XMIT}.$hash->{$c});
my $onoffcode;
if (defined($c)) {
$onoffcode = $hash->{$c};
} else {
if ($hash->{userV1setCodes}) {
$onoffcode = $hash->{userV1setCodes}{$a[0]};
}
}
if (length($onoffcode) == 4) { # EV1527
$onoffcode = $bintotristate{substr($onoffcode,0,2)} . $bintotristate{substr($onoffcode,2,2)};
}
$message = "is".uc($hash->{XMIT}.$onoffcode);
}
@ -563,7 +585,7 @@ IT_Set($@)
if(defined($attr{$name}) && defined($attr{$name}{"ITrepetition"})) {
$message = "isr".$it_defrepetition;
CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", $message));
Log3 $hash, 2, "IT set ITrepetition back: $message for $io->{NAME}";
Log3 $hash, 3, "IT set ITrepetition back: $message for $io->{NAME}";
}
## Do we need to change ITfrequency back??
@ -575,7 +597,7 @@ IT_Set($@)
## Do we need to change ITClock back??
if(defined($attr{$name}) && defined($attr{$name}{"ITclock"}))
{
Log3 $hash, 2, "Setting ITClock back to 420";
Log3 $hash, 3, "Setting ITClock back to 420";
#CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", "sic250"));
CallFn($io->{NAME}, "SetFn", $io, ($hash->{NAME}, "ITClock", "420"));
}
@ -591,20 +613,41 @@ IT_Set($@)
my $SignalRepeats = AttrVal($name,'ITrepetition', '6');
my $ITClock = AttrVal($name,'ITclock', undef);
my $f = AttrVal($name,'ITfrequency',undef);
my $ITfrequency = '';
my $protocolId;
if (defined($f)) {
$f = $f / 26 * 65536;
my $f2 = sprintf("%02x", $f / 65536);
my $f1 = sprintf("%02x", int($f % 65536) / 256);
my $f0 = sprintf("%02x", $f % 256);
my $arg = sprintf("%.3f", (hex($f2)*65536+hex($f1)*256+hex($f0))/65536*26);
Log3 $hash, 3, "$io->{NAME} IT_set: Setting ITfrequency (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz";
$ITfrequency = "#F$f2$f1$f0";
}
if (defined($ITClock)) {
$ITClock = '#C' . $ITClock;
} else {
$ITClock = '';
}
if ($hash->{READINGS}{protocol}{VAL} eq "V3") {
$protocolId = 'P17#';
$protocolId = AttrVal($name,'SIGNALduinoProtocolId', undef);
if (defined($protocolId)) {
$protocolId = 'P' . $protocolId . '#';
} else {
# IT V1
$protocolId = 'P3#';
if ($hash->{READINGS}{protocol}{VAL} eq "V3") {
$protocolId = 'P17#';
} else {
$protocolId = 'P3#'; # IT V1
}
}
Log3 $hash, 4, "$io->{NAME} IT_set: sendMsg=$protocolId" . substr($message,2) . '#R' . $SignalRepeats . $ITClock;
IOWrite($hash, 'sendMsg', $protocolId . substr($message,2) . '#R' . $SignalRepeats . $ITClock);
if ($hash->{READINGS}{protocol}{VAL} ne "EV1527" && $hash->{READINGS}{protocol}{VAL} ne "V1") { # bei ITv1 und EV1527 wird das "is" am Anfang nicht entfernt
$message = substr($message,2);
if (substr($message,0,1) eq "h") { # h entfernen falls am am Anfang
$message = substr($message,1);
}
}
Log3 $hash, 4, "$io->{NAME} IT_set: sendMsg=" . $protocolId . $message . '#R' . $SignalRepeats . $ITClock;
IOWrite($hash, 'sendMsg', $protocolId . $message . '#R' . $SignalRepeats . $ITClock . $ITfrequency);
}
return $ret;
}
@ -724,10 +767,22 @@ IT_Define($$)
# Is Protocol EV1527
#Log3 $hash,2,"ITdefine 1527: $name a3=" . $a[3];
$housecode = $a[2];
if (substr($housecode,0,4) eq '1527') {
my $evcode;
my $bincode = sprintf("%020b",hex(substr($housecode,5)));
for (my $n=0; $n<20; $n=$n+2) {
$evcode = $evcode . $bintotristate{substr($bincode,$n,2)};
}
$hash->{XMIT} = lc($evcode);
} else {
$hash->{XMIT} = lc($housecode);
}
return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
if ( ($a[3] !~ m/^[0-1]{4}$/i) );
return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
if ( ($a[4] !~ m/^[0-1]{4}$/i) );
$oncode = $a[3];
$oncode = '0000' if (length($a[3]) != 4);
$offcode = $a[4];
$offcode = '0000' if (length($a[4]) != 4);
$hash->{READINGS}{protocol}{VAL} = 'EV1527';
} elsif (length($a[2]) == 8) { # SBC, FreeTec
return "Define $a[0]: wrong IT-Code format: specify a 8 digits 0/1/f "
@ -755,25 +810,36 @@ IT_Define($$)
$hash->{READINGS}{protocol}{VAL} = 'V1';
}
$hash->{XMIT} = lc($housecode);
if ($hash->{READINGS}{protocol}{VAL} ne 'EV1527') {
$hash->{XMIT} = lc($housecode);
}
$hash->{$it_c2b{"on"}} = lc($oncode);
$hash->{$it_c2b{"off"}} = lc($offcode);
if (int(@a) > 5) {
return "Define $a[0]: wrong dimup-code format: specify a 2 digits 0/1/f/d "
if( ($a[5] !~ m/^[df0-1]{2}$/i) );
$hash->{$it_c2b{"dimup"}} = lc($a[5]);
if (int(@a) == 7) {
return "Define $a[0]: wrong dimdown-code format: specify a 2 digits 0/1/f/d "
if( ($a[6] !~ m/^[df0-1]{2}$/i) );
$hash->{$it_c2b{"dimdown"}} = lc($a[6]);
}
if (length($a[5]) != 4) { # kein EV1527
return "Define $a[0]: wrong dimup-code format: specify a 2 digits 0/1/f/d "
if( ($a[5] !~ m/^[df0-1]{2}$/i) );
} else {
return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
if( ($a[5] !~ m/^[0-1]{4}$/i) );
}
$hash->{$it_c2b{"dimup"}} = lc($a[5]);
if (int(@a) == 7) {
if (length($a[6]) != 4) { # kein EV1527
return "Define $a[0]: wrong dimdown-code format: specify a 2 digits 0/1/f/d "
if( ($a[6] !~ m/^[df0-1]{2}$/i) );
} else {
return "Define $a[0]: wrong dimup-code format: specify a 4 digits 0/1 "
if( ($a[6] !~ m/^[0-1]{4}$/i) );
}
}
$hash->{$it_c2b{"dimdown"}} = lc($a[6]);
} else {
$hash->{$it_c2b{"dimup"}} = "00";
$hash->{$it_c2b{"dimdown"}} = "00";
$hash->{$it_c2b{"dimup"}} = "00";
$hash->{$it_c2b{"dimdown"}} = "00";
}
my $code = lc($housecode);
@ -1057,10 +1123,9 @@ IT_Parse($$)
Log3 $hash,2,"$ioname IT: $housecode not defined (HE800)";
return "UNDEFINED IT_HE800_$housecode IT " . "HE800 $transmittercode $unitCode" if(!$def);
} else {
Log3 $hash,2,"$ioname IT: " . substr($msgcode,0,26) . " not defined (Address: ".substr($msgcode,0,26)." Group: $groupBit Unit: $unitCode Switch code: $onoffcode)";
my $tmpHouseCode = substr($msgcode,0,26);
my $decCode = bin2dec($tmpHouseCode);
return "UNDEFINED IT_V3_$decCode IT " . substr($msgcode,0,26) . " $groupBit $unitCode" if(!$def);
my $hexCode = sprintf("%x", oct("0b".$housecode));
Log3 $hash,2,"$ioname IT: IT_V3_$hexCode ($housecode) not defined (Address: ".substr($msgcode,0,26)." Group: $groupBit Unit: $unitCode Switch code: $onoffcode)";
return "UNDEFINED IT_V3_$hexCode IT " . substr($msgcode,0,26) . " $groupBit $unitCode" if(!$def);
}
}
$def=$modules{IT}{defptr}{lc($housecode)};
@ -1179,14 +1244,33 @@ sub IT_Attr(@)
{
my ($cmd,$name,$aName,$aVal) = @_;
my $hash = $defs{$name};
my $ret;
#Log3 $hash, 4, "$name IT_Attr: Calling Getting Attr sub with args: $cmd $aName = $aVal";
if( $aName eq 'model' && $aVal eq 'ev1527') {
#Log3 $hash, 4, "$name IT_Attr: ev1527";
$hash->{READINGS}{protocol}{VAL} = 'EV1527';
} elsif ( $aName eq 'userV1setCodes') {
my @array = split(" ",$aVal);
$hash->{userV1setCodes} = undef;
foreach my $item(@array) {
my ($i,$j)= split(/:/, $item);
$ret = "$i wrong chars in setname (only [0-9a-zA-Z-_])"
if ( ($i !~ m/^[0-9a-z-_]+$/i) );
if (length($j) != 4) { # kein EV1527
$ret = "$j wrong setcode format: specify a 2 digits 0/1/f/d "
if( ($j !~ m/^[df0-1]{2}$/i) );
} else {
$ret = "$j wrong setcode format: specify a 4 digits 0/1 "
if( ($j !~ m/^[0-1]{4}$/i) );
}
last if (defined($ret));
$hash->{userV1setCodes}{$i} = $j;
}
}
return undef;
return $ret;
}
1;