joeyhage / homebridge-alexa-smarthome

Connect Alexa devices to HomeKit
MIT License
62 stars 20 forks source link

After Initialization - Httperror #58

Open msavage6 opened 8 months ago

msavage6 commented 8 months ago

I was able to successfully install the plugin and authenticate with Amazon, or so I thought. I am able to dictate which devices I want to add as accessories and when turning on debug logs as you can see, Homebridge notes all 8 devices are matched, however that is followed by the error: After initialization - HttpError(Error getting smart home device state. Reason: Timeout)

As a result, I can add the child bridge in HomeKit, but no accessories are available to add afterwards.

In the below debug logs I have removed the full listing of Alexa devices detected as there are 92, to reduce clutter,.

Logs:

10/10/2023, 7:37:30 PM] Homebridge v1.6.1 (HAP v0.11.1) (Homebridge 52BC) is running on port 51707.
[10/10/2023, 7:37:31 PM] [homebridge-alexa-smarthome] Launched child bridge with PID 2426
[10/10/2023, 7:37:31 PM] Registering platform 'homebridge-alexa-smarthome.HomebridgeAlexaSmartHome'
[10/10/2023, 7:37:31 PM] [homebridge-alexa-smarthome] Loaded homebridge-alexa-smarthome v2.0.0 child bridge successfully
[10/10/2023, 7:37:31 PM] Loaded 0 cached accessories from cachedAccessories.0EBE82D05A80.
[10/10/2023, 7:37:31 PM] [homebridge-alexa-smarthome] Alexa-Remote: cookie was provided
[10/10/2023, 7:37:31 PM] Homebridge v1.6.1 (HAP v0.11.1) (homebridge-alexa-smarthome) is running on port 51061.
[10/10/2023, 7:37:31 PM] [homebridge-alexa-smarthome] Alexa-Remote: Authentication checked: true
[10/10/2023, 7:37:31 PM] [Ring] Found the following locations:
[10/10/2023, 7:37:31 PM] [Ring]   locationId: b8950aeb-650d-4abc-bc6a-f4e4c8281c7d - Waterloo
[10/10/2023, 7:37:31 PM] [homebridge-alexa-smarthome] Alexa-Remote: Change Base URL for API calls to na-api-alexa.amazon.ca
[10/10/2023, 7:37:31 PM] [Ring] Configuring 3 cameras and 3 devices for location "Waterloo" - locationId: b8950aeb-650d-4abc-bc6a-f4e4c8281c7d
[10/10/2023, 7:37:31 PM] [Ring] Configured camera 58e16552-36da-40d3-9912-f39e54678fab lpd_v4 Front Door
[10/10/2023, 7:37:31 PM] [Ring] Configured camera 34643de9-5817-4985-ba47-bca1786cdfe7 cocoa_camera Driveway
[10/10/2023, 7:37:31 PM] [Ring] Configured camera 2ea0196e-a8d1-4744-bf17-c6a01e58e40f cocoa_camera Backyard
[10/10/2023, 7:37:31 PM] Front Door 02DF is running on port 51956.
[10/10/2023, 7:37:31 PM] Please add [Front Door 02DF] manually in Home app. Setup Code: 173-42-594
[10/10/2023, 7:37:31 PM] Driveway 12B8 is running on port 51957.
[10/10/2023, 7:37:31 PM] Please add [Driveway 12B8] manually in Home app. Setup Code: 173-42-594
[10/10/2023, 7:37:31 PM] Backyard 7419 is running on port 51958.
[10/10/2023, 7:37:31 PM] Please add [Backyard 7419] manually in Home app. Setup Code: 173-42-594
[10/10/2023, 7:37:32 PM] [myQ] myQ API: Switched to myQ cloud region: east.
[10/10/2023, 7:37:32 PM] [myQ] myQ API: Successfully connected to the myQ API using the east myQ cloud region.
[10/10/2023, 7:37:32 PM] [myQ] myQ API: Discovered device family garagedoor: Garage Door [Liftmaster WiFi GDO DC w/Battery Backup] (serial number: CG08602A3C79, gateway: GW0E000FAC74).
[10/10/2023, 7:37:32 PM] [myQ] myQ API: Discovered device family gateway: Garage Door (serial number: GW0E000FAC74).
[10/10/2023, 7:37:32 PM] [homebridge-alexa-smarthome] Successfully authenticated Alexa account.
[10/10/2023, 7:37:34 PM] [homebridge-alexa-smarthome] Found 92 devices connected to the current Alexa account.
[10/10/2023, 7:37:34 PM] [homebridge-alexa-smarthome] BEGIN devices connected to Alexa account

END devices connected to Alexa account
[10/10/2023, 7:37:34 PM] [homebridge-alexa-smarthome] Found all 8 devices in plugin settings.
[10/10/2023, 7:37:34 PM] [homebridge-alexa-smarthome] Updating device states
[10/10/2023, 7:37:49 PM] [homebridge-alexa-smarthome] After initialization - HttpError(Error getting smart home device state. Reason: Timeout)
[10/10/2023, 7:40:39 PM] [homebridge-alexa-smarthome] Updating device states
[10/10/2023, 7:43:29 PM] [homebridge-alexa-smarthome] Updating device states

