bulldog5046 / ha_nespresso_integration

19 stars 4 forks source link

Error during add machine #1

Closed saya6k closed 9 months ago

saya6k commented 9 months ago

Environment:

스크린샷 2023-11-18 23 03 11

Config Flow find Nespresso Machine, but fail to connect.

logger:
  default: warning
  logs:
    homeassistant.setup: error
    custom_components.nespresso: debug
2023-11-18 22:59:11.286 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 177, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 389, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nespresso/config_flow.py", line 130, in async_step_user
    name = user_input[CONF_NAME]
           ~~~~~~~~~~^^^^^^^^^^^
KeyError: 'name'
2023-11-18 22:41:27.335 ERROR (MainThread) [custom_components.nespresso.config_flow] Failed to connect to device: EC:E4:50:13:F7:1F - EC:E4:50:13:F7:1F: Failed to connect after 4 attempt(s): TimeoutError
bulldog5046 commented 9 months ago

Thanks for the report.

Can you bring the machine and HA Bluetooth dongle closer together? It seems the base bluetooth connection is failing rather than the Nespresso integration.

If you're familiar with the HA CLI you can test the bluetooth connection with:

bluetoothctl connect EC:E4:50:13:F7:1F

Might need to be ran from the homeassistant docker instance depending on your environment

saya6k commented 9 months ago

It's hard to move HA server. Can I use ESP32 Bluetooth Proxy?

I got this from ESPHome Bluetooth Proxy. (ESP32-S3-Box-3)

[00:38:27][I][esp32_ble_client:201]: [0] [EC:E4:50:13:F7:1F] Connected
[00:38:27][D][esp32_ble_tracker:266]: Starting scan...
[00:38:28][I][esp32_ble_client:270]: [0] [EC:E4:50:13:F7:1F] auth complete. remote BD_ADDR: ece45013f71f
[00:40:22][D][esp-idf:000]: W (246146) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x13

[00:40:22][D][esp-idf:000]: W (246148) BT_APPL: gattc_conn_cb: if=4 st=0 id=4 rsn=0x13

[00:40:22][D][esp-idf:000]: W (246150) BT_APPL: gattc_conn_cb: if=5 st=0 id=5 rsn=0x13

[00:40:22][D][esp-idf:000]: W (246153) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13

[00:40:22][D][esp-idf:000]: W (246155) BT_BTC: btc_transfer_context No memory

This is Log from Home Assistant

2023-11-19 00:38:31.475 ERROR (MainThread) [custom_components.nespresso.nespresso] Failed to onboard Expert_ECE45013F71F
2023-11-19 00:38:31.476 ERROR (MainThread) [custom_components.nespresso.config_flow] Failed to connect to device: 'NoneType' object has no attribute 'disconnect'
2023-11-19 00:39:00.204 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 177, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 389, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nespresso/config_flow.py", line 130, in async_step_user
    name = user_input[CONF_NAME]
           ~~~~~~~~~~^^^^^^^^^^^
KeyError: 'name'
bulldog5046 commented 9 months ago

I've not ben able to get the bluetooth proxies to work to test with. But this is interesting:

2023-11-19 00:38:31.475 ERROR (MainThread) [custom_components.nespresso.nespresso] Failed to onboard Expert_ECE45013F71F

Try doing a factory reset again on the machine, this usually happens when an onboarding process has previously failed and leaves the machine with a new auth_key installed but failed to complete the process and save the device & key into HA.

Alternatively, move the coffee machine closer to the HA server for the pairing process. Part of it involves lowering the txPowerLevel so range will matter for it to successfully install the new key and complete pairing.

saya6k commented 9 months ago

After I reset once again, I succeed to connect and brew cofffee with it. Great.

I wish I have device to bind all entities. It would be better to get status.

And there are some entities that seems binary sensor is more suitable type.

Overall, nice work. Thanks.

bulldog5046 commented 9 months ago

After I reset once again, I succeed to connect and brew cofffee with it. Great.

I wish I have device to bind all entities. It would be better to get status.

And there are some entities that seems binary sensor is more suitable type.

Overall, nice work. Thanks.

I agree. The entities were brought forward from previous project and they don't seem correct or useful. However, the brew features are probably what most people want.

