Home Assistant App for Garmin

It is indeed. I missed that tap_action is applicable to template type in your examples. Thanks!

{
      "entity": "light.green_house",
      "name": "LEDs 0",
      "type": "template",
      "content": "{% if not (is_state('light.green_house', 'off') or is_state('light.green_house', 'unavailable')) %}{{ (((state_attr('light.green_house', 'brightness') | float) / 255 * 100) | round(0)) | int }}%{% else %}Off{% endif %}",
      "tap_action": {
        "service": "light.turn_on",
        "data": {
          "brightness_pct": 12
        }
      }
    }

Would be cool to have type: group also accept content. You can imagine summarising state of group would be useful on top level, e.g. show number of lights which are on. Or have a group_template type if that’s more appropriate.

1 Like

You would lose the group name, hence it has not been done.

Please remember this is just a small watch face with a little App. If you want complicated stuff, use your HA App on your phone? Think of your watch as just a simple list of favourites that saves you the need to reach for your phone.

“A Garmin application to provide a “dashboard” to control your devices via Home Assistant. The application will never be as fully fledged as a Home Assistant dashboard, so it is designed to be good enough for the simple and essential things. Those things that can be activated via an on/off toggle or a tap. That should cover lights, switches, and anything requiring a single press such as an automation. For anything more complicated, e.g. thermostat, it would always be quicker and simpler to reach for your phone or tablet… or the device’s own remote control!”

First paragraph of README!

Its not that simple.

  1. The delay in starting up the Wi-Fi connection to take an action would be a poor user experience. Its slow, that’s noticeable when doing a Sync.
  2. You need to show me where in the API documentation this idea is even possible! I am not aware of any function calls that would allow me to perform this in Monkey C. I don’t know how Sync and Spotify do it, but I can’t do it without an API call. All the HTTPS stuff goes through the phone as far as I can see.

The simulator is downloaded with the SDK.

So if you are looking to assist, you might like to write a small App that creates an HTTPS GET request without Bluetooth enabled, relying solely on Wi-Fi. We then need to detect when the Wi-Fi connnection is even an option as some watches don’t have it. I suggest this change would apply to only the Application and not the Widget version.

Good Luck!

I meant the second row. Just like “template” type has a title and contents. Group name would still be there, with an extra row rendered from template.

Another way of thinking about it is a “tap” type item with an action opening sub-menu.

Anyway, I’ll perhaps make a PR.

I can see that’s a possibility. Please do raise an issue on Github. There might be a delay (until late summer) getting round to it.

Hello,

I did some tests an research, and the makeWebRequest() method indeed does not work if BLE is off if called as is.

However, there is a way using delegate. Some people are already using it.
I need to figure out the proper code, but here are the steps:

I tested modifying the sample provided in the SDK “BulkDownloadApp” and can confirm that using the SyncDelegate way it does work, without BLE connected

This is only in the simulator, but hopefully watches would do the same.

The key function is Communications.startSync() I would say, which allows the request to use the wifi, unlike a direct call to makeWebRequest().

Are you able to share your code, e.g. via Github? It would allow me to see all the context.

So I am interested in this solution of yours, and I wonder if there might be a succint way of including it once I can see the full extent of how you have done it.

Thank you for investigating this, it will be worth an update.

Communications.startSync()
“Exit the AppBase and launch it in sync mode.”

Sounds ominous, but I’ll read up on the link in your previous post. Sorry, there will be a significant delay in taking this formward, I’m doing a course of study that’s consuming my spare time…

I did push my little test here: GitHub - brunoleon/garmin-ha-wifi-test: Test repo for testing wifi call to HA using a Garmin device

This is really a dirty test sorry, I did two commits so you can see what changed from the original sample. Change the URL to something you can monitor on the server side to see if the call is going through.

And to be complete, I don’t think that the whole application should be able to go through wifi always, but for some items like calling an action in HA (opening door in my case) it would make sense IMHO.

And no need to be sorry for your time, you already provided an very nice piece of software! That’s opensource life !

Hi @bleon Bruno,

I’ve had the briefest of moments to look at the code in your repo. I’ve not had much luck getting the application to work presently. I’m not expecting anything more than rough and ready demo…

If I understand the intent correctly, you are performing a GET request on “https://www.google.com” and then returning the response code on completion, discarding the URL contents. I assume that when the phone (BLE) is not connected and the

I have tried this in the simulator only so far under two different settings:

  1. With BLE unconnected (meaning the watch has to use Wi-Fi) and Wi-Fi connected:

