Merge pull request #9 from T0RST3N/devel

some changes and fixes
This commit is contained in:
2017-12-15 09:12:09 +01:00
committed by GitHub
3 changed files with 186 additions and 139 deletions

View File

@@ -43,6 +43,7 @@ return "\nERROR: Please install Net::Ping" if($@);
eval "use Math::Round"; eval "use Math::Round";
return "\nERROR: Please install libmath-round-perl" if($@); return "\nERROR: Please install libmath-round-perl" if($@);
use Color; use Color;
use SetExtensions; use SetExtensions;
@@ -51,7 +52,9 @@ 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.12";
my $version = "1.19";
my %XiaomiSmartHome_gets = ( my %XiaomiSmartHome_gets = (
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ], "getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
@@ -114,10 +117,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)
{ {

View File

@@ -26,7 +26,9 @@ use strict;
use warnings; use warnings;
use Math::Round qw/nearest/; use Math::Round qw/nearest/;
my $version = "1.12";
my $version = "1.19";
sub XiaomiSmartHome_Device_updateSReading($); sub XiaomiSmartHome_Device_updateSReading($);
@@ -44,7 +46,11 @@ 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 +198,11 @@ 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 $round = AttrVal( $hash->{NAME}, "round", "2" ); my $XMIround_tmp = AttrVal( $hash->{NAME}, "rnd_tmp", "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: $@";
@@ -201,6 +210,7 @@ sub XiaomiSmartHome_Device_Read($$$){
} }
my $sid = $decoded->{'sid'}; my $sid = $decoded->{'sid'};
my $model = $decoded->{'model'}; my $model = $decoded->{'model'};
my $cmd = $decoded->{'cmd'};
Log3 $name, 5, "$name: DEV_Read> SID: " . $hash->{SID} . " " . $hash->{TYPE}; Log3 $name, 5, "$name: DEV_Read> SID: " . $hash->{SID} . " " . $hash->{TYPE};
my $data = eval{decode_json($decoded->{data})}; my $data = eval{decode_json($decoded->{data})};
if ($@) { if ($@) {
@@ -208,140 +218,154 @@ sub XiaomiSmartHome_Device_Read($$$){
return; return;
} }
readingsBeginUpdate( $hash ); readingsBeginUpdate( $hash );
if (defined $data->{status}){ if (defined $data->{status}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Status: " . $data->{status}; Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Status: " . $data->{status};
readingsBulkUpdate($hash, "state", "$data->{status}", 1 ); readingsBulkUpdate($hash, "state", "$data->{status}", 1 );
if ($data->{status} eq 'motion' && $hash->{MODEL} =~ /motion/){ if ($data->{status} eq 'motion' && $hash->{MODEL} =~ /motion/){
readingsBulkUpdate($hash, "no_motion", "0", 1 ); readingsBulkUpdate($hash, "no_motion", "0", 1 );
} }
if ($data->{status} eq 'close' && $hash->{MODEL} =~ /magnet/){ if ($data->{status} eq 'close' && $hash->{MODEL} =~ /magnet/){
readingsBulkUpdate($hash, "no_close", "0", 1 ); readingsBulkUpdate($hash, "no_close", "0", 1 );
}
} }
}
if (defined $data->{no_motion}){ if (defined $data->{no_motion}){
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " NO_motion: " . $data->{no_motion}; Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " NO_motion: " . $data->{no_motion};
readingsBulkUpdate($hash, "no_motion", "$data->{no_motion}", 1 ); readingsBulkUpdate($hash, "no_motion", "$data->{no_motion}", 1 );
}
if (defined $data->{no_close}){
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " NO_close: " . $data->{no_close};
readingsBulkUpdate($hash, "no_close", "$data->{no_close}", 1 );
}
if (defined $data->{voltage}){
my $bat = ($data->{voltage}/1000);
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) {
readingsBulkUpdate($hash, "batterystate", "low", 1 );
} }
else { if (defined $data->{no_close}){
readingsBulkUpdate($hash, "batterystate", "ok", 1 ) Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " NO_close: " . $data->{no_close};
readingsBulkUpdate($hash, "no_close", "$data->{no_close}", 1 );
} }
} if (defined $data->{voltage}){
if (defined $data->{temperature}){ my $bat = ($data->{voltage}/1000);
my $temp = $data->{temperature}; Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Voltage: " . $data->{voltage};
$temp =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{3}(?=\d))/$1./g; if ($bat < 2.2) {
$temp = nearest(@arround[$round-1] ,$temp ); readingsBulkUpdate($hash, "battery", "low", 1 );
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Temperature: " . $temp . " Round: " . $round; }
readingsBulkUpdate($hash, "temperature", "$temp", 1 ); else {
} readingsBulkUpdate($hash, "battery", "ok", 1 )
if (defined $data->{humidity}){ }
my $hum = $data->{humidity}; $bat = XiaomiSmartHome_round($bat, $XMIround_bat, $name );
$hum =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{2}(?=\d))/$1./g; readingsBulkUpdate($hash, "battery_level", $bat, 1 );
$hum = nearest(@arround[$round-1] ,$hum ); }
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Humidity: " . $hum; if (defined $data->{temperature}){
readingsBulkUpdate($hash, "humidity", "$hum", 1 ); if ($data->{temperature} ne "10000"){
} my $temp = sprintf( "%#.4d", $data->{temperature});
if (defined $data->{pressure}){ $temp =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{3}(?=\d))/$1./g;
my $pres = $data->{pressure}; $temp = XiaomiSmartHome_round($temp, $XMIround_tmp, $name );
$pres =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1./g; Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Temperature: " . $temp . " Round: " . $XMIround_tmp;
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Pressure: " . $pres; readingsBulkUpdate($hash, "temperature", "$temp", 1 );
readingsBulkUpdate($hash, "pressure", "$pres", 1 ); }
} }
if (defined $data->{lux}){ if (defined $data->{humidity}){
my $lux = $data->{lux}; if ($data->{humidity} ne "0"){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Illuminance: " . $lux; my $hum = $data->{humidity};
readingsBulkUpdate($hash, "lux", "$lux", 1 ); $hum =~ s/(^[-+]?\d+?(?=(?>(?:\d{2})+)(?!\d))|\G\d{2}(?=\d))/$1./g;
} $hum = XiaomiSmartHome_round($hum, $XMIround_hum, $name );
#86sw1 + 86sw2 + ctrl_neutral1 + ctrl_neutral2 start Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Humidity: " . $hum . " Round: " . $XMIround_hum;
if (defined $data->{channel_0}){ readingsBulkUpdate($hash, "humidity", "$hum", 1 );
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Channel_0: " . $data->{channel_0}; }
readingsBulkUpdate($hash, "channel_0", "$data->{channel_0}", 1 ); }
} if (defined $data->{pressure}){
if (defined $data->{channel_1}){ if ($data->{pressure} ne "0"){
Log3 $name, 3, "$name: DEV_Read>" . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Channel_1: " . $data->{channel_1}; my $pres = $data->{pressure};
readingsBulkUpdate($hash, "channel_1", "$data->{channel_1}", 1 ); $pres =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1./g;
} Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Pressure: " . $pres;
#86sw1 + 86sw2 + ctrl_neutral1 + ctrl_neutral2 end readingsBulkUpdate($hash, "pressure", "$pres", 1 );
#plug & 86plug start }
if (defined $data->{load_voltage}){ }
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " LOAD_Voltage: " . $data->{load_voltage}; if (defined $data->{lux}){
readingsBulkUpdate($hash, "LOAD_Voltage", "$data->{load_voltage}", 1 ); my $lux = $data->{lux};
} Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Illuminance: " . $lux;
if (defined $data->{load_power}){ readingsBulkUpdate($hash, "lux", "$lux", 1 );
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " LOAD_Power: " . $data->{load_power}; }
readingsBulkUpdate($hash, "LOAD_Power", "$data->{load_power}", 1 ); #86sw1 + 86sw2 + ctrl_neutral1 + ctrl_neutral2 start
} if (defined $data->{channel_0}){
if (defined $data->{power_consumed}){ Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Channel_0: " . $data->{channel_0};
Log3 $name, 4, "$name:" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " POWER_Consumed: " . $data->{power_consumed}; readingsBulkUpdate($hash, "channel_0", "$data->{channel_0}", 1 );
readingsBulkUpdate($hash, "POWER_Consumed", "$data->{power_consumed}", 1 ); }
} if (defined $data->{channel_1}){
if (defined $data->{inuse}){ Log3 $name, 3, "$name: DEV_Read>" . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Channel_1: " . $data->{channel_1};
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " InUse: " . $data->{inuse}; readingsBulkUpdate($hash, "channel_1", "$data->{channel_1}", 1 );
readingsBulkUpdate($hash, "inuse", "$data->{inuse}", 1 ); }
} if (defined $data->{dual_channel}){
#plug & 86plug end Log3 $name, 3, "$name: DEV_Read>" . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Dual_Channel: " . $data->{dual_channel};
#rgbw_light start readingsBulkUpdate($hash, "dual_channel", "$data->{dual_channel}", 1 );
if (defined $data->{level}){ }
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Level: " . $data->{level}; #86sw1 + 86sw2 + ctrl_neutral1 + ctrl_neutral2 end
readingsBulkUpdate($hash, "level", "$data->{level}", 1 ); #plug & 86plug start
} if (defined $data->{load_voltage}){
if (defined $data->{hue}){ Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " LOAD_Voltage: " . $data->{load_voltage};
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Hue: " . $data->{hue}; readingsBulkUpdate($hash, "LOAD_Voltage", "$data->{load_voltage}", 1 );
readingsBulkUpdate($hash, "hue", "$data->{hue}", 1 ); }
} if (defined $data->{load_power}){
if (defined $data->{saturation}){ Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " LOAD_Power: " . $data->{load_power};
Log3 $name, 4, "$name:" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Saturation: " . $data->{saturation}; readingsBulkUpdate($hash, "LOAD_Power", "$data->{load_power}", 1 );
readingsBulkUpdate($hash, "saturation", "$data->{saturation}", 1 ); }
} if (defined $data->{power_consumed}){
if (defined $data->{color_temperature}){ Log3 $name, 4, "$name:" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " POWER_Consumed: " . $data->{power_consumed};
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Color_temperature: " . $data->{color_temperature}; readingsBulkUpdate($hash, "POWER_Consumed", "$data->{power_consumed}", 1 );
readingsBulkUpdate($hash, "color_temperature", "$data->{color_temperature}", 1 ); }
} if (defined $data->{inuse}){
if (defined $data->{x}){ Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " InUse: " . $data->{inuse};
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " X: " . $data->{x}; readingsBulkUpdate($hash, "inuse", "$data->{inuse}", 1 );
readingsBulkUpdate($hash, "x", "$data->{x}", 1 ); }
} #plug & 86plug end
if (defined $data->{y}){ #rgbw_light start
Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Y: " . $data->{y}; if (defined $data->{level}){
readingsBulkUpdate($hash, "y", "$data->{y}", 1 ); Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Level: " . $data->{level};
} readingsBulkUpdate($hash, "level", "$data->{level}", 1 );
#rgbw_light end }
#cube start if (defined $data->{hue}){
if (defined $data->{rotate}){ Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Hue: " . $data->{hue};
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Rotate: " . $data->{rotate}; readingsBulkUpdate($hash, "hue", "$data->{hue}", 1 );
readingsBulkUpdate($hash, "rotate", "$data->{rotate}", 1 ); }
readingsBulkUpdate($hash, "state", "rotate", 1 ); if (defined $data->{saturation}){
} Log3 $name, 4, "$name:" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Saturation: " . $data->{saturation};
#cube end readingsBulkUpdate($hash, "saturation", "$data->{saturation}", 1 );
#smoke & natgast start }
if (defined $data->{alarm}){ if (defined $data->{color_temperature}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Alarm: " . $data->{alarm}; Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Color_temperature: " . $data->{color_temperature};
readingsBulkUpdate($hash, "alarm", "$data->{alarm}", 1 ); readingsBulkUpdate($hash, "color_temperature", "$data->{color_temperature}", 1 );
} }
if (defined $data->{density}){ if (defined $data->{x}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Density: " . $data->{density}; Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " X: " . $data->{x};
readingsBulkUpdate($hash, "density", "$data->{density}", 1 ); readingsBulkUpdate($hash, "x", "$data->{x}", 1 );
} }
#smoke & natgast end if (defined $data->{y}){
#curtain start Log3 $name, 4, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Y: " . $data->{y};
if (defined $data->{curtain_level}){ readingsBulkUpdate($hash, "y", "$data->{y}", 1 );
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Curtain: " . $data->{curtain_level}; }
readingsBulkUpdate($hash, "arlarm", "$data->{curtain_level}", 1 ); #rgbw_light end
} #cube start
#curtain end if (defined $data->{rotate}){
if ($decoded->{'cmd'} eq 'heartbeat'){ Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Rotate: " . $data->{rotate};
readingsBulkUpdate($hash, "rotate", "$data->{rotate}", 1 );
readingsBulkUpdate($hash, "state", "rotate", 1 );
}
#cube end
#smoke & natgast start
if (defined $data->{alarm}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Alarm: " . $data->{alarm};
readingsBulkUpdate($hash, "alarm", "$data->{alarm}", 1 );
}
if (defined $data->{density}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Density: " . $data->{density};
readingsBulkUpdate($hash, "density", "$data->{density}", 1 );
}
#smoke & natgast end
#curtain start
if (defined $data->{curtain_level}){
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Curtain: " . $data->{curtain_level};
readingsBulkUpdate($hash, "arlarm", "$data->{curtain_level}", 1 );
}
#curtain end
if ($decoded->{'cmd'} eq 'heartbeat'){
readingsBulkUpdate($hash, 'heartbeat', $decoded->{'sid'} , 1 ); readingsBulkUpdate($hash, 'heartbeat', $decoded->{'sid'} , 1 );
} }
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
XiaomiSmartHome_Device_update($hash); XiaomiSmartHome_Device_update($hash);
return $hash->{NAME}; return $hash->{NAME};
@@ -391,8 +415,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 +492,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

View File

@@ -1,2 +1,2 @@
UPD 2017-10-24_08:55:31 36922 FHEM/71_XiaomiSmartHome.pm UPD 2017-12_08_08:06:18 36907 FHEM/71_XiaomiSmartHome.pm
UPD 2017-10-24_08:44:58 25216 FHEM/71_XiaomiSmartHome_Device.pm UPD 2017-12-13_08:02:11 26609 FHEM/71_XiaomiSmartHome_Device.pm