RobertD502 / home-assistant-iocare

Home Assistant custom component for monitoring and controlling Coway Airmega Purifiers
MIT License
52 stars 8 forks source link

Coway API error with Airmega 250s #34

Closed tymm closed 7 months ago

tymm commented 8 months ago

Hey,

Thank you for this great integration.

When I'm trying to connect my new Airmega 250s, I get the following error: "Failed setup, will retry" and "Coway API error: Coway server failed to return purifier quality status".

RobertD502 commented 8 months ago

Are there any logs that you can share?

The "failed to return purifier quality status" just means that the coway servers returned an error when calling the air quality status endpoint. This can happen intermittently.

tymm commented 8 months ago

I turned on debug logging for the integration but the only logs that I can offer are the following from the docker container output.

2024-03-09 21:11:34.394 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 6.052 seconds (success: False)
2024-03-09 21:13:08.992 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 17.346 seconds (success: False)
2024-03-09 21:13:22.649 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 8.545 seconds (success: False)
2024-03-09 21:13:37.324 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 4.582 seconds (success: False)
2024-03-09 21:14:10.821 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 13.086 seconds (success: False)
2024-03-09 21:14:59.465 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 8.521 seconds (success: False)
2024-03-09 21:16:25.902 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 6.367 seconds (success: False)
2024-03-09 21:16:52.579 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 6.200 seconds (success: False)
2024-03-09 21:17:02.086 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 4.027 seconds (success: False)
2024-03-09 21:17:16.524 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 4.189 seconds (success: False)
2024-03-09 21:17:42.970 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 6.356 seconds (success: False)
2024-03-09 21:19:23.485 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 8.208 seconds (success: False)
2024-03-09 21:19:35.091 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 6.356 seconds (success: False)
kenblu24 commented 8 months ago

I have had the same issue for a couple months now. Was waiting till I had time to properly document the issue, but since you posted this, I'll hop on board.

I also have an Airmega 250s. It is the only device on my Coway account. It may be relevant that I registered my Coway account as being in Luxembourg so that I did not have to provide my phone number during account creation. If I open the official app, I can sign in, and I can control the purifier there and see all the sensor information.

For the integration, it used to work sparsely, but would occasionally not work until I manually re-opened the official coway app. Until recently, this had a chance of causing the integration to work again, but now nothing I've tried seems to allow the integration to work. I've tried changing the password, but that has not helped.


Procedure: Taken from a running system. I click on "Enable debug logging" in the supervisor for the coway custom component, reload the component, wait to go from "Initializing" to "Failed setup, will retry", and turn off debug logging.

This appears in the resulting log in what appears to be the system startup logs: 2024-03-12 11:44:47.626 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: coway This appears in the log at the end:


