house-of-abbey / GarminHomeAssistant

Garmin application to provide a dashboard to control your Home Assistant
https://community.home-assistant.io/t/home-assistant-app-for-garmin/637348
MIT License
70 stars 12 forks source link

Add GPS reporting to the background service #94

Closed philipabbey closed 6 months ago

philipabbey commented 6 months ago

User request from https://community.home-assistant.io/t/home-assistant-app-for-garmin/637348/150

would it be possible to report gps coordinates as well?

So the background service would report both battery level, charging state and now GPS too. There could be a dependency on the granularity of the GPS since workout Apps usually take a while to pick up satelites and refine the GPS to a few meters, and the battery is in greater demand at these higher accuracies.

philipabbey commented 6 months ago

Looking trivial to extract from the watch:

var myLocation = Position.getInfo().position.toDegrees();
System.println("Position, lat:  " + myLocation[0] + " long: " + myLocation[1]);

@JosephAbbey What's the best way to include this in the API call?

            Communications.makeWebRequest(
                (Properties.getValue("api_url") as Lang.String) + "/webhook/" + (Properties.getValue("webhook_id") as Lang.String),
                {
                    "type" => "update_sensor_states",
                    "data" => [
                        {
                            "state"     => System.getSystemStats().battery,
                            "type"      => "sensor",
                            "unique_id" => "battery_level"
                        },
                        {
                            "state"     => System.getSystemStats().charging,
                            "type"      => "binary_sensor",
                            "unique_id" => "battery_is_charging"
                        }
                    ]
                },
                {
                    :method       => Communications.HTTP_REQUEST_METHOD_POST,
                    :headers      => {
                        "Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON
                    },
                    :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
                },
                method(:onReturnBatteryUpdate)
            );

I can then test on a real device.

JosephAbbey commented 6 months ago

You would also need to amend the WebhookManager setup to include it as a sensor.

Although, the official way is to use a separate request, as seen here, this creates an actual device tracker in homeassistant, rather than a sensor.

I currently have a version that includes the current activity type on my local branch which uses the original request.