2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

RESIDENTStk: Support for updated GEOFANCY version

git-svn-id: https://svn.fhem.de/fhem/trunk@17575 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2018-10-20 15:15:48 +00:00
parent a5a895a4c9
commit 79c7d6be88
3 changed files with 116 additions and 41 deletions

View File

@ -1,9 +1,10 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- change: ROOMMATE, GUEST: Support for updated GEOFANCY version
- feature: 98_GEOFANCY: add new reading LocTravDist; add support for - feature: 98_GEOFANCY: add new reading LocTravDist; add support for
Geofency.app webhook attributes currentLatitude, Geofency.app webhook attributes radius, currentLatitude,
currentLongitude, motion, wifiSSID and wifiBSSID. currentLongitude, motion, wifiSSID and wifiBSSID.
New readings: PosBSSID, PosLat, PosHomeDist, PosLocDist, New readings: PosBSSID, PosLat, PosDistHome, PosDistLoc,
PosLong, PosMotion, PosSSID, PosTravDist PosLong, PosMotion, PosSSID, PosTravDist
- bugfix: 98_GEOFANCY: fixed last* readings - bugfix: 98_GEOFANCY: fixed last* readings
- feature: 89_FULLY: New commands for sound playback and photo. - feature: 89_FULLY: New commands for sound playback and photo.

View File

