core icon indicating copy to clipboard operation
core copied to clipboard

Nanoleaf unexpected error when trying to connect

Open Nordikk opened this issue 2 years ago • 17 comments

The problem

I've moved my setup to my new home, since then I'm not able to connect my Nanoleaf Shapes to Home Assistant.

What version of Home Assistant Core has the issue?

core-2023.10.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

nanoleaf

Link to integration documentation on our website

https://www.home-assistant.io/integrations/nanoleaf/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.nanoleaf.config_flow
Source: components/nanoleaf/config_flow.py:165
Integration: nanoleaf (documentation, issues)
First occurred: 15:43:19 (3 occurrences)
Last logged: 15:43:23

Unknown error authorizing Nanoleaf
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/yarl/_url.py", line 191, in __new__
    port = val.port
           ^^^^^^^^
  File "/usr/local/lib/python3.11/urllib/parse.py", line 182, in port
    raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as 'a39d:124a:43d2:828a:f7ff:fe06:8684:16021'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 423, in _request
    url = self._build_url(str_or_url)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 357, in _build_url
    url = URL(str_or_url)
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yarl/_url.py", line 193, in __new__
    raise ValueError(
ValueError: Invalid URL: port can't be converted to integer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/nanoleaf/config_flow.py", line 165, in async_step_link
    await self.nanoleaf.authorize()
  File "/usr/local/lib/python3.11/site-packages/aionanoleaf/nanoleaf.py", line 266, in authorize
    resp = await self._session.post(f"{self._api_url}/new")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 425, in _request
    raise InvalidURL(str_or_url) from e
aiohttp.client_exceptions.InvalidURL: http://fdd7:a39d:124a:43d2:828a:f7ff:fe06:8684:16021/api/v1/new

Additional information

Nanoleaf is discovered automatically, it just won't connect

Nordikk avatar Oct 16 '23 13:10 Nordikk

Hey there @milanmeu, mind taking a look at this issue as it has been labeled with an integration (nanoleaf) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of nanoleaf can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign nanoleaf Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


nanoleaf documentation nanoleaf source (message by IssueLinks)

home-assistant[bot] avatar Oct 16 '23 13:10 home-assistant[bot]

Looks like you're using IPv6. The IP address should be enclosed by square brackets in the request URL. This is not explicitly implemented in the integration nor the package. Are you manually adding the device and entering it's IP in the config flow, or are you setting up an automatically discovered device?

milanmeu avatar Oct 16 '23 17:10 milanmeu

I've now tried adding it via IPv4 manually and it worked, thank you.

May I ask if an IPv6 implementation will be coming to the integration?

Nordikk avatar Oct 16 '23 17:10 Nordikk

IPv6 should already work if you manually add the device and enclose its IP address within square brackets. The discovery component doesn't add the brackets so the IP breaks when the API port is added. The integration (or the aionanoleaf package) should automatically add the square brackets to the API requests when IPv6 is used. I added it to my list of issues to fix. However, feel free to open a pull request, if you know how to fix it.

milanmeu avatar Oct 23 '23 10:10 milanmeu

Hey @milanmeu I am also having the same issue. I had my Nanoleaf working with HA fine till an update of the Nanoleaf app recently which required me re-add the device in the app. Which meant the HA integration also broke. So I'm trying to re-add it back in HA and getting "Unexpected error"

What version of Home Assistant Core has the issue? Core - 2024.1.2 Supervisor - 2023.12.0 Operating System - 11.4

What was the last working version of Home Assistant Core? No response

What type of installation are you running? Home Assistant OS

Integration causing the issue nanoleaf

Link to integration documentation on our website https://www.home-assistant.io/integrations/nanoleaf/

Diagnostics information No response

Example YAML snippet No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.nanoleaf.config_flow
Source: components/nanoleaf/config_flow.py:165
Integration: Nanoleaf (documentation, issues)
First occurred: 9:08:01 PM (40 occurrences)
Last logged: 10:00:30 PM

Unknown error authorizing Nanoleaf
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/yarl/_url.py", line 191, in __new__
    port = val.port
           ^^^^^^^^
  File "/usr/local/lib/python3.11/urllib/parse.py", line 182, in port
    raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as 'ca63:7e61:6142:828a:f7ff:fe07:74be:16021'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 445, in _request
    url = self._build_url(str_or_url)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 372, in _build_url
    url = URL(str_or_url)
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yarl/_url.py", line 193, in __new__
    raise ValueError(
ValueError: Invalid URL: port can't be converted to integer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/nanoleaf/config_flow.py", line 165, in async_step_link
    await self.nanoleaf.authorize()
  File "/usr/local/lib/python3.11/site-packages/aionanoleaf/nanoleaf.py", line 266, in authorize
    resp = await self._session.post(f"{self._api_url}/new")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 447, in _request
    raise InvalidURL(str_or_url) from e
aiohttp.client_exceptions.InvalidURL: http://fda8:ca63:7e61:6142:828a:f7ff:fe07:74be:16021/api/v1/new

hondoaus avatar Jan 10 '24 11:01 hondoaus

Just to add to above problem @milanmeu, my nanoleaf is auto-discovered by HA and follow the instructions to add it but then i get the "Unexpected Error".

I also tried adding it using the Nanoleaf's IP address manually with no luck, Any assistant is greatly appreciated.

hondoaus avatar Jan 10 '24 21:01 hondoaus

Same here

Dadji avatar Feb 09 '24 21:02 Dadji

I'm experiencing the same issue. Adding the device with square brackets around the IP does fix the issue, but for some reason the integration keeps removing these brackets. Any reasons you could think of that might cause this?

LouisH98 avatar Feb 15 '24 14:02 LouisH98

I can add it manually for with an ipv4 address, but it only works for a few minutes.

owen2 avatar Feb 15 '24 16:02 owen2

Im also having the same issue.. I was able to add a few of mine and then no more

zpriddy avatar Feb 19 '24 01:02 zpriddy

Getting the same issue here. Try to add them via discovery and unknown error no matter what. Trying to add them via IP address seems to work a bit better and asks me to trigger a token, but when submitting I receive a blank box that doesn't let me add the lights.

andiwd avatar Mar 10 '24 20:03 andiwd

Same issue here. When I configure it via IPv4/6, it shows a blank screen with only close buttons

Any workaround except HomeKit Controller?

Thx in advance IMG_2278

wardmatter avatar Apr 20 '24 02:04 wardmatter

My Shapes controller started having trouble recently, due, I think to the same IPV6 issues in this thread. As with @owen2 I could re-add it manually via its IPV4 address it and worked for a while (minutes, sometimes hours) before dying again.

I enabled Debug logging and noticed this:

2024-04-19 17:18:08.488 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.012 seconds (success: True)
2024-04-19 17:19:07.737 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.020 seconds (success: True)
2024-04-19 17:20:07.740 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.023 seconds (success: True)
2024-04-19 17:21:07.732 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.016 seconds (success: True)
2024-04-19 17:21:43.192 DEBUG (MainThread) [homeassistant.components.nanoleaf.config_flow] Zeroconf discovered: ZeroconfServiceInfo(ip_address=ZeroconfIPv6Address('xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'), ip_addresses=[ZeroconfIPv6Address('xxxx:xxxx:xxxx:xxxx:828a:xxxx:xxxx:xxxx'), ZeroconfIPv6Address('xxxx::xxxx:xxxx:xxxx:xxxx%3')], port=6517, hostname='Shapes-XXXX.local.', type='_nanoleafms._tcp.local.', name='Shapes XXXX._nanoleafms._tcp.local.', properties={'id': 'xx:xx:xx:xx:xx:xx', 'md': 'NL42', 'ff': '2', 'c#': '3', 's#': '1', 'ci': '5', 'pv': '1.1', 'sh': 'SKf5+w==', 'sf': '1'})
2024-04-19 17:21:43.219 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.001 seconds (success: False)
2024-04-19 17:21:48.328 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.000 seconds (success: False)
2024-04-19 17:21:58.407 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.001 seconds (success: False)
2024-04-19 17:22:18.787 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.000 seconds (success: False)
2024-04-19 17:22:58.990 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.001 seconds (success: False)
2024-04-19 17:24:19.475 DEBUG (MainThread) [homeassistant.components.nanoleaf] Finished fetching Shapes XXXX data in 0.000 seconds (success: False)

Something about the discovery process messes up the manual IPV4 configuration, and it never works again, even after a HA reboot. The only way to get it back is to remove it and re-add it.

I disabled discovery via the Nanoleaf System options after adding my Shapes and so far it's been stable image

Hopefully this helps some others having the same issue until we can fix IPV6 use correctly in the integration

belzedaar avatar Apr 21 '24 03:04 belzedaar

@belzedaar may be stupid but can't find the System option you mention, how do you get it?

hallard avatar Apr 29 '24 19:04 hallard

It is fixed after I upgraded Shapes to the latest firmware 9.4.2

wardmatter avatar Apr 30 '24 01:04 wardmatter

After updating lines from 9.4.2 -> 9.5.0 this fixed itself for me

clong avatar Jun 24 '24 22:06 clong

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.