Phonetrack HomeAssistant GPS Logger Bridge

I threw together a quick way to bridge GPS data from the android app GPS Logger between HomeAssistant and the Nextcloud APP 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

Configuration

Node-Red

In HomeAssistant follow the instructions found here 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

Exported Config

[
    {
        "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 if anyone cares :wink:

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