some changes and fixes
- change: Perl modul math::round no longer necessary - change: reading round is now rnd_tmp, rnd_hum, rnd_bat - change: reading battery is now batterystate - change: reading battery is now battery_level - fix: if GW has no SID reading stop - fix: if temperature is [1][0].xx or -[1][0].xx now the leading number is display - added: support switch 86sw2 dual_channel click
This commit is contained in:
@@ -40,8 +40,7 @@ eval "use Crypt::CBC";
|
|||||||
return "\nERROR: Please install Crypt::CBC" if($@);
|
return "\nERROR: Please install Crypt::CBC" if($@);
|
||||||
eval "use Net::Ping";
|
eval "use Net::Ping";
|
||||||
return "\nERROR: Please install Net::Ping" if($@);
|
return "\nERROR: Please install Net::Ping" if($@);
|
||||||
eval "use Math::Round";
|
|
||||||
return "\nERROR: Please install libmath-round-perl" if($@);
|
|
||||||
|
|
||||||
use Color;
|
use Color;
|
||||||
use SetExtensions;
|
use SetExtensions;
|
||||||
@@ -51,7 +50,7 @@ use SetExtensions;
|
|||||||
sub XiaomiSmartHome_Notify($$);
|
sub XiaomiSmartHome_Notify($$);
|
||||||
sub XiaomiSmartHome_updateSingleReading($$);
|
sub XiaomiSmartHome_updateSingleReading($$);
|
||||||
my $iv="\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58\x56\x2e";
|
my $iv="\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58\x56\x2e";
|
||||||
my $version = "1.15";
|
my $version = "1.18";
|
||||||
my %XiaomiSmartHome_gets = (
|
my %XiaomiSmartHome_gets = (
|
||||||
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
|
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
|
||||||
|
|
||||||
@@ -114,10 +113,13 @@ sub XiaomiSmartHome_Read($) {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $self = {}; # my new hash
|
my $self = {}; # my new hash
|
||||||
my $new_hash = {};
|
|
||||||
|
|
||||||
Log3 $name, 5, "$name: Read> Read start";
|
Log3 $name, 5, "$name: Read> Read start";
|
||||||
my $buf = "";
|
if ( ! $hash->{SID} ){
|
||||||
|
Log3 $name, 3, "$name: Read> No SID, Stop Read";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
my $buf = "";
|
||||||
my $ret = sysread($hash->{CD}, $buf, 1024);
|
my $ret = sysread($hash->{CD}, $buf, 1024);
|
||||||
if (!defined($ret) || $ret <= 0)
|
if (!defined($ret) || $ret <= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ package main;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Math::Round qw/nearest/;
|
|
||||||
|
|
||||||
my $version = "1.15";
|
|
||||||
|
my $version = "1.18";
|
||||||
sub XiaomiSmartHome_Device_updateSReading($);
|
sub XiaomiSmartHome_Device_updateSReading($);
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +44,9 @@ sub XiaomiSmartHome_Device_Initialize($)
|
|||||||
|
|
||||||
$hash->{AttrList} = "IODev follow-on-for-timer:1,0 follow-on-timer ".
|
$hash->{AttrList} = "IODev follow-on-for-timer:1,0 follow-on-timer ".
|
||||||
"do_not_notify:1,0 ignore:1,0 dummy:1,0 showtime:1,0 valueFn:textField-long ".
|
"do_not_notify:1,0 ignore:1,0 dummy:1,0 showtime:1,0 valueFn:textField-long ".
|
||||||
"round:1,2,3 ".
|
"rnd_tmp:1,2,3 ".
|
||||||
|
"rnd_hum:1,2,3 ".
|
||||||
|
"rnd_bat:1,2,3 ".
|
||||||
$readingFnAttributes ;
|
$readingFnAttributes ;
|
||||||
}
|
}
|
||||||
#####################################
|
#####################################
|
||||||
@@ -192,8 +194,9 @@ sub XiaomiSmartHome_Device_on_timeout($){
|
|||||||
#####################################
|
#####################################
|
||||||
sub XiaomiSmartHome_Device_Read($$$){
|
sub XiaomiSmartHome_Device_Read($$$){
|
||||||
my ($hash, $msg, $name) = @_;
|
my ($hash, $msg, $name) = @_;
|
||||||
my @arround = ("0.1","0.01","0.001");
|
my $XMIround_tmp = AttrVal( $hash->{NAME}, "rnd_tmp", "2" );
|
||||||
my $round = AttrVal( $hash->{NAME}, "round", "2" );
|
my $XMIround_hum = AttrVal( $hash->{NAME}, "rnd_hum", "2" );
|
||||||
|
my $XMIround_bat = AttrVal( $hash->{NAME}, "rnd_bat", "1" );
|
||||||
my $decoded = eval{decode_json($msg)};
|
my $decoded = eval{decode_json($msg)};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
Log3 $name, 1, "$name: DEV_Read> Error while request: $@";
|
Log3 $name, 1, "$name: DEV_Read> Error while request: $@";
|
||||||
@@ -230,26 +233,27 @@ sub XiaomiSmartHome_Device_Read($$$){
|
|||||||
if (defined $data->{voltage}){
|
if (defined $data->{voltage}){
|
||||||
my $bat = ($data->{voltage}/1000);
|
my $bat = ($data->{voltage}/1000);
|
||||||
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Voltage: " . $data->{voltage};
|
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Voltage: " . $data->{voltage};
|
||||||
readingsBulkUpdate($hash, "battery", $bat, 1 );
|
|
||||||
if ($bat < 2.2) {
|
if ($bat < 2.2) {
|
||||||
readingsBulkUpdate($hash, "batterystate", "low", 1 );
|
readingsBulkUpdate($hash, "battery", "low", 1 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate($hash, "batterystate", "ok", 1 )
|
readingsBulkUpdate($hash, "battery", "ok", 1 )
|
||||||
}
|
}
|
||||||
|
$bat = XiaomiSmartHome_round($bat, $XMIround_bat, $name );
|
||||||
|
readingsBulkUpdate($hash, "battery_level", $bat, 1 );
|
||||||
}
|
}
|
||||||
if (defined $data->{temperature}){
|
if (defined $data->{temperature}){
|
||||||
my $temp = $data->{temperature};
|
my $temp = sprintf( "%#.4d", $data->{temperature});
|
||||||
$temp =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{3}(?=\d))/$1./g;
|
$temp =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{3}(?=\d))/$1./g;
|
||||||
$temp = nearest(@arround[$round-1] ,$temp );
|
$temp = XiaomiSmartHome_round($temp, $XMIround_tmp, $name );
|
||||||
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Temperature: " . $temp . " Round: " . $round;
|
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Temperature: " . $temp . " Round: " . $XMIround_tmp;
|
||||||
readingsBulkUpdate($hash, "temperature", "$temp", 1 );
|
readingsBulkUpdate($hash, "temperature", "$temp", 1 );
|
||||||
}
|
}
|
||||||
if (defined $data->{humidity}){
|
if (defined $data->{humidity}){
|
||||||
my $hum = $data->{humidity};
|
my $hum = $data->{humidity};
|
||||||
$hum =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{2}(?=\d))/$1./g;
|
$hum =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{2}(?=\d))/$1./g;
|
||||||
$hum = nearest(@arround[$round-1] ,$hum );
|
$hum = XiaomiSmartHome_round($hum, $XMIround_hum, $name );
|
||||||
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Humidity: " . $hum;
|
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Humidity: " . $hum . " Round: " . $XMIround_hum;
|
||||||
readingsBulkUpdate($hash, "humidity", "$hum", 1 );
|
readingsBulkUpdate($hash, "humidity", "$hum", 1 );
|
||||||
}
|
}
|
||||||
if (defined $data->{pressure}){
|
if (defined $data->{pressure}){
|
||||||
@@ -272,6 +276,10 @@ sub XiaomiSmartHome_Device_Read($$$){
|
|||||||
Log3 $name, 3, "$name: DEV_Read>" . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Channel_1: " . $data->{channel_1};
|
Log3 $name, 3, "$name: DEV_Read>" . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Channel_1: " . $data->{channel_1};
|
||||||
readingsBulkUpdate($hash, "channel_1", "$data->{channel_1}", 1 );
|
readingsBulkUpdate($hash, "channel_1", "$data->{channel_1}", 1 );
|
||||||
}
|
}
|
||||||
|
if (defined $data->{dual_channel}){
|
||||||
|
Log3 $name, 3, "$name: DEV_Read>" . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Dual_Channel: " . $data->{dual_channel};
|
||||||
|
readingsBulkUpdate($hash, "dual_channel", "$data->{dual_channel}", 1 );
|
||||||
|
}
|
||||||
#86sw1 + 86sw2 + ctrl_neutral1 + ctrl_neutral2 end
|
#86sw1 + 86sw2 + ctrl_neutral1 + ctrl_neutral2 end
|
||||||
#plug & 86plug start
|
#plug & 86plug start
|
||||||
if (defined $data->{load_voltage}){
|
if (defined $data->{load_voltage}){
|
||||||
@@ -340,6 +348,9 @@ sub XiaomiSmartHome_Device_Read($$$){
|
|||||||
readingsBulkUpdate($hash, "arlarm", "$data->{curtain_level}", 1 );
|
readingsBulkUpdate($hash, "arlarm", "$data->{curtain_level}", 1 );
|
||||||
}
|
}
|
||||||
#curtain end
|
#curtain end
|
||||||
|
if ($decoded->{'cmd'} eq 'heartbeat'){
|
||||||
|
readingsBulkUpdate($hash, 'heartbeat', $decoded->{'sid'} , 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
@@ -391,8 +402,10 @@ sub XiaomiSmartHome_Device_update($){
|
|||||||
if( $model =~ /motion/) {
|
if( $model =~ /motion/) {
|
||||||
XiaomiSmartHome_Device_mot($hash, $hash->{READINGS}{motionOffTimer}{VAL}) if( $hash->{READINGS}{motionOffTimer});
|
XiaomiSmartHome_Device_mot($hash, $hash->{READINGS}{motionOffTimer}{VAL}) if( $hash->{READINGS}{motionOffTimer});
|
||||||
}
|
}
|
||||||
# Update delete old reading Voltage
|
# Update delete old reading voltage & batterystate
|
||||||
CommandDeleteReading( undef, "$name voltage" ) if(defined(ReadingsVal($name,"voltage",undef)));
|
CommandDeleteReading( undef, "$name voltage" ) if(defined(ReadingsVal($name,"voltage",undef)));
|
||||||
|
CommandDeleteReading( undef, "$name batterystate" ) if(defined(ReadingsVal($name,"batterystate",undef)));
|
||||||
|
CommandDeleteReading( undef, "$name round" ) if(defined(ReadingsVal($name,"round",undef)));
|
||||||
}
|
}
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
@@ -466,6 +479,21 @@ sub XiaomiSmartHome_Device_Undef($)
|
|||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
sub XiaomiSmartHome_round {
|
||||||
|
my ($n, $p, $name) = @_;
|
||||||
|
Log3 $name, 5, "$name: DEV_Round>" . " Value: " . $n . " points: " . $p;
|
||||||
|
my $sign = ($n > 0) ? 1 : -1;
|
||||||
|
|
||||||
|
$p ||= 0;
|
||||||
|
$n *= 10 ** $p;
|
||||||
|
$n = int($n + .5 * $sign);
|
||||||
|
Log3 $name, 5, "$name: DEV_Round>" . " Result_value: " . $n / 10**$p;
|
||||||
|
return $n / 10**$p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
UPD 2017-10-30_11:17:13 36922 FHEM/71_XiaomiSmartHome.pm
|
UPD 2017-12_08_13:29:11 36907 FHEM/71_XiaomiSmartHome.pm
|
||||||
UPD 2017-10-30_11:17:14 25266 FHEM/71_XiaomiSmartHome_Device.pm
|
UPD 2017-12-08_13:28:54 26468 FHEM/71_XiaomiSmartHome_Device.pm
|
||||||
|
|||||||
Reference in New Issue
Block a user