Home Assistant App for Garmin

Right, these struggles indicate some actions I shall take shortly:

  1. Suggest Studio Code Server is installed for editing against the JSON schema
  2. On error INVALID_HTTP_BODY_IN_NETWORK_RESPONSE, perform a follow up repeat call with a plain text response expectation in order to display the error message received. This is however not as trivial as you might expect due to the way HTTP calls are made with asynchronous callback methods and how that affects the flow of control.

Hi. Not sure if posting in the correct place.
This is a great app for garmin
But the new timeout value introduced in v1.6 is not working for me.
No error, no app exit either
My json, after schema, reads:

  "title": "Home",
  "timeout": 5,
  "items": [

is it ok?
can you update the sample schema in case it should be build differently?
thanks

Hi @alanwe,

I think this is the best place to post, then others can benefit from our conversation.
The new timeout feature is a global setting in the App settings rather than the JSON. It defaults to zero (disabled), so you should be able to amend it from there.

Thank you for the compliment.

Hi @NP_Complete ,
I found the setting in the app settings. Everything ok.
I would like to suggest if you can reset the timeout counter while scrolling the screen.
When you are scrolling your items list, just looking at their states, the app closes.
It would be better if you start counting when there is no user interaction.
Another idea… watch screen wakes up when you rotate your wrist towards your face.
And turns off when you rotate away of your face.
If you can detect that gesture, you can exit the app on that trigger too.
Thanks, and nice work.

Yes indeed, however that is not possible. I tried. The solution here is the best simple one, so I suggest increasing the timeout value, e.g. 60s. I don’t get any scroll events from the menu interactions.

Another idea… watch screen wakes up when you rotate your wrist towards your face.

We also had the same other ideas. It would be nice, but again we can’t find a way to hook any screen on/off events.

Sorry.

1 Like

Does the watch app support locks?

Or only the entity types listed in the table in the documentation?

I suppose I should create a lock toggle script if not.

I believe it does because one user submitted a Github pull request to ask for confirmation view timeout precisely to limit the risk further with sensitive devices. I personally would not advise it, but that’s your choice. So the current mitigations are:

  1. Optional confirmation of action
  2. Timeout on that confirmation (e.g. 3 secs, can be disabled)

The entity types are just that, entities. Best try it and see if it does what you want.

1 Like

HI! I installed the app and entered all the fields but I have this error: no response, check internet connection. I confirm that the cell phone is connected via BT to the telephone.

Hi there!

Sorry to say, it looks pretty much as the error message says.

The error is caused by a Communications.NETWORK_REQUEST_TIMED_OUT response code. The app is unable to fetch the data it needs. You need to work the Internet connection lead a fair bit more. E.g. can you reach your menu definition from a web browser? Are the URLs correct? No I mean really correct, really really! There have been a few mistyped and failed copies resolved by correcting the URLs and API keys. Find some software that allows copy & paste of the text fields to your watch. For example I use Microsoft Windows “Phone Link” software for my Android phone.

Good Luck!

thanks for the reply: for confirmation I’ll list the fields I entered:
url home assistant api: https://192.168.1.145/api
url jason: https://192.168.1.145/config/www/garmin/home.json
I tried to put the api link as: https://192.168.1.145:8123/api but the browser gives me 404: Not Found

I’m definitely doing something wrong but I don’t know what…

1 Like

192.168.1.145 is a private LAN IP address not accessible from the public Internet. This means it will only work on your private LAN. If you want this URL to work from anywhere, you need to setup your Home Assistant to be operable publically and supply the correct public domain name or IP address. Are you using mobile data to access this URL? Try you local LAN Wi-Fi instead.

How you achieve the functioning URLs is left to the user alone. Everyone’s circumstances are slightly different hence its your responsibility to get the working URLs.

You might like to setup Dynamic DNS and port forwarding on your router. That is out of scope of this thread! There are lots of help articles on the Internet.

https://192.168.1.145/config/www/garmin/home.json

Did you mean https://192.168.1.145/local/garmin/home.json as per the example in the README linked above?

Good luck!

1 Like

If anyone is struggling to test their API access, here’s a Bash script I used on my Raspberry Pi to test the connection:

#!/bin/bash

API_KEY="<Your API key>"
URL="https://<Your Domain>/api"

curl -s -X GET \
  -H "Authorization: Bearer ${API_KEY}" \
  -H "Content-Type: application/json" \
  ${URL}/

This should return the following JSON formatted ASCII text:

{"message":"API running."}

If you get that response then ${URL} without the trailing \ is the correct API URL. But you do need to use the ${API_KEY} in that call, hence it won’t just work from a browser address bar.

I did it! it was a wrong address of the json file! A thousand thanks!

ps: Can you just confirm that I can’t ask for confirmation of the lights and switches? but they are about scenes and automations

Its worth noting that I have posted the API error codes link above several times, see Toybox.Communications.

A little more information is required to understand the causes. The -400 suggests that the responce returned something other than JSON, e.g. a plain text error code. Limitations of the Connect IQ API calls mean I can’t retrieve that after the response has been processed. So all we know is that the HTTP request was not JSON.

Further:

This URL should be publically accesible now, and no API key is required to access the menu definition as it is not served by the HomeAssistant API, the URL can in fact be anywhere on the Internet. But it is most convenient to have it all served by the Home Assistant web server (outside the HA API). When I click that link I get an HTTP response code:

This site can’t be reached

mydomain.duckdns.org took too long to respond.

ERR_CONNECTION_TIMED_OUT

So the URL still is not working. It might be correct, but I’m guessing you’ve not yet looked into setting up port forwarding on your router as I suggested above.

I think you need to setup port forwarding for HTTPS to your HomeAssistant IP address. That means you need:

  1. HomeAssistant to be allocated a permanent / fixed IP address by DHCP. This is based on a mapping of MAC address to IP address (192.168.1.145).
  2. You need HTTPS port 443 forwarded to that fixed IP address (192.168.1.145).

Then you might have a chance of an external HTTPS request reaching your HomeAssistant. But your setup might still have a web proxy, e.g. converting HTTPS to HTTP internally in your network before the HomeAssistant webserver. You need to follow this through and see where the HTTP GET request for the menu configuration is getting lost.

Once you have the menu being served to the web browser, you might have a chance of reaching the HomeAssistant API URL. But that test requires the API_KEY, and is therefore slightly harder.

Much of this is more about how to manage TCP/IP on your LAN rather than the actual Garmin application, and there are better thought out tutorials on forwarding web requests from public to private networks already on the Internet than my potted explanation here.

1 Like

For those without a Raspberry Pi or other Linux box to hand, the Bash script above can be converted to Windows batch file as follows.

@echo off

set API_KEY=<Your API key>
set URL=https://<Your Domain>/api

curl -s -X GET ^
  -H "Authorization: Bearer %API_KEY%" ^
  -H "Content-Type: application/json" ^
  %URL%/

echo.
pause

This assume a modern installation of Windows with curl on the PATH by default.

image

Finally, there’s an online way of testing the API URL too, thanks to REQBIN.

Just make sure you add the trailing \ to the URL for this test, and then remove it for the correct API URL on success.

There are no confirmations on toggles. I’m not sure how we would do that, perhaps using a custom menu item class, and that’s a whole load of pain given we can currently use one out of a box for the current behaviour.

Confirmations were introduced for scenes and automations.

You could separate the toggle into two items, one for ‘on’ with an optional confirmation and one for ‘off’ with an optional confirmation.

Did anyone else manage to get app working with nabu casa? I checkd URLS, json files on web, and it is working.

Yes we did. We took out a free trial of Nabu Casa solely to find out why others might be struggling. We got it working in 5 minutes. Well, that’s the good news, the bad news is we did not discover why othersa were struggling!

As per the README.md linked above

If you are struggling with getting the application to work, please consult the trouble shooting guide first.

This picture shows what we did: GarminHomeAssistant/Troubleshooting.md at b2461a09e62e6121f5ea48d32e1fb879d2d32361 · house-of-abbey/GarminHomeAssistant · GitHub

I checkd URLS, json files on web, and it is working.

It would be more helpful to know what error messages you were getting when it is not working:

  1. It sounds lke you have got the configuration JSON file for the menu working - but I’ll state this assumption as your post was more general.
  2. Did you positively confirm you had the API URL working? That requires a bit more effort, but not much.

In our experience, all the setup issues so far have been silly mistakes the eye did not catch. The only problems we’ve had to take action for are where the app failed to provide the user with a helpful error message, usually because of device specific issues we can’t test without buying every device we support. Hence we rely on the simulator (which is known to deviate from real life).

1 Like

Honestly, I don’t know what helped, but it started working.

Previously I didn’t get any error, glances only showed that API and Menu were unavailable. After entering the application, there was a black screen.
I tried checking the URL several times, both the API and the JSON file, and verified the addresses according to your guide (thanks!).

Since the last time I checked the watch, I haven’t changed anything in HA or Garmin Connect, I only see that in LOGs that HA lost connection with Nebu Casa for a moment, maybe just restarting HA would help? Now I won’t know.