2024-03-13 18:38:46.718 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary
2024-03-13 18:38:55.570 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 25.035 seconds (success: False)
2024-03-13 18:39:01.725 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary
2024-03-13 18:39:16.720 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary
2024-03-13 18:39:31.559 DEBUG (MainThread) [custom_components.coway] Finished fetching coway data in 30.603 seconds (success: False)
2024-03-13 18:39:31.725 WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary```
Landshark77 commented 8 months ago

Recently received my 400S and I'm having the exact same issue as above. Everything so far is working fine in the Mobile app. If there's any other data I can provide that's not already mentioned above, just give me a shout. Happy to help where I can.

RobertD502 commented 8 months ago

On vacation so I won't be able to do anything until I'm back. Looks like they have made some changes to the API as indicated by the forced requirement to update the mobile app to continue using:

image

RobertD502 commented 8 months ago

I have investigated the cause of the current issue and it is due to Coway completely changing the API. This will require a completely rewrite of the backend library, which I'll get to once I have some time. I will add a message to the readme of this repo to indicate the state - this message will be removed when the rewrite has been completed.

ZappavdV commented 7 months ago

Hi,

I bought a 300s unit last week and I had the same issue until now.

I disabled the 'skip password change' and like magic, everything seems to work. Maybe this can work for other people too?

Cheers!

kenblu24 commented 7 months ago

@ZappavdV Lucky you. Perhaps your device is old enough that your Coway app and account are pinned at an old version?

RobertD502 commented 7 months ago

Hi,

I bought a 300s unit last week and I had the same issue until now.

I disabled the 'skip password change' and like magic, everything seems to work. Maybe this can work for other people too?

Cheers!

The most likely reason this was your issue, and it was resolved by changing this option, is because your Coway account is brand new - With your account being new, Coway won't present you with the password change prompt during login. Possibly, at some point, Coway will start serving you with a prompt to change your password. At that time, the integration will fail to work, and you'll need to adjust the integration's options to have the "skip password change" option enabled.

For anyone that is experiencing issues with purifiers working and then the integration not working when a newly purchased purifier is added to the account, I'll need to investigate if Coway is doing something different with a new firmware version on the purifiers / what happens in the backend library to cause the integration to break. The only way I can investigate this is by having anyone with such an issue reach out to me on Discord (RobertD502) to temporarily grant me access to their Coway account.

@kenblu24 It looks like something funky is going on with your account....Just like the scenario above, the easiest way to get to the bottom of this is to grant me temp access to your account (to debug what is going on) by reaching out to me on Discord (RobertD502).

gh69 commented 7 months ago

I've got an older 300s that has worked perfectly with this integration since 2022. It worked so well that earlier this week I bought another smaller model, the 250s, with the intention of setting it up in a different room and integrating it into HA as well, but right after i added this new 250s to my existing Coway account, the integration went into that "Failed setup, will retry" status (with a tool-tip reading "Coway API error: Coway server failed to return purifier quality status"), the old 300s device entities all went "Unavailable", and the new 250s device didn't even get discovered. I wasn't sure if the integration even supported multiple devices on a single account so I went ahead and created a new secondary Coway account, re-added the older 300s to this new account, and added the new account via the integration as a new hub and this brought my old 300s device and entities back online. Assuming that the integration does supports multiple devices in a single account, it looks like having one new device in the mix kills things even for older devices.

randomstring commented 7 months ago

For anyone that is experiencing issues with purifiers working and then the integration not working when a newly purchased purifier is added to the account, I'll need to investigate if Coway is doing something different with a new firmware version on the purifiers / what happens in the backend library to cause the integration to break. The only way I can investigate this is by having anyone with such an issue reach out to me on Discord (RobertD502) to temporarily grant me access to their Coway account.

This is exactly my situation. Integration worked great right up until I added a new 250S to my account a few days ago.

@RobertD502 Is there a way I can provide debugging info without sharing account credentials?

RobertD502 commented 7 months ago

Unfortunately, I won't be able to get far with just a debug from the backend library - I'd need to use an affected account with an older version of the IoCare app (to use the older API) and MITM the connection in order to see what it is doing. For anyone concerned, you can change your password after I am done. I don't have any nefarious intentions (I have users provide accounts all the time for adding new devices for my other integrations).

The only other solution is for any affected user to do the work themselves and then open a PR that fixes the issue in the cowayaio backend library.

randomstring commented 7 months ago

As a test, I removed the new 250S from my account (via the iPhone app) and reloaded the Homeassistant integration and it initialized correctly and I had access to the previous 400S again. Re-registered the 250S and reloaded the integration and it fails again.

Deleting the older 400S and leaving the newer 250S and then restarting the HomeAssistant integrations fails. Adding the older 400s back also continues to fail.

@RobertD502 I'm pinging you on discord about credentials.

pflonk commented 7 months ago

@RobertD502 if it helps, I made an account with Coway on 9th of april, so quite recently, and use an AP-1512HHS. If you need credentials, tell me about the best way to send them to you. 😃

RobertD502 commented 7 months ago

0.4.0 has been released which should take care of the issue caused by newer purifiers not using the old quality status endpoint.

Thank you to @randomstring for giving me temporary access to his account which allowed me to track down this issue and add some extra goodies for 250S users.

Landshark77 commented 7 months ago

I can confirm this works with my new 400S. Many thanks!

pflonk commented 7 months ago

Can confirm as well, works with my AP-1512HHS. Thanks a lot for this fix 👌😀

gh69 commented 7 months ago

My previously not-working 250S is now working as well. @RobertD502 Thank you!

tymm commented 6 months ago

My previously not-working 250S is now working as well. @RobertD502 Thank you!

Same here. Thanks a lot!