Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added trigger filtering capabilities to the location node for specific events #4

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
## Life360.
# Life360

[Life360](https://www.life360.com) is an iOS/Android app for location tracking and geofencing your own (and friends'/family) location. It has a multitude of features, but this repo is explicitly for triggering home automations in [Node Red](http://nodered.org). It mimmicks the triggers available in the [IFTTT Life360 service](http://ifttt.com/life360) by providing triggers for:

- A specific person leaves or arrives at a specific (or any) place
- Any person (in a Life360 "circle") leaves or arrives at a specific (or any) place
- First person (in a Life360 "circle") arrives at a specific place
- Last person (in a Life360 "circle") leaves a specific place
- Any person in any circle leaves/arrives at a specific (or any) place

This package adds 2 nodes to Node Red:

- Server node (which contains login credentials and communicates with Life360)
- Location node (which contains the rules for specifying the types of events to output)
48 changes: 47 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module.exports.circles = function (session) {
request(options)
.then(response => {
let circles = response.body.circles;
//console.log("Returning circles: " + JSON.stringify(circles));
resolve(circles);
});
});
Expand Down Expand Up @@ -99,4 +100,49 @@ module.exports.circle = function (session, circleId) {
resolve(circle);
});
});
}
}

/**
* Fetch the user's places
*/
module.exports.places = function (session, circleId) {
if (!session) throw new Error("session not specified");
return new Promise((resolve, reject) => {
const LIFE360_PLACES_URL = `https://api.life360.com/v3/circles/${circleId}/allplaces`
const options = {
url: LIFE360_PLACES_URL,
headers: {
'Authorization': `${session.token_type} ${session.access_token}`
},
json: true
};
// console.log(`Fetching places at ${LIFE360_PLACES_URL}`);
request(options)
.then(response => {
let places = response.body.places;
resolve(places);
});
});
}

/**
* Fetch the user's members
*/
module.exports.members = function (session, circleId) {
if (!session) throw new Error("session not specified");
return new Promise((resolve, reject) => {
const LIFE360_MEMBERS_URL = `https://api.life360.com/v3/circles/${circleId}/members`
const options = {
url: LIFE360_MEMBERS_URL,
headers: {
'Authorization': `${session.token_type} ${session.access_token}`
},
json: true
};
request(options)
.then(response => {
let members = response.body.members;
resolve(members);
});
});
}
Loading