I get this error message. That’s all the debug I have.

Error: System Error
Details: failed inside handle_json_callback
Stack: 
  1. With Wi-Fi also disconnected I get “Sync Complete” but the code is -104 (BLE_CONNECTION_UNAVAILABLE). This is perhaps explainable since there is no connection at all.
    complete

  2. With:

I get “WiFi Not Configured”, again perhaps explainable.

What settings are required for a successful GET request over the watch’s Wi-Fi?

We’re looking for the watch (device) to resort to turning on Wi-Fi when we can’t go via the phone. Is this something that only works on real devices?

When I tried to startSync() in GHA, it looks like the method shows a synchronisation progress bar. Feels like this functionality is intended for some other usage.

Anyway, if I can get to the point where I understand how to initiate a GET request, then there’s figuring how how to separate what does and does not go through Wi-Fi. Easiest is everything, which includes fetching the status of all switches. Otherwise there’s lots of code churn separating HTTP requests out and customising how different sorts are managed.

Stumped…

Hello @NP_Complete ,

may be you missed this part: “Change the URL to something you can monitor on the server side to see if the call is going through.”

That is how I was able to see if the call was working or not, I checked the logs on the server side. I just did not want to provide a link to my own HA on github so I set it to www.google.com

As to the original purpose I think it is to sync music mostly, but I don’t see anything that would prevent us to use this call for a simple GET.

Yeah, I got that bit. I didn’t change the address because I was already getting reported failures for a realibly good URL. The reported failures gave me little confidence in being able to integrate any such solution since the returned values need to be useable. Also the presence of the Sync progress bar & view are a distraction from the app.

On the latter, it looks like even if the return codes issue can be addressed, work needs to be done to hide the sync progress view, so potential to be a bit hacky.

Odd that Garmin did not provide something simpler and more helpful for plain HTTP over Wi-Fi!

@NP_Complete Hi Philip. I’m having a similar problem accessing my menu JSON file, but I don’t think I have the same issue with the url to file location mapping. I’ve been through all the documentation and troubleshooting, which was great getting me to this point, but nothing I’ve found seems to work in terms of actually accessing the file.

I’m completely new to JSON and just trying to get anything to show up on the dashboard so I can confirm the basic connection is there and then work on setting up my dashboard.

I’m stuck here:

I also can’t get to the menu.json file pasting the https://MY-ID.ui.nabu.casa/local/garmin/menu.json url in my browser - I get a 404 error

Here’s what I’ve done so far - the step I can’t get past is an error message that says “No JSON returned from HTTP request” as soon as I open the app on my watch. I was getting error messages saying something like “check the internet connection” before I think I sorted out the urls to use, so I think I might have made enough progress to get the watch connected to the JSON file, but that’s where I’m stuck.

  • I’ve generated a long-lived access token in HA and have that in the API Key for HomeAssistant field in the App Settings.

  • I have [u]https://MY-ID.ui.nabu.casa/api[/u] in the URL for HomeAssistant API field in the App Settings

  • I have [u]https://MY-ID.ui.nabu.casa/local/garmin/menu.json[/u] in the URL for menu configuration (JSON) field in the App Settings

  • I’ve created the file /homeassistant/config/www/garmin/menu.json in the Home Assistant File Editor

  • I’ve added this to my configuration.yaml file and rebooted HA:

http:
  cors_allowed_origins:
    - https://house-of-abbey.github.io
  • I have the following JSON code in that file - just trying to get a single switch to show up in the dashboard for the watch app so I can go from there:
{
  "$schema": "https://raw.githubusercontent.com/house-of-abbey/GarminHomeAssistant/main/config.schema.json",
  "title": "Home",
  "items": [
    {
      "entity": "switch.victron_system_relay_0",
      "name": "Van Engine",
      "type": "toggle"
    }
  ]
}

Could it be related to the Nabu Casa certificate? I saw a post about including these two lines in the HTTP section of the confiuration.yaml file, but I can’t restart HA due to an invalid configuration error with these lines in there and I don’t know how to include the certificate from Nabu Casa there if that’s what I need to do…

Thanks in advance for any help!

That’s where your problem starts. The URL is wrong. No point putting the URL anywhere else until you get that right in the browser.

The URL should work in the browser without any long lived tokens, that part is your next step after getting the correct URL.

  • I’ve created the file /homeassistant/config/www/garmin/menu.json in the Home Assistant File Editor

Okay that looks fine.

