tsunglung / XiaomiAirFryer

Xiaomi Smart Air Fryer integration for Home Assistant
MIT License
66 stars 18 forks source link

Unknown error occurred #22

Open GentleHoneyLover opened 6 months ago

GentleHoneyLover commented 6 months ago

Hello,

Trying to configure the integration but it fails. Tried both methods (login + password and IP + token). The Fryer is on and connected to wi-fi. I can control it via the Mi app.

Can you please help! Thanks a ton!

NAME: Mi Smart Air Fryer 3.5L MODEL: careli.fryer.maf07 HASS: 2024.2.2 (running in Docker) Integration installed via HACS.

Screenshot 2024-02-22 at 20 03 02 Screenshot 2024-02-22 at 20 05 21
yaba commented 6 months ago

I have the same issue. Just installed it today.

DEDEit commented 5 months ago

Hi, it gave me a generic error when entering the email address, I tried with the numeric ID and it worked. Have you also checked that you have selected the correct server? Here is the list:

I hope it helps

bolderbast commented 4 months ago

Seems I have a similar issue

I get the same error for the "automatic" and "manual" method. But in my case, the Airfryer is in my IOT VLAN and my Home Assistant (running in docker) is in my Internal VLAN. I have MDNS reflector running (was already in-place for Google Cast), and I have (temporarily) openend all TCP and UDP ports between the Home Assistant host and the Airfryer (bi-directional).

Any suggestions/help?

image image

Devices found for server "de" @ home "<redacted>":
   ---------
   NAME:     Airfryer
   ID:       <redacted>
   MAC:      <redacted>
   IP:       <redacted>>
   TOKEN:    <redacted>>
   MODEL:    careli.fryer.maf10a
   ---------
homeassistant  | 2024-04-29 15:12:55.862 ERROR (MainThread) [aiohttp.server] Error handling request
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/device.py", line 54, in async_connect_device
homeassistant  |     self._device_info = await self._hass.async_add_executor_job(
homeassistant  |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
homeassistant  |     result = self.fn(*self.args, **self.kwargs)
homeassistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/miio/click_common.py", line 183, in _wrap
homeassistant  |     self._fetch_info()
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/miio/device.py", line 153, in _fetch_info
homeassistant  |     devinfo = DeviceInfo(self.send("miIO.info"))
homeassistant  |                          ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/miio/device.py", line 107, in send
homeassistant  |     return self._protocol.send(
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/miio/miioprotocol.py", line 161, in send
homeassistant  |     self.send_handshake()
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/miio/miioprotocol.py", line 74, in send_handshake
homeassistant  |     raise DeviceException("Unable to discover the device %s" % self.ip)
homeassistant  | miio.exceptions.DeviceException: Unable to discover the device <redacted>
homeassistant  | 
homeassistant  | The above exception was the direct cause of the following exception:
homeassistant  | 
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
homeassistant  |     resp = await request_handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
homeassistant  |     resp = await handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
homeassistant  |     return await handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
homeassistant  |     return await handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
homeassistant  |     return await handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
homeassistant  |     return await handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 88, in ban_middleware
homeassistant  |     return await handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
homeassistant  |     return await handler(request)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
homeassistant  |     response = await handler(request)
homeassistant  |                ^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
homeassistant  |     result = await handler(request, **request.match_info)
homeassistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 71, in with_admin
homeassistant  |     return await func(self, request, *args, **kwargs)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
homeassistant  |     return await super().post(request, flow_id)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
homeassistant  |     result = await method(view, request, data, *args, **kwargs)
homeassistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
homeassistant  |     result = await self._flow_mgr.async_configure(flow_id, data)
homeassistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 356, in async_configure
homeassistant  |     result = await self._async_configure(flow_id, user_input)
homeassistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 402, in _async_configure
homeassistant  |     result = await self._async_handle_step(
homeassistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 506, in _async_handle_step
homeassistant  |     result: _FlowResultT = await getattr(flow, method)(user_input)
homeassistant  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/config/custom_components/xiaomi_airfryer/config_flow.py", line 280, in async_step_cloud
homeassistant  |     return await self.async_step_connect()
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/config/custom_components/xiaomi_airfryer/config_flow.py", line 333, in async_step_connect
homeassistant  |     await connect_device_class.async_connect_device(self.host, self.token)
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/device.py", line 61, in async_connect_device
homeassistant  |     raise SetupException(
homeassistant  | homeassistant.components.xiaomi_miio.const.SetupException: DeviceException during setup of xiaomi device with host <redacted>
GentleHoneyLover commented 4 months ago

I found a solution. Turns out Xiaomi devices ignore requests coming from other subnets. Here are some details and solution.

In short, you need to setup NAT masquerading on your router like so:

iptables -t nat -A POSTROUTING -s YOUR_HOMEASSISTANT_IP/32 -d YOUR_DEVICE_IP/32 -j MASQUERADE

After that, the device will be responding to requests coming from home assistant in another subnet. Of course, the firewall should not be preventing that and there should be functioning inter-VLAN routing in place.

bolderbast commented 4 months ago

Great! That got it connected.

But it looks like the Air Fryer requires Internet Access for all sensors to work. Is that correct?

This integration does not show a "cloud" symbol, so I was kind of expecting it to work fully local without any Internet connectivity.

Not a big deal to let it connect to the Internet, but if it's not required then I'd rather not. :-)

GentleHoneyLover commented 4 months ago

I blocked access for the fryer to internet and dns in my firewall. And it still happily works and shows all sensors. So, maybe the initial configuration requires xiami cloud but after that it works locally.

bolderbast commented 4 months ago

Hmmm, OK. I had it internet connected to register it with the Xiaomi cloud. Then I blocked internet traffic. Now all my sensors are "Unknown" until I grant the AirFryer Internet access... I'll investigate further and I needed, I'll open a separate issue for that. Thanks for the help!

gmcinalli commented 1 month ago

For those with Ubiquiti devices: it seems that is now possible to masquerade NAT with the new version of Network Application. Works like a charm with my Xiaomi Smart Air Fryer 6.5L.

https://community.ui.com/releases/UniFi-Network-Application-8-3-32/54f3b506-afcf-4a7c-aba6-01a884dd9003

GentleHoneyLover commented 1 month ago

@gmcinalli, cool — thanks for sharing! I didn't notice it in the changeling. No need to be messing with CLI anymore :)

Would mind sharing a screenshot of how your NAT setting for XIaomi looks like in the UI?

gmcinalli commented 1 month ago

@GentleHoneyLover Sure! Here it is. Source is HA, destination is the AirFryer, interface is the VLAN where the fryer is located.

image
ilmaino1984 commented 6 hours ago

Same problem. Regards