Home Assistant interface for Garmin's Connect IQ platform


#41

@ajoyce: I certainly would not be opposed to using the long-term token in HassIQ, but I imagine it would have the issue you saw a reference to; that ConnectIQ fails to send the Authorization headers correctly. Which also causes the new auth system to fail. I am going to question the ConnectIQ team on that functionality, but historically I have seen them slow to address some of these issues, so I may look into a small HA patch which would allow the authorization headers to be also sent in differently.


#42

That sounds excellent. Thanks again for your work on this! Would you be able to suggest a workaround in the interim? I’m scratching my head trying to come up with something


#43

Well this was fun!

Bearing in mind I have absolutely no experience in writing apps - I’ve managed to get this working with the new auth system in the simulator!

Took a lot of mucking about with getting your project files imported into Eclipse (for some reason it didn’t want to accept it as a ConnectIQ project - had to start a new empty ConnectIQ project and then copy everything across - in hindsight I guess just adding a monkey.jungle file containing reference to manifest.xml would have worked?) but have got there finally.

The SDK seems to send headers correctly, the problem is that the current code uses the x-ha-access headers from the old system which no longer work. Currently logging in with EITHER the legacy system OR the new OAuth requires input from the user, which can’t be displayed on the watch, so it just returns a 401.

The modification I have made is bypassing the password system altogether and just using the long-lived access token method, which requires no additional input from the user. The only changes I have made are to function requestUpdate():

	function requestUpdate() {
		System.println("Requesting update");

//	not used	if (password != null) {
//	not used		headers = {
//	not used			"Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON, "x-ha-access" => password
//	not used		};
	    if (token == null) {
			headers = {
				"Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON, "Authorization" => "Bearer REALLYLONGSUPERSECRETACCESSTOKENCODEGOESHERE"
			};
		} else {
			headers = {
				"Content-Type" => Comm.REQUEST_CONTENT_TYPE_JSON
			};
		}

Obviously this is a very rough and ready proof-of-concept and needs polish, i.e. user input for the long lived access token etc, but it shows that with the new configuration the Garmin does indeed send authorization in headers correctly.

See below:


#44

See also:

Working on https on both local network and out and about :slight_smile:


#45

@alanf - I’ve made a GitHub account, uploaded the changes and submitted a pull request - would you mind taking a look when you next get a chance?


#46

Oh excellent, thank you! I will check it out.


#47

I’ve submitted another pull request adding the function to adjust font size so you can fit more entities on the status screen at once :smile:


#49

Just an FYI, the latest version of the HassIQ widget has been uploaded to the Connect IQ store and properly supports HA’s new authorization method.


#50

A small note here, I discovered an issue with the recent release regarding the refreshing of tokens. A fix is in progress. I’ll update again when its resolved.


#51

The token refresh issue should be resolved. Please update to the latest version of the HassIQ app to use the modern authentication.


#52

Hi, it’s nice!

I tried to make group

hassiq:

name: hassiq
entities:
  - light.kuchyn
  - light.obyvak
  - light.loznice
  - light.zachod
  - light.chodba
view: true

and config in IQ connect:

 Host: https://super....:443
 visable group: group.hassiq
 Long-Lived Access Token: eyJ.....

but in watch: no devices
Do you have any advice?


#53

Thank you very much Alan for the updates! I now have it up and running both locally and with my ddns service. Very cool to be able to control my home lights with my watch! Thanks for your hard work.


#54

May be a dumb question, but have you restarted your home assistant after creating this group? i.e. does it show up as an entity in your states page?


#55

Of course :wink: I did it.


#56

set
view: true
to

view: false

or delete the entire line, reload groups


#57

I tried but nothing has changed…


#58

If you area using Hassio, sometimes I have restart hassio (the host) to get groups reloaded


#59

Here’s how I’ve set up my group, and its working fine. Perhaps you can use it as a template if yours is slightly different.

  # lights to show up on garmin watch
  Garmin Lights:
    entities: 
    - group.kitchen_ceiling_lights
    - group.living_room_ceiling_lights
    - light.entry_light
    - light.bedroom_light
    - light.bathroom_light

#60

Thank you looks like my. Do you’ve SSL in HA?


#61

Try removing the :443 from your host address. That should be implied by the https.

Also, do you get a status code or just an empty screen?