@ -116,8 +116,9 @@ sub GEOFANCY_CGI() {
my $date = ""; my $date = "";
my $time = ""; my $time = "";
my $locName = ""; my $locName = "";
my $posLocDist = ""; my $radius = "";
my $posHomeDist = ""; my $posDistLoc = "";
my $posDistHome = "";
my $locTravDist = ""; my $locTravDist = "";
my $motion = ""; my $motion = "";
my $wifiSSID = ""; my $wifiSSID = "";
@ -314,10 +315,10 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
"unknown", "stationary", "walking", "running", "unknown", "stationary", "walking", "running",
"automotive", "cycling" "automotive", "cycling"
); );
my $motion = lc( $webArgs->{motion} ); my $motionLc = lc( $webArgs->{motion} );
return ( "text/plain; charset=utf-8", return ( "text/plain; charset=utf-8",
"NOK Unknown motion type '" . $webArgs->{motion} . "'" ) "NOK Unknown motion type '" . $webArgs->{motion} . "'" )
if ( !grep( /^$motion$/, @motions ) ); if ( !grep( /^$motionLc$/, @motions ) );
} }
# Locative.app # Locative.app
@ -345,6 +346,8 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
$date = GEOFANCY_ISO8601UTCtoLocal( $webArgs->{date} ); $date = GEOFANCY_ISO8601UTCtoLocal( $webArgs->{date} );
$lat = $webArgs->{latitude}; $lat = $webArgs->{latitude};
$long = $webArgs->{longitude}; $long = $webArgs->{longitude};
$radius = $webArgs->{radius}
if ( defined( $webArgs->{radius} ) );
$address = $webArgs->{address} $address = $webArgs->{address}
if ( defined( $webArgs->{address} ) ); if ( defined( $webArgs->{address} ) );
$device = $webArgs->{device}; $device = $webArgs->{device};
@ -493,18 +496,18 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
if ( $homeLat && $homeLong ) { if ( $homeLat && $homeLong ) {
Debug "$homeLat $homeLong"; Debug "$homeLat $homeLong";
if ( $posLat ne "" && $posLong ne "" ) { if ( $posLat ne "" && $posLong ne "" ) {
$posHomeDist = $posDistHome =
UConv::distance( $posLat, $posLong, $homeLat, $homeLong, 2 ); UConv::distance( $posLat, $posLong, $homeLat, $homeLong, 2 );
} }
elsif ( $lat ne "" && $long ne "" ) { elsif ( $lat ne "" && $long ne "" ) {
$posHomeDist = $posDistHome =
UConv::distance( $lat, $long, $homeLat, $homeLong, 2 ); UConv::distance( $lat, $long, $homeLat, $homeLong, 2 );
} }
} }
# distance between location and position # distance between location and position
if ( $lat ne "" && $long ne "" && $posLat ne "" && $posLong ne "" ) { if ( $lat ne "" && $long ne "" && $posLat ne "" && $posLong ne "" ) {
$posLocDist = UConv::distance( $posLat, $posLong, $lat, $long, 2 ); $posDistLoc = UConv::distance( $posLat, $posLong, $lat, $long, 2 );
} }
# travelled distance for location # travelled distance for location
@ -579,15 +582,16 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
# backup last known position # backup last known position
foreach ( foreach (
'PosSSID', 'PosBSSID', 'PosMotion', 'PosSSID', 'PosBSSID', 'PosMotion', 'PosLat',
'PosLat', 'PosLong', 'PosHomeDist', 'PosLong', 'PosDistHome', 'PosDistLoc', 'PosTravDist',
'PosLocDist', 'PosTravDist', 'LocTravDist' 'LocTravDist', 'LocRadius'
) )
{ {
$currReading = "curr" . $_ . "_" . $deviceAlias; $currReading = "curr" . $_ . "_" . $deviceAlias;
$lastReading = "last" . $_ . "_" . $deviceAlias; $lastReading = "last" . $_ . "_" . $deviceAlias;
$currVal = ReadingsVal( $name, $currReading, "" ); $currVal = ReadingsVal( $name, $currReading, undef );
readingsBulkUpdate( $hash, $lastReading, $currVal ); readingsBulkUpdate( $hash, $lastReading, $currVal )
if ( defined($currVal) );
} }
readingsBulkUpdate( $hash, "currPosSSID_" . $deviceAlias, $wifiSSID ); readingsBulkUpdate( $hash, "currPosSSID_" . $deviceAlias, $wifiSSID );
@ -595,15 +599,17 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
readingsBulkUpdate( $hash, "currPosMotion_" . $deviceAlias, $motion ); readingsBulkUpdate( $hash, "currPosMotion_" . $deviceAlias, $motion );
readingsBulkUpdate( $hash, "currPosLat_" . $deviceAlias, $posLat ); readingsBulkUpdate( $hash, "currPosLat_" . $deviceAlias, $posLat );
readingsBulkUpdate( $hash, "currPosLong_" . $deviceAlias, $posLong ); readingsBulkUpdate( $hash, "currPosLong_" . $deviceAlias, $posLong );
readingsBulkUpdate( $hash, "currPosHomeDist_" . $deviceAlias, readingsBulkUpdate( $hash, "currPosDistHome_" . $deviceAlias,
$posHomeDist ); $posDistHome );
readingsBulkUpdate( $hash, "currPosLocDist_" . $deviceAlias, readingsBulkUpdate( $hash, "currPosDistLoc_" . $deviceAlias,
$posLocDist ); $posDistLoc );
readingsBulkUpdate( $hash, "currLocTravDist_" . $deviceAlias, readingsBulkUpdate( $hash, "currLocTravDist_" . $deviceAlias,
$locTravDist ); $locTravDist );
readingsBulkUpdate( $hash, "currPosTravDist_" . $deviceAlias, readingsBulkUpdate( $hash, "currPosTravDist_" . $deviceAlias,
$posTravDist ); $posTravDist );
readingsBulkUpdate( $hash, "currLocRadius_" . $deviceAlias, $radius );
if ( lc($entry) eq "enter" if ( lc($entry) eq "enter"
|| lc($entry) eq "1" || lc($entry) eq "1"
|| lc($entry) eq "entered" || lc($entry) eq "entered"
@ -666,10 +672,10 @@ m/(19|20)\d\d-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([0-1][0-9]|2[0-3]):([0-5
$locName = $id if ( $locName eq "" ); $locName = $id if ( $locName eq "" );
RESIDENTStk_SetLocation( RESIDENTStk_SetLocation(
$deviceAlias, $locName, $trigger, $id, $deviceAlias, $locName, $trigger, $id,
$time, $lat, $long, $address, $time, $lat, $long, $address,
$device, $posLat, $posLong, $posLocDist, $device, $radius, $posLat, $posLong, $posDistHome,
$motion, $wifiSSID, $wifiBSSID $posDistLoc, $motion, $wifiSSID, $wifiBSSID
) if ( IsDevice( $deviceAlias, "ROOMMATE|GUEST" ) ); ) if ( IsDevice( $deviceAlias, "ROOMMATE|GUEST" ) );
} }

View File

@ -1478,29 +1478,40 @@ sub RESIDENTStk_DurationTimer($;$) {
sub RESIDENTStk_SetLocation(@) { sub RESIDENTStk_SetLocation(@) {
my ( my (
$name, $location, $trigger, $id, $time, $name, $location, $trigger, $id, $time,
$lat, $long, $address, $device, $posLat, $lat, $long, $address, $device, $radius,
$posLong, $posLocDist, $motion, $wifiSSID, $wifiBSSID $posLat, $posLong, $posDistHome, $posDistLoc, $motion,
$wifiSSID, $wifiBSSID
) = @_; ) = @_;
my $hash = $defs{$name}; my $hash = $defs{$name};
my $TYPE = GetType($name); my $TYPE = GetType($name);
my $prefix = RESIDENTStk_GetPrefixFromType($name); my $prefix = RESIDENTStk_GetPrefixFromType($name);
my $state = ReadingsVal( $name, "state", "initialized" ); my $state = ReadingsVal( $name, "state", "initialized" );
my $presence = ReadingsVal( $name, "presence", "present" ); my $presence = ReadingsVal( $name, "presence", "present" );
my $currLocation = ReadingsVal( $name, "location", "-" ); my $currLocation = ReadingsVal( $name, "location", "-" );
my $currWayhome = ReadingsVal( $name, "wayhome", "0" ); my $currWayhome = ReadingsVal( $name, "wayhome", "0" );
my $currLat = ReadingsVal( $name, "locationLat", "-" ); my $currLat = ReadingsVal( $name, "locationLat", "-" );
my $currLong = ReadingsVal( $name, "locationLong", "-" ); my $currLong = ReadingsVal( $name, "locationLong", "-" );
my $currAddr = ReadingsVal( $name, "locationAddr", "" ); my $currRadius = ReadingsVal( $name, "locationRadius", "" );
my $currAddr = ReadingsVal( $name, "locationAddr", "" );
my $currPosLat = ReadingsVal( $name, "positionLat", "" );
my $currPosLong = ReadingsVal( $name, "positionLong", "" );
my $currPosDistHome = ReadingsVal( $name, "positionDistHome", "" );
my $currPosDistLoc = ReadingsVal( $name, "positionDistLocation", "" );
my $currPosMotion = ReadingsVal( $name, "positionMotion", "" );
my $currPosSSID = ReadingsVal( $name, "positionSSID", "" );
my $currPosBSSID = ReadingsVal( $name, "positionBSSID", "" );
$id = "-" if ( !$id || $id eq "" ); $id = "-" if ( !$id || $id eq "" );
$lat = "-" if ( !$lat || $lat eq "" ); $lat = "-" if ( !$lat || $lat eq "" );
$long = "-" if ( !$long || $long eq "" ); $long = "-" if ( !$long || $long eq "" );
$address = "" if ( !$address ); $address = "" if ( !$address );
$time = "" if ( !$time ); $time = "" if ( !$time );
$device = "" if ( !$device ); $device = "" if ( !$device );
$posLat = "" if ( !$posLat || $posLat eq "-" );
$posLong = "" if ( !$posLong || $posLong eq "-" );
Log3 $name, 5, Log3 $name, 5,
"$TYPE $name: received location information: id=$id name=$location trig=$trigger date=$time lat=$lat long=$long address:$address device=$device"; "$TYPE $name: received location information: id=$id name=$location trig=$trigger date=$time lat=$lat long=$long posLat=$posLat posLong=$posLong address:$address device=$device";
my $searchstring; my $searchstring;
@ -1522,6 +1533,61 @@ sub RESIDENTStk_SetLocation(@) {
readingsBulkUpdate( $hash, "locationPresence", "absent" ) readingsBulkUpdate( $hash, "locationPresence", "absent" )
if ( $trigger == 0 ); if ( $trigger == 0 );
# travelled distance for location
my $locTravDist = "";
if ( $lat ne "" && $long ne "" ) {
my $locLatVal = ReadingsVal( $name, "locationLat", "-" );
$locLatVal = ReadingsVal( $name, "lastLocationLat", "-" )
if ( $locLatVal eq "-" );
my $locLongVal = ReadingsVal( $name, "locationLong", "-" );
$locLongVal = ReadingsVal( $name, "lastLocationLong", "-" )
if ( $locLongVal eq "-" );
if ( $locLatVal ne "-" && $locLongVal ne "-" ) {
$locTravDist =
UConv::distance( $lat, $long, $locLatVal, $locLongVal, 2 );
}
}
# travelled distance for position
my $posTravDist = "";
if ( $posLat ne "" && $posLong ne "" ) {
my $currPosLatVal = ReadingsVal( $name, "positionLat", "" );
my $currPosLongVal = ReadingsVal( $name, "positionLong", "" );
if ( $currPosLatVal ne "" && $currPosLongVal ne "" ) {
$posTravDist = UConv::distance( $posLat, $posLong, $currPosLatVal,
$currPosLongVal, 2 );
}
}
# backup last known position
foreach (
'positionLat', 'positionLong',
'positionDistHome', 'positionDistLocation',
'positionMotion', 'positionSSID',
'positionBSSID', 'positionTravDistance',
'locationTravDistance'
)
{
my $currReading = $_;
my $lastReading = "last" . $_;
my $currVal = ReadingsVal( $name, $currReading, undef );
readingsBulkUpdate( $hash, $lastReading, $currVal )
if ( defined($currVal) );
}
# update position based readings
readingsBulkUpdate( $hash, "positionLat", $posLat );
readingsBulkUpdate( $hash, "positionLong", $posLong );
readingsBulkUpdate( $hash, "positionDistHome", $posDistHome );
readingsBulkUpdate( $hash, "positionDistLocation", $posDistLoc );
readingsBulkUpdate( $hash, "positionMotion", $motion );
readingsBulkUpdate( $hash, "positionSSID", $wifiSSID );
readingsBulkUpdate( $hash, "positionBSSID", $wifiBSSID );
readingsBulkUpdate( $hash, "positionTravDistance", $posTravDist );
readingsBulkUpdate( $hash, "locationTravDistance", $locTravDist );
# check for implicit state change # check for implicit state change
# #
my $stateChange = 0; my $stateChange = 0;
@ -1633,15 +1699,17 @@ sub RESIDENTStk_SetLocation(@) {
) )
{ {
Log3 $name, 5, "$TYPE $name: archiving last known location"; Log3 $name, 5, "$TYPE $name: archiving last known location";
readingsBulkUpdate( $hash, "lastLocationLat", $currLat ); readingsBulkUpdate( $hash, "lastLocationLat", $currLat );
readingsBulkUpdate( $hash, "lastLocationLong", $currLong ); readingsBulkUpdate( $hash, "lastLocationLong", $currLong );
readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr ) readingsBulkUpdate( $hash, "lastLocationRadius", $currRadius );
readingsBulkUpdate( $hash, "lastLocationAddr", $currAddr )
if ( $currAddr ne "" ); if ( $currAddr ne "" );
readingsBulkUpdate( $hash, "lastLocation", $currLocation ); readingsBulkUpdate( $hash, "lastLocation", $currLocation );
} }
readingsBulkUpdate( $hash, "locationLat", $lat ); readingsBulkUpdate( $hash, "locationLat", $lat );
readingsBulkUpdate( $hash, "locationLong", $long ); readingsBulkUpdate( $hash, "locationLong", $long );
readingsBulkUpdate( $hash, "locationRadius", $radius );
if ( $address ne "" ) { if ( $address ne "" ) {
readingsBulkUpdate( $hash, "locationAddr", $address ); readingsBulkUpdate( $hash, "locationAddr", $address );