# Phonetrack HomeAssistant GPS Logger Bridge

**URL:** <https://discourse.nodered.org/t/phonetrack-homeassistant-gps-logger-bridge/27690>\
**Category:** Share Your Projects\
**Created:** [3 June 2020 02:24 UTC](https://discourse.nodered.org/t/phonetrack-homeassistant-gps-logger-bridge/27690 "2020-06-03T02:24:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dugite-code](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dugite-code/32/3438_2.png) [@dugite-code](https://discourse.nodered.org/u/dugite-code)\
**Post date:** [3 June 2020 02:24 UTC](https://discourse.nodered.org/t/phonetrack-homeassistant-gps-logger-bridge/27690/1 "2020-06-03T02:24:23Z")

</div>

I threw together a quick way to bridge GPS data from the android app [GPS Logger](https://play.google.com/store/apps/details?id=com.mendhak.gpslogger) between HomeAssistant and the Nextcloud APP [Phonetrack](https://apps.nextcloud.com/apps/phonetrack).

Note: Returns the highest http response code thrown by either service, this can result in the GPS logger submitting multiple times if there is any issues with either Nextcloud or HomeAssistant

## Extra Nodes used

> **[node-red-contrib-httpauth](https://flows.nodered.org/node/node-red-contrib-httpauth)**
>
> Node which implements HTTP Basic/Digest Authorization.

> **[node-red-contrib-config](https://flows.nodered.org/node/node-red-contrib-config)**
>
> A node-red node to set flow and global context values at start up.

## Configuration

### Node-Red

In HomeAssistant follow the instructions found [here](https://www.home-assistant.io/integrations/gpslogger/) to obtain the GPS Logger web hook url and add this to the config node

In Nextcloud after creating a tacking session click the link icon and fetch the link labled `GpsLogger GET and POST link :` and add this to the config node

Edit the `http auth` Node with your desired credentials.

### GPS Logger

Go to `Logging details` -\> `Log to custom URL` -\> `URL` and add your Node-Red url: `https://example.tld/node-red/gps_logger?latitude=%LAT&longitude=%LON&device=[Your_Device_Name_Here]&accuracy=%ACC&battery=%BATT&speed=%SPD&direction=%DIR&altitude=%ALT&provider=%PROV&activity=%ACT&timestamp=%TIMESTAMP` - Note: edit the url and the [Your\_Device\_Name\_Here]

Go to `Logging details` -\> `Log to custom URL` -\> `Basic Authentication` add the username and password you set in the `http auth` node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d33d8423820aa89b0e1bce737429022b4150507.png)

## Exported Config

```auto
[
    {
        "id": "d3063735.81fee",
        "type": "http in",
        "z": "fa05d4c5.666e88",
        "name": "GPS Logger endpoint",
        "url": "/gps_logger",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 120,
        "y": 100,
        "wires": [
            [
                "48a06220.5ce424"
            ]
        ]
    },
    {
        "id": "eb378b88.eb2958",
        "type": "debug",
        "z": "fa05d4c5.666e88",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 1150,
        "y": 160,
        "wires": []
    },
    {
        "id": "40b34f9a.4db0d8",
        "type": "http request",
        "z": "fa05d4c5.666e88",
        "name": "Home Assistant",
        "method": "POST",
        "ret": "txt",
        "paytoqs": false,
        "url": "",
        "tls": "",
        "proxy": "",
        "authType": "",
        "x": 600,
        "y": 180,
        "wires": [
            [
                "17f901ca.f3d53e"
            ]
        ]
    },
    {
        "id": "1158aae0.cff345",
        "type": "change",
        "z": "fa05d4c5.666e88",
        "name": "Build HomeAssistant Query",
        "rules": [
            {
                "t": "set",
                "p": "headers",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "headers.content-type",
                "pt": "msg",
                "to": "application/x-www-form-urlencoded",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "url",
                "pt": "msg",
                "to": "homeassistant",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "\"latitude=\" & req.query.latitude & \"&longitude=\" & req.query.longitude & \"&device=\" & req.query.device & \"&accuracy=\" & req.query.accuracy & \"&battery=\" & req.query.battery & \"&speed=\" & req.query.speed & \"&direction=\" & req.query.direction & \"&altitude=\" & req.query.altitude & \"&provider=\" & req.query.provider & \"&activity=\" & req.query.activity",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 180,
        "wires": [
            [
                "40b34f9a.4db0d8"
            ]
        ]
    },
    {
        "id": "8c050501.4c0588",
        "type": "change",
        "z": "fa05d4c5.666e88",
        "name": "Set Phonetrack URL",
        "rules": [
            {
                "t": "set",
                "p": "url",
                "pt": "msg",
                "to": "$flowContext(\"phonetrack\") & req.query.device & \"?lat=\" & req.query.latitude & \"&lon=\" & req.query.longitude & \"&acc=\" & req.query.accuracy & \"&speed=\" & req.query.speed & \"&bearing=\" & req.query.direction & \"&timestamp=\" & req.query.timestamp & \"&battery=\" & req.query.battery",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 360,
        "y": 140,
        "wires": [
            [
                "6ff30b79.a22e7c"
            ]
        ]
    },
    {
        "id": "6ff30b79.a22e7c",
        "type": "http request",
        "z": "fa05d4c5.666e88",
        "name": "PhoneTrack",
        "method": "POST",
        "ret": "txt",
        "paytoqs": false,
        "url": "",
        "tls": "",
        "proxy": "",
        "authType": "",
        "x": 590,
        "y": 140,
        "wires": [
            [
                "17f901ca.f3d53e"
            ]
        ]
    },
    {
        "id": "dca86ae7.b81fb8",
        "type": "http response",
        "z": "fa05d4c5.666e88",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 1150,
        "y": 200,
        "wires": []
    },
    {
        "id": "198786f0.04cbd1",
        "type": "config",
        "z": "fa05d4c5.666e88",
        "name": "URLS",
        "properties": [
            {
                "p": "phonetrack",
                "pt": "flow",
                "to": "https://example.tld/apps/phonetrack/log/gpslogger/ __phonetrackid__ /",
                "tot": "str"
            },
            {
                "p": "homeassistant",
                "pt": "flow",
                "to": "https://home.example.tld/api/webhook/ __webhookkey__",
                "tot": "str"
            }
        ],
        "active": true,
        "x": 90,
        "y": 60,
        "wires": []
    },
    {
        "id": "17f901ca.f3d53e",
        "type": "join",
        "z": "fa05d4c5.666e88",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "statusCode",
        "propertyType": "msg",
        "key": "url",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 790,
        "y": 160,
        "wires": [
            [
                "97160453.f48fa"
            ]
        ]
    },
    {
        "id": "97160453.f48fa",
        "type": "change",
        "z": "fa05d4c5.666e88",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "statusCode",
                "pt": "msg",
                "to": "$max(statusCode.$number())",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 940,
        "y": 160,
        "wires": [
            [
                "7b71caeb.a9fcdc"
            ]
        ]
    },
    {
        "id": "cd4374b1.ed507",
        "type": "comment",
        "z": "fa05d4c5.666e88",
        "name": "Set URLS for HomeAssistant and PhoneTrack",
        "info": "",
        "x": 190,
        "y": 20,
        "wires": []
    },
    {
        "id": "7b71caeb.a9fcdc",
        "type": "switch",
        "z": "fa05d4c5.666e88",
        "name": "",
        "property": "statusCode",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "200",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 970,
        "y": 200,
        "wires": [
            [
                "eb378b88.eb2958",
                "dca86ae7.b81fb8"
            ],
            [
                "dca86ae7.b81fb8"
            ]
        ]
    },
    {
        "id": "48a06220.5ce424",
        "type": "node-red-contrib-httpauth",
        "z": "fa05d4c5.666e88",
        "name": "",
        "file": "",
        "cred": "",
        "authType": "Basic",
        "realm": "",
        "username": "",
        "password": "",
        "hashed": false,
        "x": 160,
        "y": 140,
        "wires": [
            [
                "8c050501.4c0588",
                "1158aae0.cff345"
            ]
        ]
    }
]

```

I've mirrored this post onto [my blog](https://peekread.info/tech/20200603-node-red-phonetrack-homeassistant-bridge/) if anyone cares 😉

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 August 2020 02:24 UTC](https://discourse.nodered.org/t/phonetrack-homeassistant-gps-logger-bridge/27690/2 "2020-08-02T02:24:30Z")

</div>

This topic was automatically closed after 60 days. New replies are no longer allowed.
