Skip to content

Discovery fails - Connection cannot be made - "Code: 3004, Message: value is illegal" #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jplabcpt opened this issue Mar 5, 2025 · 98 comments
Labels
bug Something isn't working msmart-ng Issue is with underlying msmart-ng library

Comments

@jplabcpt
Copy link

jplabcpt commented Mar 5, 2025

Has anyone experienced this issue:
Running on the 2.4Ghz network, adding Midea AC - it picks up the devices (shown in list after auto discovery) with correct ID and IP address. Once it goes to the next step, it pauses for 10 seconds and then comes back with error "A connection could not be made" (see screenshot).

Even manually adding does not work with same error.

I already have one Midea AC running on the same setup and works perfectly (added a couple of months ago), but new devices (exact same model) seems to have issues in being added.

Image
@ryanandres
Copy link

Could you provide debug logs?

It's probably related to mill1000/midea-msmart#193

@jplabcpt
Copy link
Author

jplabcpt commented Mar 5, 2025

ah yes, might be related. Thanks for tagging it.

Here is the log output from msmart-ng discover

INFO:msmart.cli:Discovering all devices on local network.
WARNING:msmart.discover:Reported device IP 192.168.xxx.xxx does not match received IP 192.168.xxx.xxx. Using received IP.
INFO:msmart.cloud:Using Midea cloud server: https://mp-prod.appsmb.com (China: False).
ERROR:msmart.discover:Code: 3004, Message: value is illegal.
ERROR:msmart.discover:Code: 3004, Message: value is illegal.
ERROR:msmart.discover:Code: 3004, Message: value is illegal.
ERROR:msmart.discover:Code: 3004, Message: value is illegal.
INFO:msmart.cli:Found 2 devices.
INFO:msmart.cli:Found device:
{'ip': '192.168.xxx.xxx', 'port': 6444, 'id': xxxxxxxxxxxxxxx, 'online': False, 'supported': False, 'type': <DeviceType.AIR_CONDITIONER: 172>, 'name': 'net_ac_XXXX', 'sn': 'xxxxxxxxxxxxxxx', 'key': None, 'token': None}
INFO:msmart.cli:Found device:
{'ip': '192.168.xxx.xxxx', 'port': 6444, 'id': xxxxxxxxxxxxxxx, 'online': False, 'supported': False, 'type': <DeviceType.AIR_CONDITIONER: 172>, 'name': 'net_ac_XXXX', 'sn': 'xxxxxxxxxxxxxxx', 'key': None, 'token': None}

@raribeir
Copy link

raribeir commented Mar 5, 2025

Same here. Regardless of the Cloud region I pick I get that for a newly installed AC device.
The other AC devices previously configured are working fine, so it seems that it is only about discovering them.

@zabbidou
Copy link

zabbidou commented Mar 5, 2025

I have the same problem here, the auto discovery shows me the two ACs I have, and their correct IPs, but can't connect to them, regardless of the region chosen. I also tried to input the IP directly, but I get the same result

Here's the Home Assistant log:

