Support for new Sensors vibration
-add support for sensor vibration -fix some fixes for multigw support.
This commit is contained in:
@@ -51,7 +51,7 @@ 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.31";
|
my $version = "1.33";
|
||||||
|
|
||||||
my %XiaomiSmartHome_gets = (
|
my %XiaomiSmartHome_gets = (
|
||||||
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
|
"getDevices" => ["get_id_list", '^.+get_id_list_ack' ],
|
||||||
@@ -107,7 +107,8 @@ sub XiaomiSmartHome_Initialize($) {
|
|||||||
"17:XiaomiSmartHome_Device" => "^.+smoke",
|
"17:XiaomiSmartHome_Device" => "^.+smoke",
|
||||||
"18:XiaomiSmartHome_Device" => "^.+weather.v1",
|
"18:XiaomiSmartHome_Device" => "^.+weather.v1",
|
||||||
"19:XiaomiSmartHome_Device" => "^.+sensor_motion.aq2",
|
"19:XiaomiSmartHome_Device" => "^.+sensor_motion.aq2",
|
||||||
"20:XiaomiSmartHome_Device" => "^.+sensor_wleak.aq1"};
|
"20:XiaomiSmartHome_Device" => "^.+sensor_wleak.aq1",
|
||||||
|
"21:XiaomiSmartHome_Device" => "^.+vibration"};
|
||||||
FHEM_colorpickerInit();
|
FHEM_colorpickerInit();
|
||||||
}
|
}
|
||||||
#####################################
|
#####################################
|
||||||
@@ -130,7 +131,7 @@ sub XiaomiSmartHome_Read($) {
|
|||||||
InternalTimer(gettimeofday() + 2, "XiaomiSmartHome_connect", $hash, 0);
|
InternalTimer(gettimeofday() + 2, "XiaomiSmartHome_connect", $hash, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $json = $hash->{helper}{JSON}->incr_parse($buf);
|
my $json = $hash->{helper}{JSON}->incr_parse($buf);
|
||||||
my $decoded = eval{decode_json($buf)};
|
my $decoded = eval{decode_json($buf)};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
Log3 $name, 1, "$name: Read> Error while request: $@";
|
Log3 $name, 1, "$name: Read> Error while request: $@";
|
||||||
@@ -145,6 +146,7 @@ sub XiaomiSmartHome_Read($) {
|
|||||||
Log3 $name, 5, "$name: Read> [PLAIN] " . $buf;
|
Log3 $name, 5, "$name: Read> [PLAIN] " . $buf;
|
||||||
my $rsid = $decoded->{'sid'};
|
my $rsid = $decoded->{'sid'};
|
||||||
if ($decoded->{'cmd'} eq 'read_ack' || $decoded->{'cmd'} eq 'report' && $decoded->{'model'} ne 'gateway'|| $decoded->{'cmd'} eq 'heartbeat' && $decoded->{'model'} ne 'gateway' || $decoded->{'cmd'} eq 'write_ack' && $decoded->{'model'} ne 'gateway') {
|
if ($decoded->{'cmd'} eq 'read_ack' || $decoded->{'cmd'} eq 'report' && $decoded->{'model'} ne 'gateway'|| $decoded->{'cmd'} eq 'heartbeat' && $decoded->{'model'} ne 'gateway' || $decoded->{'cmd'} eq 'write_ack' && $decoded->{'model'} ne 'gateway') {
|
||||||
|
# devices does not exist yet
|
||||||
if (!$modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME}){
|
if (!$modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME}){
|
||||||
Log3 $name, 5, "$name: Read> XiaomiSmartHome_Device unknown trying autocreate" ;
|
Log3 $name, 5, "$name: Read> XiaomiSmartHome_Device unknown trying autocreate" ;
|
||||||
my $def=$modules{XiaomiSmartHome}{defptr};
|
my $def=$modules{XiaomiSmartHome}{defptr};
|
||||||
@@ -155,36 +157,49 @@ sub XiaomiSmartHome_Read($) {
|
|||||||
Log3 $value->{NAME}, 5, "$value->{NAME}: $rsid is sensor from $value->{NAME}";
|
Log3 $value->{NAME}, 5, "$value->{NAME}: $rsid is sensor from $value->{NAME}";
|
||||||
Dispatch($value, $buf, undef);
|
Dispatch($value, $buf, undef);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} eq $hash->{NAME}) {
|
# devices available with proper gw
|
||||||
|
elsif ($modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} eq $hash->{NAME}) {
|
||||||
Log3 $name, 5, "$name: Read> XiaomiSmartHome_Device known! " . "SID: " . $rsid . " " . $modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} . " " . $hash->{NAME};
|
Log3 $name, 5, "$name: Read> XiaomiSmartHome_Device known! " . "SID: " . $rsid . " " . $modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} . " " . $hash->{NAME};
|
||||||
Log3 $name, 5, "$name: Read> Dispatching " . $buf . " " . $hash->{NAME};
|
Log3 $name, 5, "$name: Read> Dispatching " . $buf . " " . $hash->{NAME};
|
||||||
Dispatch($hash, $buf, undef);
|
}
|
||||||
}
|
# Senosoren check
|
||||||
elsif ($modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} ne $hash->{NAME}) {
|
elsif ($modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} ne $hash->{NAME}) {
|
||||||
Log3 $name, 5, "$name: Read> Wrong Modul HASH Trying to find the right one " . $modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} . " <> " . $hash->{NAME} ;
|
Log3 $name, 5, "$name: Read> Wrong Modul HASH Trying to find the right one " . $modules{XiaomiSmartHome_Device}{defptr}{$rsid}{IODev}->{NAME} . " <> " . $hash->{NAME} ;
|
||||||
$hash = $modules{XiaomiSmartHome_Device}{defptr}{$rsid}->{IODev};
|
$hash = $modules{XiaomiSmartHome_Device}{defptr}{$rsid}->{IODev};
|
||||||
Log3 $name, 5, "$name: Read> Using this GW " . $hash->{NAME} . " no Dispatching!";
|
Log3 $name, 5, "$name: Read> Using this GW " . $hash->{NAME} ;
|
||||||
}
|
}
|
||||||
|
Log3 $name, 5, "$name: Read> Dispatching " . $buf . " " . $hash->{NAME};
|
||||||
|
Dispatch($hash, $buf, undef);
|
||||||
|
}
|
||||||
|
# gateway sensor list
|
||||||
|
elsif ($decoded->{'cmd'} eq 'get_id_list_ack'){
|
||||||
|
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
|
||||||
|
Log3 $name, 5, "$name: Read> Reading Sensorlist with $self->{NAME}" ;
|
||||||
|
XiaomiSmartHome_Reading ($self, $buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
# gateway not definded
|
||||||
elsif (!$modules{XiaomiSmartHome}{defptr}{$rsid}){
|
elsif (!$modules{XiaomiSmartHome}{defptr}{$rsid}){
|
||||||
Log3 $name, 1, "$name: Read> GW not defined " . $buf;
|
Log3 $name, 1, "$name: Read> GW not defined " . $buf;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
# gateway defined but not the right modul instance - change
|
||||||
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} ne $hash->{SID} ){
|
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} ne $hash->{SID} ){
|
||||||
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
|
$self = $modules{XiaomiSmartHome}{defptr}{$rsid};
|
||||||
Log3 $name, 5, "$name: Read> Change HASH Ref to $self->{NAME}";
|
Log3 $name, 5, "$name: Read> Wrong Modul HASH skipping $self->{NAME}";
|
||||||
XiaomiSmartHome_Reading ($self, $buf);
|
#XiaomiSmartHome_Reading ($self, $buf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
#gateway defined and the right modul instance - nothing to change
|
||||||
{
|
elsif ( $modules{XiaomiSmartHome}{defptr}{$rsid}->{SID} eq $hash->{SID} ){
|
||||||
Log3 $name, 5, "$name: Read> HASH correctly";
|
Log3 $name, 5, "$name: Read> HASH correctly";
|
||||||
XiaomiSmartHome_Reading ($hash, $buf);
|
XiaomiSmartHome_Reading ($hash, $buf);
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#####################################
|
#####################################
|
||||||
sub XiaomiSmartHome_Reading ($@) {
|
sub XiaomiSmartHome_Reading ($@) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use warnings;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
my $version = "1.30";
|
my $version = "1.33";
|
||||||
|
|
||||||
sub XiaomiSmartHome_Device_updateSReading($);
|
sub XiaomiSmartHome_Device_updateSReading($);
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ sub XiaomiSmartHome_Device_Initialize($)
|
|||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
$hash->{Match} = ".*magnet.*|.*motion.*|sensor_ht|.*switch.*|plug|.*cube.*|86sw1|86sw2|ctrl_neutral1|ctrl_neutral2|rgbw_light|curtain|ctrl_ln1|ctrl_ln2|86plug|natgas|smoke|weather.v1|sensor_wleak.aq1";
|
$hash->{Match} = ".*magnet.*|.*motion.*|sensor_ht|.*switch.*|plug|.*cube.*|86sw1|86sw2|ctrl_neutral1|ctrl_neutral2|rgbw_light|curtain|ctrl_ln1|ctrl_ln2|86plug|natgas|smoke|weather.v1|sensor_wleak.aq1|vibration";
|
||||||
$hash->{DefFn} = "XiaomiSmartHome_Device_Define";
|
$hash->{DefFn} = "XiaomiSmartHome_Device_Define";
|
||||||
$hash->{SetFn} = "XiaomiSmartHome_Device_Set";
|
$hash->{SetFn} = "XiaomiSmartHome_Device_Set";
|
||||||
$hash->{UndefFn} = "XiaomiSmartHome_Device_Undef";
|
$hash->{UndefFn} = "XiaomiSmartHome_Device_Undef";
|
||||||
@@ -362,11 +362,20 @@ sub XiaomiSmartHome_Device_Read($$$){
|
|||||||
readingsBulkUpdate($hash, "arlarm", "$data->{curtain_level}", 1 );
|
readingsBulkUpdate($hash, "arlarm", "$data->{curtain_level}", 1 );
|
||||||
}
|
}
|
||||||
#curtain end
|
#curtain end
|
||||||
|
#vibration Start
|
||||||
|
if (defined $data->{'coordination'}){
|
||||||
|
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Coordination: " . $data->{coordination};
|
||||||
|
readingsBulkUpdate($hash, "coordination", "$data->{coordination}", 1 );
|
||||||
|
}
|
||||||
|
if (defined $data->{'final_tilt_angle'}){
|
||||||
|
Log3 $name, 3, "$name: DEV_Read>" . " Name: " . $hash->{NAME} . " SID: " . $sid . " Type: " . $hash->{MODEL} . " Final tilt angle: " . $data->{final_tilt_angle};
|
||||||
|
readingsBulkUpdate($hash, "final_tilt_angle", "$data->{final_tilt_angle}", 1 );
|
||||||
|
}
|
||||||
|
#vibration end
|
||||||
if ($decoded->{'cmd'} eq 'heartbeat'){
|
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};
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
UPD 2018-07-02_21:06:31 38896 FHEM/71_XiaomiSmartHome.pm
|
UPD 2018-09-09 12:43:14 39606 FHEM/71_XiaomiSmartHome.pm
|
||||||
UPD 2018-06-22_12:45:46 29142 FHEM/71_XiaomiSmartHome_Device.pm
|
UPD 2018-09-09 12:43:16 29789 FHEM/71_XiaomiSmartHome_Device.pm
|
||||||
|
|||||||
Reference in New Issue
Block a user