Glad it's working. Hopefully more dev to come :)

saya6k commented 9 months ago

Can I control capsule count in this integration? Now I gain ability to brew coffee in Home Assistant, but lose ability to count capsule in official app :(

And it would be better to use HACS format so that I can register github to HACS.

bulldog5046 commented 9 months ago

Can I control capsule count in this integration? Now I gain ability to brew coffee in Home Assistant, but lose ability to count capsule in official app :(

And it would be better to use HACS format so that I can register github to HACS.

I don't believe it works, it came from the old codebase. I don't have anything that can pair to my machine to see the original app functionality. Could you raise a feature request and i'll take a look at it when i can. Please give as much info as possible.

I will move this across to HACS in time but you are the first beta tester as far as i know so i need some feedback :)

saya6k commented 9 months ago

OK, it's 2 AM in South Korea, so I'll test this while I brew coffee tomorrow.

tikismoke commented 9 months ago

Binary sensor was done in mqtt because i was more using the python script than the integration. Those because I got no correct knowledge and no help only criticism 'it do not work'...

For caps count it is done automatically by the machine. Brew a coffee count less one. You only have to make inventory once a buy and change the value read here: nb_capsule = device.char_read("06aa3a15-f22a-11e3-9daa-0002a5d5c51b").

@saya6k does it mean you where able to use the esp as bridge between ha server and the coffee machine? Because effectively distance was the higher issue off nearly all users.

bulldog5046 commented 9 months ago

Ok cool. Thanks for the info. Mine has always reported 65535, probably because i've never had an app conencted to initialize it.

Just did some testing and that characteristic is also writable:

Connected: True Paired: True Onboarded: True { 'Fault': 1, 'always_1': 1, 'awake': 0, 'caps_number': 15, 'capsule_engaged': 0, 'capsule_mechanism_jammed': 0, 'descaling_counter': 65535, 'descaling_needed': 0, 'sleeping': 1, 'slider': 'closed', 'tray_open_tray_sensor_full': 0, 'tray_sensor_during_brewing': 0, 'water_engadged': 0, 'water_hardness': 4, 'water_is_empty': 0, 'water_temp_low': 1}

Will look to add this feature so yuo can manage caps in HA 👍

bulldog5046 commented 9 months ago

Functionality added and brought into HA as service nespresso:caps to manage the caps counter.

https://github.com/bulldog5046/ha_nespresso_ingetration/issues/2

saya6k commented 9 months ago

@saya6k does it mean you where able to use the esp as bridge between ha server and the coffee machine? Because effectively distance was the higher issue off nearly all users.

Yes, I'm able to connect machine by ESP32 bluetooth proxy. This is log I got from ESPHome, not Home Assistant.

[09:20:40][I][bluetooth_proxy:282]: [0] [EC:E4:50:13:F7:1F] Connecting v3 without cache
[09:20:40][D][esp32_ble_tracker:215]: Pausing scan to make connection...
[09:20:40][I][esp32_ble_client:069]: [0] [EC:E4:50:13:F7:1F] 0x01 Attempting BLE connection
[09:20:41][I][esp32_ble_client:201]: [0] [EC:E4:50:13:F7:1F] Connected
[09:20:41][D][esp32_ble_tracker:266]: Starting scan...
[09:20:42][I][esp32_ble_client:270]: [0] [EC:E4:50:13:F7:1F] auth complete. remote BD_ADDR: ece45013f71f
[09:20:47][I][esp32_ble_client:086]: [0] [EC:E4:50:13:F7:1F] Disconnecting.
[09:20:47][D][esp-idf:000]: W (117200) BT_HCI: hci cmd send: disconnect: hdl 0x1, rsn:0x13

[09:20:47][D][esp-idf:000]: W (117203) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x16

[09:20:47][D][esp-idf:000]: W (117205) BT_APPL: gattc_conn_cb: if=4 st=0 id=4 rsn=0x16

[09:20:47][D][esp-idf:000]: W (117208) BT_APPL: gattc_conn_cb: if=5 st=0 id=5 rsn=0x16

[09:20:47][D][esp-idf:000]: W (117226) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x16

But it require me to reload integration after I reboot. I don't know why is that.

And It took 3 minutes to poll capsule counter after update counter to 100. But succeeded to update capsule counter.

2023-11-19 09:35:05.893 DEBUG (MainThread) [custom_components.nespresso.sensor] Cap Counter updated
2023-11-19 09:36:47.638 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_is_empty 0
2023-11-19 09:36:47.639 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-descaling_needed 1
2023-11-19 09:36:47.639 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-capsule_mechanism_jammed 0
2023-11-19 09:36:47.639 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-always_1 1
2023-11-19 09:36:47.639 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_temp_low 0
2023-11-19 09:36:47.639 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-awake 0
2023-11-19 09:36:47.640 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_engadged 1
2023-11-19 09:36:47.640 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-sleeping 0
2023-11-19 09:36:47.640 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-tray_sensor_during_brewing 0
2023-11-19 09:36:47.640 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-tray_open_tray_sensor_full 0
2023-11-19 09:36:47.640 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-capsule_engaged 0
2023-11-19 09:36:47.640 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-Fault 1
2023-11-19 09:36:47.641 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-descaling_counter 65535
2023-11-19 09:36:47.641 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-caps_number 65535
2023-11-19 09:36:47.641 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-slider closed
2023-11-19 09:36:47.641 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_hardness 0
2023-11-19 09:38:53.364 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_is_empty 0
2023-11-19 09:38:53.364 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-descaling_needed 1
2023-11-19 09:38:53.366 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-capsule_mechanism_jammed 0
2023-11-19 09:38:53.366 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-always_1 1
2023-11-19 09:38:53.366 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_temp_low 0
2023-11-19 09:38:53.366 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-awake 1
2023-11-19 09:38:53.367 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_engadged 0
2023-11-19 09:38:53.376 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-sleeping 0
2023-11-19 09:38:53.377 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-tray_sensor_during_brewing 0
2023-11-19 09:38:53.378 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-tray_open_tray_sensor_full 0
2023-11-19 09:38:53.378 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-capsule_engaged 0
2023-11-19 09:38:53.378 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-Fault 0
2023-11-19 09:38:53.378 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-descaling_counter 65535
2023-11-19 09:38:53.381 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-caps_number 100
2023-11-19 09:38:53.381 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-slider closed
2023-11-19 09:38:53.383 DEBUG (MainThread) [custom_components.nespresso.sensor] State Expert_ECE45013F71F-water_hardness 0
bulldog5046 commented 9 months ago

And It took 3 minutes to poll capsule counter after update counter to 100. But succeeded to update capsule counter.

Yes, I did add a note on the example i've given about this. I'll have a think about how we can update this part faster rather than wait for the next polling.

tikismoke commented 9 months ago

I'm surprised by this value too: descaling_counter 65535

I thing you must define a water hardness. (It's also a read/write)

Like the caps count it seems that this one do not change as you never use the official apps.

bulldog5046 commented 9 months ago

@tikismoke Any chance you've seen a case where a factory reset doesn't clear the auth_key? I'm not sure if i've managed to brick my machine.

Factory reset isn't clearning the key and the last known key does enable access to the characteristics but they are all blank.

tikismoke commented 9 months ago

@bulldog5046 no indeed.

I assume you lay have put the com part in an indésirables status.

Cut power for a night and retry the next day.

elkarto commented 9 months ago

@saya6k does it mean you where able to use the esp as bridge between ha server and the coffee machine? Because effectively distance was the higher issue off nearly all users.

Yes, I'm able to connect machine by ESP32 bluetooth proxy. This is log I got from ESPHome, not Home Assistant.

Could you explain briefly the steps to connect via ESP32 bluetooth proxy? Thank you!!

saya6k commented 9 months ago

@saya6k does it mean you where able to use the esp as bridge between ha server and the coffee machine? Because effectively distance was the higher issue off nearly all users.

Yes, I'm able to connect machine by ESP32 bluetooth proxy. This is log I got from ESPHome, not Home Assistant.

Could you explain briefly the steps to connect via ESP32 bluetooth proxy? Thank you!!

My HA machine is installed in closet so I can't move it. I just placed ESP32 bluetooth proxy node close to machine.