Logger: msmart.discover
Source: custom_components/midea_ac/config_flow.py:103
integration: Midea Smart AC ([documentation](https://github.com/mill1000/midea-ac-py), [issues](https://github.com/mill1000/midea-ac-py/issues))
First occurred: 12:29:39 AM (6 occurrences)
Last logged: 12:31:08 AM

Code: 3004, Message: value is illegal.
Failed to login to cloud. Error: Code: 3102, Message: Account or password incorrect, please re-enter
Could not establish cloud connection.

And the msmart-ng logs:

.\msmart-ng.exe discover
INFO:msmart.cli:Discovering all devices on local network.
WARNING:msmart.discover:Reported device IP [192.168.100.5](http://192.168.100.5/) does not match received IP [192.168.100.9](http://192.168.100.9/). Using received IP.
INFO:msmart.cloud:Using Midea cloud server: https://mp-prod.appsmb.com/ (China: False).
WARNING:msmart.discover:Reported device IP [192.168.100.3](http://192.168.100.3/) does not match received IP [192.168.100.7](http://192.168.100.7/). Using received IP.
ERROR:msmart.discover:Failed to login to cloud. Error: Code: 3102, Message: Account or password incorrect, please re-enter
ERROR:msmart.discover:Could not establish cloud connection.
INFO:msmart.cloud:Using Midea cloud server: https://mp-prod.appsmb.com/ (China: False).
ERROR:msmart.discover:Failed to login to cloud. Error: Code: 3102, Message: Account or password incorrect, please re-enter
ERROR:msmart.discover:Could not establish cloud connection.
INFO:msmart.cli:Found 2 devices.
INFO:msmart.cli:Found device:
{'ip': '192.168.100.9', 'port': 6444, 'id': 153931627892240, 'online': False, 'supported': False, 'type': <DeviceType.AIR_CONDITIONER: 172>, 'name': 'net_ac_2890', 'sn': '000000P0000000Q1B88C295428900000', 'key': None, 'token': None}
INFO:msmart.cli:Found device:
{'ip': '192.168.100.7', 'port': 6444, 'id': 153931627892236, 'online': False, 'supported': False, 'type': <DeviceType.AIR_CONDITIONER: 172>, 'name': 'net_ac_8CB6', 'sn': '000000P0000000Q104D6F4CB8CB60000', 'key': None, 'token': None}

The logs with the mismatched IPs are weird, I looked in the DHCP bindings and 192.168.100.5 and .3 are used by a phone and a watch, .7 and .9 are the correct IPs of the ACs. I can control them in the app, so at least I know their wifi is working haha

@cbarth3
Copy link

cbarth3 commented Mar 5, 2025

Just installed a new Midea Smart AC and was trying to set this up to have better connection compared to the matter connection and received the "A connection could not be made" error.

@Merril-r
Copy link

Merril-r commented Mar 6, 2025

I am having the exact same issues. This integration previously work for me, but I had to start a clean installation of HA.

This is in my logs but I never entered any login information.

This error originated from a custom integration.

Logger: msmart.discover
Source: custom_components/midea_ac/config_flow.py:142
integration: Midea Smart AC (documentation, issues)
First occurred: 14:29:55 (8 occurrences)
Last logged: 14:32:17

Failed to login to cloud. Error: Code: 3144, Message: login failed, login ID is empty, please login again.
Could not establish cloud connection.
Failed to login to cloud. Error: Code: 3102, Message: Account or password incorrect, please re-enter
Code: 3004, Message: value is illegal.

@patrick2724
Copy link

I have the same problem, both of them can no longer be connected no matter what I do, I have already set up hay but it still doesn't work, one of the two was even added before but I accidentally removed it now I can't add it anymore

Image
Image

@Layklant12
Copy link

Bump! I have the exact same issue. Tried several time, tried to restore backup. Not connecting anymore, no matter the server.

@patrick2724
Copy link

It used to work for me but I had stupidly removed the device, now I can no longer add the device, even new devices can no longer be connected

@dustin-auby
Copy link

Hi all, I'm getting the same issue. The first device sets up fine and then any additional devices fail

@jplabcpt
Copy link
Author

jplabcpt commented Mar 7, 2025

hey @mill1000, have any clue what might be causing this?

@maciekdnd
Copy link

Same for me. Even changing regions in my account doesn't help. I have 4 units, recently one of the devices stopped working, so new one had to be installed. 3 are working properly, and unable to adopt the new one.

@mill1000
Copy link
Owner

mill1000 commented Mar 7, 2025

Sorry I'm on a trip with limited access to internet.

Most likely Midea changed their API, or has cracked down on its usage outside of their app.

Once I return I'll look into the API again and see if anything can be done.

Users who already have their token & key should be able to manually add their devices.

If you previously added the device to HA, it's possible the token & key could be found in an HA backup if you have one.

@patrick2724
Copy link

@mill1000 Unfortunately no, there is an error that the token is not known

it was the case that you could no longer operate the devices even though they were online, so you usually remove the device and simply add it again, but you can't add any devices at the moment

@patrick2724
Copy link

When using tokens, the errors occur (Unknown error occurred)( A connection could not be established with these settings. )

Image

@mill1000
Copy link
Owner

mill1000 commented Mar 7, 2025

When using tokens, the errors occur (Unknown error occurred)( A connection could not be established with these settings. )

Image

You'll have to provide full debugs then because no cloud access is required if you already have a key and token.

@patrick2724
Copy link

When using tokens, the errors occur (Unknown error occurred)( A connection could not be established with these settings. )
Image

You'll have to provide full debugs then because no cloud access is required if you already have a key and token.

I know that, I had already added the devices with tokens, but now it doesn't work anymore, the devices can no longer be addressed

@mill1000
Copy link
Owner

mill1000 commented Mar 7, 2025

Ok, please provide full debug logs after rebooting HA so I can help.

@patrick2724
Copy link

@mpactdev
Copy link

mpactdev commented Mar 8, 2025

I have yet to dig in too far, but I likewise have lost HA access to my units. (Existing configs, manually added from key and token!)
It started the day this post was created, so I'm assuming it could be related. I'll post back when I know more.

@mill1000
Copy link
Owner

mill1000 commented Mar 9, 2025

home-assistant_2025-03-08T00-04-50.511Z.log

Thanks. The only midea_ac error in this log is the following.

File "/config/custom_components/midea_ac/config_flow.py", line 237, in _test_manual_connection
    await device.authenticate(token, key)
  File "/usr/local/lib/python3.13/site-packages/msmart/base_device.py", line 65, in authenticate
    await self._lan.authenticate(token, key)
  File "/usr/local/lib/python3.13/site-packages/msmart/lan.py", line 511, in authenticate
    token = convert(token)
  File "/usr/local/lib/python3.13/site-packages/msmart/lan.py", line 508, in convert
    return bytes.fromhex(x) if isinstance(x, str) else x
           ~~~~~~~~~~~~~^^^
ValueError: non-hexadecimal number found in fromhex() arg at position 15

Which implies you've entered the token incorrectly.

I should improve the reported error in this situation.

@githubdoramon
Copy link

Just for the sake of measuring the impact, the same happened for me. For 2 days I can't access my AC through HA anymore. But it works just fine through the SmartHome app

@patrick2724
Copy link

patrick2724 commented Mar 9, 2025

home-assistant_2025-03-08T00-04-50.511Z.log

Thanks. The only midea_ac error in this log is the following.

File "/config/custom_components/midea_ac/config_flow.py", line 237, in _test_manual_connection
    await device.authenticate(token, key)
  File "/usr/local/lib/python3.13/site-packages/msmart/base_device.py", line 65, in authenticate
    await self._lan.authenticate(token, key)
  File "/usr/local/lib/python3.13/site-packages/msmart/lan.py", line 511, in authenticate
    token = convert(token)
  File "/usr/local/lib/python3.13/site-packages/msmart/lan.py", line 508, in convert
    return bytes.fromhex(x) if isinstance(x, str) else x
           ~~~~~~~~~~~~~^^^
ValueError: non-hexadecimal number found in fromhex() arg at position 15

Which implies you've entered the token incorrectly.

I should improve the reported error in this situation.

I only have one token and it didn't work the last time but now all of a sudden

The problem is not really the token but that I can no longer connect 4 devices

@NatyaSadella
Copy link

I have the same problem, can't connect my midea AC anymore. Worked a year ago with a silent cool 26 pro wf, IP is correct and ID is correct.

@mpactdev
Copy link

mpactdev commented Mar 9, 2025

I have yet to dig in too far, but I likewise have lost HA access to my units. (Existing configs, manually added from key and token!) It started the day this post was created, so I'm assuming it could be related. I'll post back when I know more.

Self-update - mine may not be related after all, could be the connection time issue, or may not. I was able to re-add the devices and have them talk again.

HOWEVER!
I noticed that trying to run msmart-ng discover no longer yields the key and token, and was missing one of my v3 devices (which I haven't used in months, but was discovered a few weeks ago). I was fortunate to have saved my discover output a few weeks ago and that information worked. I did update to the latest version of the msmart-ng package and the results were the same.

@jplabcpt
Copy link
Author

jplabcpt commented Mar 10, 2025

@mill1000, I finally managed to get the logs when trying to add my two AC's (one was connected successfully before):

2025-03-10 09:20:17.342 WARNING (MainThread) [msmart.cloud] Request to https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/mj/user/login timed out.
2025-03-10 09:20:18.458 ERROR (MainThread) [msmart.discover] Failed to login to cloud. Error: Code: 3144, Message: login failed, login ID is empty, please login again.
2025-03-10 09:20:18.459 ERROR (MainThread) [msmart.discover] Could not establish cloud connection.
2025-03-10 09:20:51.546 ERROR (MainThread) [msmart.discover] Failed to login to cloud. Error: Code: 3102, Message: Account or password incorrect, please re-enter
2025-03-10 09:20:51.546 ERROR (MainThread) [msmart.discover] Could not establish cloud connection.

Looks like some authentication in the back-end to the cloud environment failing. I assume it uses the credential from the MIdea app?

home-assistant_2025-03-10T07-21-37.553Z.log

@lukeansell
Copy link

I seem to be having the same issue as well. Removed one of my ACs due to IP address change and unable to add it back. At first I tried to add it then tried it again at it said adding was already in progress. After a few minutes I restarted HA and now I have the A connection could not be made. error.

@patrick2724
Copy link

patrick2724 commented Mar 10, 2025

always comes to me ( Code: 3004, Message: value is illegal. )
But that can't be because it recognizes the device

2025-03-10 09:06:13.267 ERROR (MainThread) [msmart.discover] Code: 3004, Message: value is illegal.
2025-03-10 09:06:13.721 ERROR (MainThread) [msmart.discover] Code: 3004, Message: value is illegal.

Image

home-assistant_2025-03-10T08-06-52.863Z.log

@Merril-r
Copy link

I have tried the last four versions. They all five the same error

@mill1000
Copy link
Owner

Just released 2025.3.0 which includes the fix for this.

@dustin-auby
Copy link

Midea Smart AC
Device connection could not be made.

hi i still get this error even with the new update. will try get the logs

@NatyaSadella
Copy link

"Cloud connection could not be made" :(

@dustin-auby
Copy link

Image Image

@dustin-auby
Copy link

i dont see any other errors in the logs juat this one

@dustin-auby
Copy link

i do see this in the debug logs so it does make a connection

2025-03-21 23:49:57.485 DEBUG (MainThread) [custom_components.midea_ac.coordinator] Finished fetching midea_ac data in 0.661 seconds (success: True)

@raribeir
Copy link

raribeir commented Mar 21, 2025 via email

@jplabcpt
Copy link
Author

Works perfectly now! Thanks again @mill1000

@tom314159
Copy link

tom314159 commented Mar 22, 2025

@dustin-auby
I had exactly the same issue the first time I tried using the 2025.3.0 integration, I changed the region and it worked fine, I expect you've tried that but thought I'd suggest it anyway :)
@mill1000
Thank you for your work, it's very much appreciated!

@SmolKopra
Copy link

SmolKopra commented Mar 22, 2025

I had also problems to add my new Midea PortaSplit. I had to create a NetHome Plus Account (SmartHome dosn't work) and use the "midea beautiful air cli" in the terminal to get the token and the key to configure the AC manual.

pip install --upgrade midea-beautiful-air midea-beautiful-air-cli discover --account ACCOUNT_EMAIL --password PASSWORD --credentials

hope that helps

@Merril-r
Copy link

Works perfectly now! Thank you so much for the effort you put in to get this to work again @mill1000

@mill1000
Copy link
Owner

@dustin-auby @NatyaSadella

Sorry you're still having trouble.

Did you try the region option as others suggested? I've found the EU area to be picky.

@dustin-auby
Copy link

@dustin-auby @NatyaSadella

Sorry you're still having trouble.

Did you try the region option as others suggested? I've found the EU area to be picky.

Hi yes i have tried all 3 regions and it shows the same error. i have also restarted home assistant

@NatyaSadella
Copy link

Region switch to US did the trick for me too, yay.

But when I try to configure the air conditioner, I get a 500 Internal Server Error. To be honest, I have no idea whether it’s due to my setup or the integration—I would assume the former.

@raribeir
Copy link

raribeir commented Mar 22, 2025 via email

@NatyaSadella
Copy link

NatyaSadella commented Mar 22, 2025

Yup I did multiple restarts on every device and everything is up to date.

The translated error is:

The configuration flow could not be loaded: 500 Internal Server Error - Server got itself in trouble.

@mill1000
Copy link
Owner

The configuration flow could not be loaded: 500 Internal Server Error - Server got itself in trouble.

Yeah that doesn't sound like an issue from this integration. Unless of course the debug logs are showing lots of errors from midea :)

@mill1000
Copy link
Owner

@dustin-auby Can you enable debug logging and post them here after trying to add a device? Or can you run the msmart-ng discover outside of HA and see if that can fetch your token & key?

@dustin-auby
Copy link

@dustin-auby Can you enable debug logging and post them here after trying to add a device? Or can you run the msmart-ng discover outside of HA and see if that can fetch your token & key?

Ok I can do that , will revert once I have the logs

@dustin-auby
Copy link

@dustin-auby Can you enable debug logging and post them here after trying to add a device? Or can you run the msmart-ng discover outside of HA and see if that can fetch your token & key?

Ok so tried to test it again and this time it did work. not sure what changed. one thing that did happen is there was a trip on the db for the office and the AC lost power. the Home assistant was not affected though only the AC lost power

@jpurdy647
Copy link

jpurdy647 commented Mar 25, 2025

Same issue here with the connection failure. Waited for these last two updates, still no good.
How do I use msmart-ng discover? I tried using pip install which was succesfull, but msmart-ng is not an executable command from the commandline ('msmart-ng' is not recognized as an internal or external command, operable program or batch file.)

Image

HA log:

This error originated from a custom integration.

Logger: msmart.discover
Source: custom_components/midea_ac/config_flow.py:142
integration: Midea Smart AC (documentation, issues)
First occurred: 8:57:50 PM (8 occurrences)
Last logged: 9:05:02 PM

Failed to login to cloud. Error: Code: 3144, Message: login failed, login ID is empty, please login again.
Could not establish cloud connection.
Code: 3004, Message: value is illegal.

@mill1000
Copy link
Owner

You don't appear to be using the latest version based on your screenshot. The error "a connection could not be made" was replaced with "device connection could not be made" or "cloud connection could not be made".

@jpurdy647
Copy link

jpurdy647 commented Mar 25, 2025

I had to restart HA! I did several updates and thought I had restarted. It failed configuration several times after restarting, then eventually started working after a couple minutes. Now all seems perfect!

By the way, I saw this comment:
midea-ac-py can't do this, and the host doesn't help.

Let me say, I bought this brand specifically because of this integration which others have had success with, and I am immensely appreciative of your effort here. I recognize you do it for free and thank you so much!

@NatyaSadella
Copy link

NatyaSadella commented Mar 26, 2025

The configuration flow could not be loaded: 500 Internal Server Error - Server got itself in trouble.

Yeah that doesn't sound like an issue from this integration. Unless of course the debug logs are showing lots of errors from midea :)

I don't know if this info is helpful but it looked like it was indeed an issue with the integration. Logs told me "AttributeError: MideaOptionFlow object has no attribute config_entry"

I had to edit the config_flow.py file, now I can configure the AC

@mill1000
Copy link
Owner

What was the edit you made? And what version of HA are you running?

@NatyaSadella
Copy link

What was the edit you made? And what version of HA are you running?

This was the solution:

image

But I run HA in a docker on a RPI5 and I didn't knew I had to update HA core manually. I was on a older 2023 version so maybe updating to the latest core version would have fixed this too I guess.

@mill1000
Copy link
Owner

Yes the older HA release was likely the problem in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working msmart-ng Issue is with underlying msmart-ng library
Projects
None yet
Development

No branches or pull requests