bwssytems / ha-bridge

Home automation bridge that emulates a Philips Hue light system and can control other systems such as a Vera, Harmony Hub, Nest, MiLight bulbs or any other system that has an http/https/tcp/udp interface. This is a compact impl to run on small format computers. This is impl started from this project https://github.com/armzilla/amazon-echo-ha-bridge.
Apache License 2.0
1.45k stars 199 forks source link

Hub emulation isn't working consistently for an app that supports Philips Hue in local mode #1378

Open guy1958 opened 2 years ago

guy1958 commented 2 years ago

The problem is in authenticating the user when the app reconnects. Let me explain:

HomeGenie has a companion Android app (HomeGenie Plus) that also supports some UPNP devices directly, including Philips Hue. So I had it "discover" the HA Bridge as a Hue Bridge, and was able to control devices through the bridge, exactly as I wanted. It quickly detects the bridge and all defined devices when I click on Link, and I can then control the "lights" directly. Works great! But...it only works once. If I close the Android app and reopen it again, I get "authorization error" from the HA Bridge, and have to delete the Hue Hub and rediscover it again. Then it works again...until I close the phone app again. Frustrating.

Once it detects the Bridge, it shows me the IP address it found it at, and shows a username of "homegenie" (that I could edit). I then click on "next" and I can select the discovered devices I want to include. I just choose "select all", and it works. Until I close and restart the app. Then I get the "authorization error" whenever I try to control any devices.

In the HA Bridge under "Update Security Settings, I tried, under "Use username/password for Hue API" to set it to "true" and enter a username of "homegenie" with no password (there is no provision to enter a password in the Android app), but that doesn't change anything. I also looked at the settings under "HomeGenie Names and IP Addresses" under Bridge Control, but that appears more to be meant for the HomeGenie server app, so that HA Bridge can send commands to it. I'm just trying to have the HomeGenie Plus phone app send commands to an emulated Hue bridge, and it almost works, except for subsequent reconnections. Something to do with authentication. Should I be trying to enter another name than the default "homegenie" when it discovers the bridge? If so, what? It looks like allowing the link to occur authenticates the app for that one session.

The phone app is here:

https://play.google.com/store/apps/details?id=com.glabs.homegenieplus&utm_source=global_co&utm_medium=prtnr&utm_content=Mar2515&utm_campaign=PartBadge&pcampaignid=MKT-AC-global-none-all-co-pr-py-PartBadges-Oct1515-1

guy1958 commented 2 years ago

Another thing I tried: I clicked on "Manage Links" and saw several entries, one of which appears to be related to when I linked the HomeGenie Plus app. The name comes up as "HomeGenie#SM-G973W#192.168.0.105". So I tried entering that (the whole string) as the username, but then the app asks me to press the link button on the hub (which I click on HA bridge). That re-allows that session to work. But again, exiting the app and relaunching it gives the authorization error.

Is there a way to manually create a username in the HA bridge?

guy1958 commented 2 years ago

Well I've found at least a workaround. In the "Manage Links" list, I saw several entries, so I though I'd try another one of them. One of them is named "auto insert user", and I entered that as a user name in the Home Genie Plus app. Now it connects and reconnects fine, even overnight.

So it seems the app doesn't like ""HomeGenie#SM-G973W#192.168.0.105". Too long? Doesn't like the # character? My understanding of the Philips Hue hub system is that it's the hub (or emulator) that generates the user names when you allow a link to be added. Maybe someone at BWS could explain what some of the names we are seeing in the Manage Links list are for, like the "auto insert user" I tried, and "test_ha_bridge". The ability to edit the names might be a useful addition someday.

HA bridge is a great piece of software and I'm grateful for it, but the documentation is a bit sparse in some areas.