core: Shelly integration broken in core-2021.2.0

The problem

Shelly integration is broken since core-2021.2.0 update. Entities are unavailable. When delete shelly device, a new integration is detected but unable to configure (endless spining).

What is version of Home Assistant Core has the issue?

core-2021.2.0

What was the last working version of Home Assistant Core?

core-2021.1.5

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Shelly

Link to integration documentation on our website

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

Example YAML snippet

# Put your YAML below this line

Anything in the logs that might be useful for us?

# Put your logs below this line
Logger: homeassistant.components.shelly.config_flow
Source: components/shelly/__init__.py:54
Integration: Shelly (documentation, issues)
First occurred: 8:45:55 AM (1 occurrences)
Last logged: 8:45:55 AM

Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/shelly/config_flow.py", line 166, in async_step_confirm_discovery
    device_info = await validate_input(self.hass, self.host, {})
  File "/usr/src/homeassistant/homeassistant/components/shelly/config_flow.py", line 41, in validate_input
    coap_context = await get_coap_context(hass)
  File "/usr/src/homeassistant/homeassistant/helpers/singleton.py", line 42, in async_wrapped
    result = await func(hass)
  File "/usr/src/homeassistant/homeassistant/components/shelly/__init__.py", line 54, in get_coap_context
    await context.initialize()
  File "/usr/local/lib/python3.8/site-packages/aioshelly/coap.py", line 86, in initialize
    self.sock = socket_init()
  File "/usr/local/lib/python3.8/site-packages/aioshelly/coap.py", line 66, in socket_init
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, group)
OSError: [Errno 105] No buffer space available

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 36 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Hi there,

I updated to 2021.2.0 and had the problem too with my Shelly EM integration.

After some digging regarding the error, I found out that it is related to multicast addresses/groups. I followed part of the instructions here : https://blog.mphomphego.co.za/blog/2017/06/28/why-am-i-getting-errno105-no-buffer-space-available-when-subscribing-to-multicast-addresses.html#:~:text=The "Errno 105" in this,groups at the same time.

by only adding the line below in the /etc/sysctl.conf :

Increase number of multicast groups permitted

net.ipv4.igmp_max_memberships=1024

After rebooting HASS, the Shelly integration worked again.

I am running it on an Odroid N2+, with Armbian.

Great. Going to close this. We have reverted the change to listen on all interfaces.

Also, is this issue specific to shelly? Or is it common to any integrations using IGMP and listening to broadcast addresses?

Ban by default attaching sockets to all network interfaces

Set the igmp_max_memberships carefully. The default value is 20 increasing it significantly can have negative impact on the system. I would first try with 256 and if that works leave it like that. No need to have the potential to waste kernel memory.

I had the same problem, but turned out there was another layer to it. In my logs I saw

2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 127.0.0.1 to multicast 224.0.1.187 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 127.0.0.1 to multicast 224.0.1.188 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 192.168.2.10 to multicast 224.0.1.187 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 192.168.2.10 to multicast 224.0.1.188 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 192.168.11.11 to multicast 224.0.1.187 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 192.168.11.11 to multicast 224.0.1.188 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 172.17.0.1 to multicast 224.0.1.187 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 172.17.0.1 to multicast 224.0.1.188 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 172.30.32.1 to multicast 224.0.1.187 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 172.30.32.1 to multicast 224.0.1.188 membership
2021-02-04 21:53:21 DEBUG (MainThread) [aioshelly.coap] Adding ip 192.168.2.5 to multicast 224.0.1.187 membership
2021-02-04 21:53:21 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Arbeitszimmer Rollladen for shelly
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 239, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/shelly/__init__.py", line 84, in async_setup_entry
    coap_context = await get_coap_context(hass)
  File "/usr/src/homeassistant/homeassistant/helpers/singleton.py", line 42, in async_wrapped
    result = await func(hass)
  File "/usr/src/homeassistant/homeassistant/components/shelly/__init__.py", line 54, in get_coap_context
    await context.initialize()
  File "/usr/local/lib/python3.8/site-packages/aioshelly/coap.py", line 86, in initialize
    self.sock = socket_init()
  File "/usr/local/lib/python3.8/site-packages/aioshelly/coap.py", line 66, in socket_init
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, group)
OSError: [Errno 98] Address in use

and from looking at the code in aioshelly/coap.py and the recent changes I was able to deduce it was tripping over a secondary IP on the same interface. This is how my main interface is normally configured:

root@kodlixio:~# ip a s enp1s0
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:e0:4c:3b:d5:b5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.10/24 brd 192.168.2.255 scope global dynamic enp1s0
       valid_lft 84408sec preferred_lft 84408sec
    inet 192.168.2.5/32 brd 192.168.2.5 scope global enp1s0:0
       valid_lft forever preferred_lft forever

Disabling the secondary IP and restarting homeassistant made all shellies work immediately.

@benniju you also seem to have two networks on eth0, not quite the same as my setup but similar. The code tries to join eth0 into the multicast group twice, and the second time fails.