That too does not look too bad, it should map across if the domain name is correct. So either the domain name is wrong or the files at that location on your webserver are not publically accessible for some reason.

Essentially, work the problem until the URL works in a browser and forget the watch app until it does.

That’s fot the on-line web editor to work, but that requires a pubically accessible URL first.

That certificate issue requires a little more thought, not sure what that’s about. Let’s park that one for the mo’. Comment out those changes to configuration.yaml briefly. Get your HA instance restarted and check you can reach the URL from a browser. Until you’ve got that sorted you are dead in the water…

1 Like

Thanks for the quick reply. I agree and understand just getting the url to work is the first step. I’m sure the domain name is right - I’ve pasted the same Nabu Casa ID that is working for the API into that url, and triple-checked the folder hierarchies in HA to the url structure. I’ve always copied and pasted the Nabu Casa ID number to avoid any typos, too. I even tried moving the menu.json file up a folder level in HA to just the www folder, but that didn’t change anything. I did comment out the whole http section in the configuration/yaml file as a first step.

I also confirmed that I don’t have anything related to Trusted Networks or anything like that in my HA configuration - the file just has a few standard things like thermostats, etc. in it.

I did try shortening the url to see if I could access higher folders in HA, and once I got to just https://MY-ID.ui.nabu.casa/local/, I get a 403 Error (Forbidden) instead of the 404 error. Not sure if that at least confirms that the basic domain name is correct at least. This seems like a big clue - I get a Forbidden error at the www (local) folder level, but then 404 errors anywhere below that. But I have no idea how to confirm or address this.

I’m thinking there is some type of setting or configuration I need to do in HA to allow any folders to be accessible this way, but haven’t seen anyone else have issues with that or mention it. I’ve had the Remote Access for HA Cloud turned on since I started using HA, and the cloud access through Nabu Casa has worked for me on multiple devices since I started using it.

Here’s what the More Details about the HA Cloud certificates includes - neither of those match the (working) API Key, which is the long-lived access token I set up following the initial instructions. I can access the API and get the “API Running” message, though, so I’m assuming that url and key are all correct and working.

I also just tried going to the same local network as my HA instance and using the url http://192.168.XX.XX:8123/local/garmin/menu.json - I get the same 404 error with http and a different error with https: (This site can’t provide a secure connection; 192.168.XX.XX sent an invalid response. ERR_SSL_PROTOCOL_ERROR). The same IP address and port opens the HA instance when I’m on the local network.

I tried this link (https://homeassistant.local/local/garmin/menu.json) from the GitHub readme on the local network and got this error: "This site can’t be reached; homeassistant.local refused to connect.; Try: * Checking the connection, * [Checking the proxy and the firewall]; ERR_CONNECTION_REFUSED

I would suspect proxy or firewall issues, but the API connection works fine, as does every other remote connection I’ve tried to make to my HA instance…

I think I figured it out by finding this.

It looks like maybe this line in the Github readme file is out of date? Always putting the json file in the www folder within the config folder in HA is what was making it not work. As soon as I moved the json file to the www folder in HA at “root” (not in the config folder), it’s been working fine…

We have used /config/www/garmin/<something>.json on our Home Assistant’s file system. That equates to a URL of https://homeassistant.local/local/garmin/<something>.json.

Thank you for this report, I have updated the README.md accordingly. Very helpful of you to have solved the problem.

1 Like

Hey,

I think I need some help troubleshooting.

My watch fails both on the API url and the menu url. When i open the app list, the first 3 second it says “unconfigured” and it changes to “unavailable”. This happens for both the api and the menu.

I have now moved the menu.json to a webhost completely outside my HA setup. I still fails.

I have a “DIY” https/ssl setup with cloudflare.
Its been configured by following this guide: Securing Home Assistant with Cloudflare (hodgkins.io)

From outside i can access my api url fine. Its also been tested with REQBIN.

Other steps Ive tried is to change both urls to my local IP adresses, and setting up a wireguard tunnel from my phone to my firewall at home. The urls with ip still works in my phone browser, but the watch says “unavailable” still.

So now I do not know where to look next.
Any suggestions?

(The watch is a Venu 2)
API url: https://t45.gmx.YY/api. (tried with / at the end aswell)
MENU url: https://gmx.YY/json/garmin.json

(replace “YY” with “no”, just a measure to avoid bots to fetch my urls.)

Thanks in advance.

My problem seems to be related to iphone // Connect app.
After closing and opening both ConnectIQ and Connect. The watch app now works :slight_smile:

Thank @NP_Complete for your help during the weekend

1 Like