Plugin Config:

{
    "bridge": {
        "name": "Homebridge 52BC",
        "username": "0E:38:31:A8:52:BC",
        "port": 51707,
        "pin": "173-42-594",
        "advertiser": "ciao",
        "bind": [
            "en0"
        ]
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 3123,
            "auth": "form",
            "theme": "dark-mode-blue-grey",
            "tempUnits": "c",
            "lang": "auto",
            "platform": "config"
        },
        {
            "refreshToken": "----",
            "unbridgeCameras": true,
            "platform": "Ring"
        },
        {
            "email": "----@hotmail.com",
            "password": "----",
            "name": "myQ",
            "platform": "myQ"
        },
        {
            "devices": [
                "Bedroom Speaker",
                "End Table Speaker",
                "Kitchen Display",
                "Living Room Display",
                "Office Display",
                "Backyard Plug 1",
                "Backyard Plug 2",
                "Bathroom Speaker"
            ],
            "auth": {
                "refreshInterval": 4,
                "proxy": {
                    "clientHost": "192.168.4.105",
                    "port": 9000
                }
            },
            "amazonDomain": "amazon.ca",
            "language": "en-CA",
            "performance": {
                "cacheTTL": 200,
                "backgroundRefresh": true
            },
            "debug": false,
            "_bridge": {
                "username": "0E:BE:82:D0:5A:80",
                "port": 51061
            },
            "platform": "HomebridgeAlexaSmartHome"
        }
    ]
}

Screenshots:

Environment:

joeyhage commented 8 months ago

@msavage6 I just published a new version, v2.0.1, that I hope will fix this issue. Please let me know if you get things working once you upgrade. Thanks!

msavage6 commented 8 months ago

Thanks for the quick reply.

I performed the update and restarted HB, unfortunately still seeing the same error:

[10/11/2023, 10:44:22 AM] [homebridge-alexa-smarthome] Found all 8 devices in plugin settings. [10/11/2023, 10:44:22 AM] [homebridge-alexa-smarthome] Updating device states [10/11/2023, 10:44:38 AM] [homebridge-alexa-smarthome] After initialization - HttpError(Error getting smart home device state. Reason: Timeout)

MatthewBFormal commented 8 months ago

I'm seeing the same issue after a fresh install of homebridge and the plugin v2.0.1 - I'm running ~45 devices

[10/15/2023, 7:26:00 AM] [HomebridgeAlexaSmartHome] Updating device states [10/15/2023, 7:26:15 AM] [HomebridgeAlexaSmartHome] After initialization - HttpError(Error getting smart home device state. Reason: Timeout)

dltacube commented 8 months ago

@joeyhage I noticed this issue while debugging https://github.com/joeyhage/homebridge-alexa-smarthome/issues/63 and noticed that queries to the state endpoint on my homebridge can take up to 25 seconds. The problem I noticed is that if the original query errors out, all subsequent queries are submitted with a blank payload (no devices in body, just an empty list).

I'm not super proficient in javascript so I patched my install of alexa-remote2 to have a 30 second base timeout and it's been working ever since. I might take another crack at it but thought I'd pass this on!

PS: the same query from my phone takes like 400ms so there is something strange going on besides the retry logic.

MatthewBFormal commented 8 months ago

@dltacube Can you share your patch?

dltacube commented 8 months ago

https://github.com/Apollon77/alexa-remote/blob/b801cc99a52bc73a62c6ab7e531e90418bace04b/alexa-remote.js#L1010

I changed flags.timeout || 10000 to 30000 on the line above.

Brandonlive2000 commented 7 months ago

I am having a similar issue. I was able to install the plugin on my HOOBS device and authenticate through Amazon successfully. The logs show the cookie was untrained an updated. But when the bridge restarts and tries to connect to Alex, it fails to do so. I have not been able to get the devices from Alexa.

11/23/2023, 7:56:47 AMAlexa Smarthome BridgeHomebridgeAlexaSmartHomeAlexa login cookie updated. Storing cookie in file: /var/lib/hoobs/alexasmarthomebridge/persist/.homebridge-alexa-smarthome 11/23/2023, 7:56:57 AMAlexa Smarthome Bridge starting 11/23/2023, 7:57:10 AMAlexa Smarthome BridgeLoaded plugin 'homebridge-alexa-smarthome' 11/23/2023, 7:57:10 AMAlexa Smarthome BridgeLoading 1 platforms... 11/23/2023, 7:57:12 AMAlexa Smarthome BridgeBridge is running on port 51896. 11/23/2023, 7:57:12 AMAlexa Smarthome BridgeHomebridgeAlexaSmartHomeERRORFailed to initialize connection to Alexa. - You can try to get the cookie manually by opening http://hoobs.local:9000/ with your browser. 11/23/2023, 7:57:12 AMAlexa Smarthome BridgeHomebridgeAlexaSmartHomeERRORAfter initialization - HttpError(Error getting smart home devices. Reason: Cookie invalid, Renew unsuccessful)

