Where Do You Stand On Presence?

Still just using Owntracks on Android and it is absolutely perfect for me. Love it.

1 Like

In the script, I just looked for the hubitat endpoint and updated to point to an http in node:

For the script I modified, it just looked like this:

# Change your IP and Port here :
#URL_HUBITAT = 'http://192.168.1.xx/apps/api/414/location/?user=PARAM_NAME&location=PARAM_IDX&cmd=PARAM_CMD&access_toke$
URL_HUBITAT = 'http://<yourIPhere>:1880/tile/?pi=LivingRoom&user=PARAM_NAME&location=PARAM_IDX&cmd=PARAM_CMD'

I then feed that into a function node with the following code (ignore Unifi portions):

var tName;
var tDevice;
var tAction;

//set tName based on topic
if (msg.topic == "Tile") {
    tName = msg.req.query.user;
    tDevice = msg.req.query.pi;
    if (msg.req.query.cmd == "HOME") {
        tAction = "CONNECTED";
    } else if (msg.req.query.cmd = "AWAY") {
        tAction = "DISCONNECTED";
    }
}
if (msg.topic == "Unifi") {
    tName = global.get("wifiDevices", "file")[msg.payload.data[0].user];
    tDevice = msg.payload.data[0].user;
    if (msg.payload.data[0].key == "EVT_WU_Connected") {
        tAction = "CONNECTED";
    } else if (msg.payload.data[0].key = "EVT_WU_Disconnected") {
        tAction = "DISCONNECTED";
    }
    //console.log(tName + " - " + tDevice + " - " + msg.payload.data[0].key);
}
if (msg.topic == "UnifiBackup") {
    tName = msg.payload.user;
    tDevice = msg.payload.device;
    tAction = msg.payload.value;
}

//define global name and initialize
var varName = "tile" + tName;
if (global.get(varName,"file") === undefined) {
    global.set(varName,[],"file");
}

//pull global into working variable
var tArray = global.get(varName,"file");

//determine presence based on topic
if (tAction == "CONNECTED") {
    let pos = tArray.indexOf(tDevice);
    if (pos == -1) {
        let newLength = tArray.push(tDevice);
    }
} else if (tAction == "DISCONNECTED") {
    let pos = tArray.indexOf(tDevice);
    if (pos >= 0) {
        let removedValue = tArray.splice(pos, 1);
    }
}

//re-file array into global
global.set(varName,tArray,"file");

//define new output message
var newMsg = {}

//populate new message
newMsg.topic = msg.topic;
newMsg.payload = {};
newMsg.payload.user = tName;
newMsg.payload.action = tAction;
newMsg.payload.modality = msg.topic;
if (tArray.length == 0) {
    newMsg.payload.value = "AWAY";
    newMsg.command = "departed";
} else {
    newMsg.payload.value = "HOME";
    newMsg.command = "arrived";
}

return newMsg;

That newMsg payload can then be sent to virtual presence devices in Hubitat via MakerAPI. You don't really need to do that unless you utilize presence devices in Rule Machine though.

1 Like

Nice - I will give that a go. At the moment there are quite a few events being generated by the various beacons (and x3 due to the added receivers) so offloading all this to node red and simply reporting the final presence state to HE will cut this down quite a bit.

That's all I use is the ST and AA mod.
If I have the wife put the sensor in her purse so if we leave together the house always sees both of us leave.

Is this 'Locative' an app that's only available in certain regions perhaps? I can't find it on the UK on the App Store.

Edit: Found it. Stupid App Store! Searching 'Locative' it doesn't show up. I had to type in the developer instead in the search "Bearologics' and it's the first result.

2 Likes

Others to consider (they both work well and I believe use similar methods as Locative):

Geofency

Owntracks

2 Likes

I don't suppose there's a guide anywhere on how to setup Locative with Hubitat for presence? I've installed the app and set up the geofence but have no idea what to enter for the 'Webhook on arrival' and 'Webhook on departure'. I've never done anything with http get or post as yet :confused:

1 Like

Would you not make use of Maker API? Using the URL's it sets up to adjust a virtual presence sensor?

Yeah I've created an instance of maker api (not sure whether I need one for arrival and another for departure). I've added a virtual presence sensor. I'm also not sure which of the multiple maker api cloud urls I need to add as the server.

You can get tge device it from the device edit page, just look at the url in the address bar.

You won't need a separate instance for arrival and departure.

You want to use the url for issuing a command. Check back on the device edit page, I think it's arrived and departed are the two commands. You can test this in a browser by pasting the url you construct into the address bar, having replaced things like the device id and command name. You won't need the secondary value.

I can find an example if you need one.

1 Like

Thanks - I found that if you put the devices page in grid instead of list view, the device ID is shown for all devices there.

That makes sense - I'll have a play and come back if I get stuck.

Edit: In maker do I want the url for get device command or send device command? In the Locative app do I select GET or POST. Apologies for the dum****s questions!

1 Like

Here is the original Locative thread, with some instructions for use.

4 Likes

Thanks @ogiewon I've had a look through that thread.

I changed the global http settings to GET and pasted the maker api cloud url's in one at a time and clicked the 'Send Test-Request' link. Both departed and arrived messages popped up on my iPhone and the logs show that my virtual presence sensor updated with each test so that looks good.

I take it that once I've tested it as above I need to delete the url I pasted into the Global http settings (as they are entered in the Locations section)?

3 Likes

You can leave the URL in the global settings section. It will not cause any harm.

1 Like

I didn’t find it by searching in the App Store either. I googled the site and then used the AppStore link from their webpage.

1 Like

I had the same issue searching for Locative - The Developer name brought it up.

2 Likes

Even though I have it working with cloud links I think I am going to use this as a test to try using the makerAPI for the first time.

Thanks for the details and the link to the previous thread.

1 Like

I'm cheering you on. You may recall from my previous question that I couldn't find a way to surface the webhook payload in RM. Maybe that's something that can be done in MakerAPI and you'll share.

1 Like

You could write your own OAuth2 enabled App, which would allow it to use cloud endpoints. This would provide much more control over parsing the data coming from Locative.

1 Like

I'm surprised how accurate the geofence in Locative is and how snappy it actions in Hubitat via maker. I've set my Home radius to 100m and decided to check it via the logs and my CCTV. The virtual presence sensor I created in Hubitat showed 'arrived' in the logs at 13:27:53 and when I checked playback of my camera at that moment (synced via NTP) I could see my car approaching right on the geofence perimeter....I'm impressed :grinning:

2 Likes