kongo09 / philips-airpurifier-coap

💨 Philips AirPurifier custom component for Home Assistant. Supports local CoAP protocol.
165 stars 25 forks source link

Model AC2889 fails to connect #34

Closed KrizzeOne closed 2 years ago

KrizzeOne commented 2 years ago

Hi, I didn't want to add this to the existing issue #31 so I start a new one.

I bought a AC2889/10 and I was very happy to find a custom integration for the air purifier. Thanks for that! But I have a connection problem too.

My HA is up to date. (core-2022.5.3). This repo is up to date (v0.10.1) and when I try to add it as an integration I get this.

httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 289, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 289, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 515, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 743, in async_device_update
    raise exc
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 315, in update
    ) = self.entity_description.value_fn(status, self._last_device_value)
  File "/usr/src/homeassistant/homeassistant/components/fritz/sensor.py", line 66, in _retrieve_external_ip_state
    return status.external_ip  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/lib/fritzstatus.py", line 55, in external_ip
    return self.fc.call_action("WANIPConn", "GetExternalIPAddress")[
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 284, in call_action
    return self.soaper.execute(service, action_name, arguments)
  File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/soaper.py", line 256, in execute
    with self.session.post(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 577, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
kongo09 commented 2 years ago

Are you sure this is related to this integration? I cannot see any reference to philips_airpurifier_coap in your log, but rather to fritzconection and fritz

KrizzeOne commented 2 years ago

I'm sorry, I took blindly the most recent lines out of my logs.

When I try to register my purifier via IP, I get a Timeout, cannot connect to device. Now, with related logs :)

2022-05-11 09:58:43 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration philips_airpurifier_coap which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2022-05-11 09:59:55 DEBUG (MainThread) [custom_components.philips_airpurifier_coap.config_flow] trying to configure host: 192.168.178.39
2022-05-11 10:00:25 WARNING (MainThread) [custom_components.philips_airpurifier_coap.config_flow] Timeout, host 192.168.178.39 doesn't answer, aborting
2022-05-11 13:27:40 DEBUG (MainThread) [custom_components.philips_airpurifier_coap.config_flow] trying to configure host: 192.168.178.39
2022-05-11 13:28:10 WARNING (MainThread) [custom_components.philips_airpurifier_coap.config_flow] Timeout, host 192.168.178.39 doesn't answer, aborting
KrizzeOne commented 2 years ago

My fritz.box shows [Philips-DHCP-Client](http://192.168.178.39/) and this is the IP I took.

kongo09 commented 2 years ago

This could be the connectivity problem. Try to power cycle your Philips device and then connect again. The timeout happens when the device doesn't answer.

KrizzeOne commented 2 years ago

I forgot to mention that this error is independent from Purifier power status. I tried it in both cases and I always get the timeout.


2022-05-11 14:59:21 DEBUG (MainThread) [custom_components.philips_airpurifier_coap.config_flow] trying to configure host: 192.168.178.39
2022-05-11 14:59:21 DEBUG (MainThread) [aioairctrl.coap.client] syncing
2022-05-11 14:59:51 WARNING (MainThread) [custom_components.philips_airpurifier_coap.config_flow] Timeout, host 192.168.178.39 doesn't answer, aborting
kongo09 commented 2 years ago

I didn't mean power status. I meant: switch the device off, wait 10 secs, switch it back on. Then restart HA and see if it works.

KrizzeOne commented 2 years ago

Done.

Same error, more logs.

2022-05-11 18:36:40 DEBUG (MainThread) [aioairctrl.coap.client] syncing
  File "/usr/local/lib/python3.9/site-packages/aiocoap/util/asyncio/recvmsg.py", line 95, in __del__
  File "/usr/local/lib/python3.9/site-packages/aiocoap/util/asyncio/recvmsg.py", line 83, in close
2022-05-11 18:39:35 ERROR (MainThread) [aiohttp.server] Error handling request
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_ws.py", line 138, in prepare
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_response.py", line 421, in prepare
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_response.py", line 429, in _start
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_response.py", line 502, in _write_headers
  File "/usr/local/lib/python3.9/site-packages/aiohttp/http_writer.py", line 131, in write_headers
  File "/usr/local/lib/python3.9/site-packages/aiohttp/http_writer.py", line 76, in _write
2022-05-11 18:40:25 DEBUG (MainThread) [aioairctrl.coap.client] syncing
2022-05-11 18:37:10 WARNING (MainThread) [custom_components.philips_airpurifier_coap.config_flow] Timeout, host 192.168.178.39 doesn't answer, aborting
2022-05-11 18:38:54 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration philips_airpurifier_coap which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2022-05-11 18:40:25 DEBUG (MainThread) [custom_components.philips_airpurifier_coap.config_flow] trying to configure host: 192.168.178.39
2022-05-11 18:40:55 WARNING (MainThread) [custom_components.philips_airpurifier_coap.config_flow] Timeout, host 192.168.178.39 doesn't answer, aborting
Logger: custom_components.philips_airpurifier_coap.config_flow
Source: custom_components/philips_airpurifier_coap/config_flow.py:190
Integration: Philips AirPurifier (with CoAP) ([documentation](https://github.com/kongo09/philips-airpurifier-coap), [issues](https://github.com/kongo09/philips-airpurifier-coap/issues))
First occurred: 18:40:55 (1 occurrences)
Last logged: 18:40:55
kongo09 commented 2 years ago

Two questions:

KrizzeOne commented 2 years ago
  1. Yes: HA Terminal with ping 192.168.178.39 received data
  2. I tried yours first. Do you have a - maybe - working alternative for me?
kongo09 commented 2 years ago

No good suggestion, sorry

Habe you tried the command line utility?

KrizzeOne commented 2 years ago

I was talking about the the build in HA command line.

kongo09 commented 2 years ago

I mean the aioairctrl utility?

KrizzeOne commented 2 years ago

The one from your readme? I tried it at the very beginning on my MacBook, but it's not working.

source aioairctrl-shell.sh

ERROR: You must give at least one requirement to install (see "pip help install")
WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.
You should consider upgrading via the '/Users/xxx/HomeAssistant/dev/philips-airpurifier-coap/.venv/bin/python3.9 -m pip install --upgrade pip' command.
aioairctrl-shell.sh:23: command not found: aioairctrl
kongo09 commented 2 years ago

yes, that's the one. Maybe I made a mistake in the README. I'll take a look and let you know. It's a simple client that is using the same library to connect to the device. If that is working, the problem is with the HA integration. If that is also not working, the problem is either with your network or your device.

kongo09 commented 2 years ago

The instructions have been outdated. I get the same error message.

I've done an update, so please try the new instructions and let me know if that gets you reply from your device. For whatever reason, mine also just stopped replying...

KrizzeOne commented 2 years ago

First of all, thank you for your efforts! My python 2.7 is pretty old and doesn't include venv, so I updated to python 3.9.12 via https://opensource.com/article/19/5/python-3-default-mac

kongo09 commented 2 years ago

Ok, so then it is not a problem of the integration but either of your network or your device

kongo09 commented 2 years ago

Also try status-observe

KrizzeOne commented 2 years ago

In which context should I use status-observe? Inside the virtual environment it's not available.

One question: Is it important what my browser shows when I open my purifiers IP address? I see:

{
error: "Badly formed (DI Comm) request "
}
KrizzeOne commented 2 years ago

I tried something else via https://github.com/rgerganov/py-air-control

I can find my fan via wifi.

airctrl --ipaddr 192.168.178.39

GET error: Padding is incorrect.
Will retry after getting a new key ...
Exchanging secret key with the device ...
Saving session_key xxxxxxx to /Users/xxx/.pyairctrl
[om]                          Fan speed: 0
[pwr]                         Power: OFF
[cl]                          Child lock: False
[aqil]                        Light brightness: 100
[uil]                         Buttons light: ON
[mode]                        Mode: auto
[pm25]                        PM25: 6
[iaql]                        Allergen index: 2
[aqit]                        Air quality notification threshold: 0
[ddp]                         Used index: IAI
kongo09 commented 2 years ago

Hm, that's strange. In the end, the aioairctrl library also goes back to the work of rgerganov. I'm a bit lost why the one works for you and the other doesn't.

kongo09 commented 2 years ago

Is it important what my browser shows

That's also interesting, my browser doesn't answer anything when I try to open the device. Something must be different here.

jmtatsch commented 2 years ago

I have exactly the same device AC2889/10 and the same problem here. aioairctrl also doesnt produce anything for me.

jmtatsch commented 2 years ago

So the problem seems to be that AC2889/10 is an older device that only supports http protocol not coap or plain_coap. You can see that when you play around with the old airctrl:

This works airctrl --ipaddr 192.168.179.70 --protocol http This doesnt airctrl --ipaddr 192.168.179.70 --protocol coap This doesnt airctrl --ipaddr 192.168.179.70 --protocol plain_coap

aioairctrl readme also states aioairctrl works using encrypted coap not mentioning the other two protocols because support was probably dropped somewhere on the way.

There seem to be also differences between fw versions. I have 1.0.4 which doesn't support coap. @mfrister seems to have 1.0.7 which does seem to support coap.

jmtatsch commented 2 years ago

We should probably use this integration https://github.com/GeorgeSG/philips_airpurifier_http

kongo09 commented 2 years ago

You are right, the library here only supports encrypted coap. However, I also have an AC2889/10 and it works with this integration.

kongo09 commented 2 years ago

By the way, which firmware version are your devices running? Maybe you are lucky that your device was never online to download the latest Philips firmware, which introduces all the connectivity problem. If you have an old firmware that doesn't have encrypted coap but works with the other integrations you should consider yourself lucky and make sure you never by accident go online with the device so that it doesn't update itself.

KrizzeOne commented 2 years ago

@kongo09 :

I'm surprised by the firmware version. I thought that it will update automatically as soon as it is connected to my wifi.

@jmtatsch I can confirm the same behavior with my device and network when running the commands you mentioned.

I tried the integration you proposed. It doesn't work:

And now it gets weird: The HA configuration check doesn't work after I add

fan:
  platform: philips_airpurifier_http
  host: 192.168.178.39

to my configuration.yaml

AND: Restarting HA is not possible 🙈 You can click it, but nothing happens!

As soon as I remove the fan config lines, everything works as expected.

kongo09 commented 2 years ago

My AC2889 has the following firmware

So there seems to be a fundamental difference. Even though this integration here doesn't work for you, I'm sure you're better off with the older firmware. Maybe you get the http integration to work...

kongo09 commented 2 years ago

I'll close this now as we figured out that the model does not support encrypted coap.