joshuamio commented 6 months ago

I am having a similar issue. I was able to install the plugin on my HOOBS device and authenticate through Amazon successfully. The logs show the cookie was untrained an updated. But when the bridge restarts and tries to connect to Alex, it fails to do so. I have not been able to get the devices from Alexa.

11/23/2023, 7:56:47 AMAlexa Smarthome BridgeHomebridgeAlexaSmartHomeAlexa login cookie updated. Storing cookie in file: /var/lib/hoobs/alexasmarthomebridge/persist/.homebridge-alexa-smarthome 11/23/2023, 7:56:57 AMAlexa Smarthome Bridge starting 11/23/2023, 7:57:10 AMAlexa Smarthome BridgeLoaded plugin 'homebridge-alexa-smarthome' 11/23/2023, 7:57:10 AMAlexa Smarthome BridgeLoading 1 platforms... 11/23/2023, 7:57:12 AMAlexa Smarthome BridgeBridge is running on port 51896. 11/23/2023, 7:57:12 AMAlexa Smarthome BridgeHomebridgeAlexaSmartHomeERRORFailed to initialize connection to Alexa. - You can try to get the cookie manually by opening http://hoobs.local:9000/ with your browser. 11/23/2023, 7:57:12 AMAlexa Smarthome BridgeHomebridgeAlexaSmartHomeERRORAfter initialization - HttpError(Error getting smart home devices. Reason: Cookie invalid, Renew unsuccessful)

it's exactly the same for me...

pjkuras commented 5 months ago

This is a shot in the dark, but why not try deleting that cookie, and redoing the initial authentication? The cookie path is in the log, and you can delete by logging into HOOBS and then going to the Terminal in the three dots menu upper-right. Default login is hoobs, password hoobsadmin.

lpleahy commented 5 months ago

any update on this? i am seeing the same issue and would love to get this to work

joeyhage commented 5 months ago

@lpleahy what issue are you experiencing? And are you a HOOBS user? I will be able to help you better if you open a new issue and fill out the issue template. Thanks!

pjkuras commented 5 months ago

For those experiencing the "HttpError(Error getting smart home devices. Reason: Cookie invalid, Renew unsuccessful)" issue, if you are running HOOBS, what version of HOOBS, Homebridge, and Node.js are you using?

I am successfully using homebridge-alexa-smarthome on HOOBS 4.3 on a Raspberry Pi, but I noticed today that my Node.js is stuck at 16.20.2 (21 is current), and my Homebridge is stuck at 1.6 (1.7 is current). It may be that those running up-to-date HOOBS/Homebridge/Node installations will experience this error, while "lucky" me, stuck with an older version, am not.

You can find the versions on the HOOBS dashboard (log into HOOBS with a browser), on the right side.

lpleahy commented 5 months ago

Hi @joeyhage, thank you for getting back to me and sorry for the delay in following-up.

I am not a HOOBS user, I am using homebridge directly on a raspberry pi. I am seeing the same error that was initially reported in this issue:

[homebridge-alexa-smarthome] After initialization - HttpError(Error getting smart home device state. Reason: Timeout)

I haven't been able to take the time to test this myself yet, but I noticed from this commit that it fixes the call to querySmarthomeDevices, but I believe it misses some other calls that may be failing for the timeout. Given that @dltacube was able to fix this by patching this line in alexa-remote2 I imagine there are other https calls being made in alexa-api-wrapper.tx that are not properly plumbing the timeout override through.

I could be missing something, but as an example, this code can accept a maxTimeout field that is used as part of the flags for the httpsGet call but it is not set here (note that this would be set to 60_000 with the patch that was set by @dltacube as it covers everything that ultimately invokes the httpsGet method).

LMK if you'd like me to submit a new issue instead, but I believe this same issue is not fully fixed given the behavior I am experiencing.

lpleahy commented 5 months ago

Sorry to be a bother, I was just wondering if you were able to take a look at this yet. If not, I can set this up myself locally and try to figure out a fix.

kesumin commented 5 months ago

I was able to find a fix, at least for my own version of the issue. Between the new Homebridge installation in which I'd never previously had this issue, I'd majorly reconfigured my network. I'm not sure which device had a fault, but I found that Homebridge started sending successful requests to Amazon whilst I was removing old devices via Alexa iOS. This included a deprecated Eero router, unplugged devices, and devices I no longer use.

I'm not sure if this helps as well, but during my network reconfiguration, I was trying to move all my IoT devices onto a separate wifi VLAN network. I had trouble with this in the beginning and learned I had to go to Amazon Device Preferences(NA/US) and disable "Frustration-free setup" under "Saved Network Passwords" to manually set the correct network during device setup.

homebridge-alexa-smarthome is now working as expected. I'm able to provide anything else in case anyone's interested in my solution.

System Information Running Homebridge 1.7.0 (docker homebridge/homebridge:latest) via compose (Ubuntu Jammy Jellyfish (22.04.3 LTS)) node.js v20.11.0

mewanas1209 commented 4 months ago

@kesumin can you please share your solution.