8000 Binary ping sensor unavailable after HA (re)start · Issue #43188 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Binary ping sensor unavailable after HA (re)start #43188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rds76 opened this issue Nov 13, 2020 · 20 comments · Fixed by #43869
Closed

Binary ping sensor unavailable after HA (re)start #43188

rds76 opened this issue Nov 13, 2020 · 20 comments · Fixed by #43869

Comments

@rds76
Copy link
rds76 commented Nov 13, 2020

The problem

Ping binary sensor not available - entity is not created for unavailable remote hosts or after ping timeout
Manually reloading ping integration from HA frontend will make failed entities available

Environment

  • Home Assistant Core release with the issue: 0.116.4
  • Last working Home Assistant Core release (if known): 0.115 ?
  • Operating environment (OS/Container/Supervised/Core): linux
  • Integration causing this issue: binary_sensor.ping

Problem-relevant configuration.yaml

- platform: ping
  name: Ping Sonoff02
  host: sonoff02
  count: 2
  scan_interval: 300

Traceback/Error logs

2020-11-13 15:05:59 ERROR (MainThread) [homeassistant.components.ping.binary_sensor] Timed out running command: `['ping', '-n', '-q', '-c', '5', '-W1', 'sonoff02']`, after: 8s
@probot-home-assistant
Copy link

ping documentation
ping source
(message by IssueLinks)

@Coolie1101
Copy link

@rds76 Have you resolved this issue?, I'm seeing the same for all ping sensors.

@rds76
Copy link
Author
rds76 commented Nov 19, 2020

Unfortunately not, there is not solution cause sensor simply doesn't exists so you cannot update it. You need to manually click "reload ping integration" after each HA (re)start. Someone should mark that as BUG

@Coolie1101
Copy link

Maybe adding some sort of delay on startup to the ping integration may help, only if I new how.

@rds76
Copy link
Author
rds76 commented Nov 19, 2020

Impossible, HA stars asynchronously in threads, you cannot delay entity creation process

@rds76
Copy link
Author
rds76 commented Nov 20, 2020

Upgraded HA to 0.118.1 and Python to 3.8.6. No luck. Once ping sensor hits unavailable device during start - all the rest ping entites are unavailable in dashboard until manual update of ping integration is invoked.

@bdraco
Copy link
Member
bdraco commented Dec 2, 2020

#43869 should fix this. There may be a followup tweak needed after #43869 merges though to adjust the behavior.

If you can test with the change in #43869, it would be appricated.

@rds76
Copy link
Author
rds76 commented Dec 2, 2020

PermissionError: [Errno 1] Operation not permitted

2020-12-03 00:51:59 ERROR (MainThread) [homeassistant.components.binary_sensor] ping: Error on device update!
Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.8/site-packages/icmplib/sockets.py", line 86, in __init__
    self._sock = self._create_socket(
  File "/opt/homeassistant/lib/python3.8/site-packages/icmplib/sockets.py", line 445, in _create_socket
    return socket.socket(
  File "/usr/local/lib/python3.8/socket.py", line 231, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted

@bdraco
Copy link
Member
bdraco commented Dec 3, 2020

Thanks. I've got some more adjustments to make and I'll have a new commit pushed up soon.

8000

@bdraco
Copy link
Member
bdraco commented Dec 3, 2020

@rds76 I pushed up two more commits. Can you give it a spin?

@rds76
Copy link
Author
rds76 commented Dec 3, 2020

Another error Permission denied, btw I'm running HA under non root user

Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 359, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 466, in async_device_update
    await task
  File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping/binary_sensor.py", line 112, in async_update
    await self._ping.async_update()
  File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping/binary_sensor.py", line 131, in async_update
    data = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/homeassistant/lib/python3.8/site-packages/icmplib/ping.py", line 131, in ping
    sock = ICMPv4Socket(
  File "/opt/homeassistant/lib/python3.8/site-packages/icmplib/sockets.py", line 100, in __init__
    raise ICMPSocketError(str(err))
icmplib.exceptions.ICMPSocketError: [Errno 13] Permission denied

@bdraco
Copy link
Member
bdraco commented Dec 3, 2020

@rds76
Can you try running this as the same user you are running HA?

ping.py

from functools import lru_cache

from icmplib import SocketPermissionError, ping as icmp_ping

# In python 3.9 and later, this can be converted to just be `cache`
@lru_cache(maxsize=None)
def can_create_raw_socket():
    """Verify we can create a raw socket."""
    try:
        icmp_ping("127.0.0.1", count=0, timeout=0)
        return True
    except SocketPermissionError:
        return False


print (can_create_raw_socket())
(venv) root@ha-dev:/tmp# whoami 
root
(venv) root@ha-dev:/tmp# python3 ping.py
True
(venv) root@ha-dev:/tmp# su nobody -s /bin/bash
nobody@ha-dev:/tmp$ python3 ping.py
False

@bdraco
Copy link
Member
bdraco commented Dec 3, 2020

Also what is sysctl net.ipv4.ping_group_range set to?

@rds76
Copy link
Author
rds76 commented Dec 3, 2020
homeassistant@server:/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping$ whoami
homeassistant
homeassistant@server:/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping$ python3 pingtest.py
Traceback (most recent call last):
  File "pingtest.py", line 3, in <module>
    from icmplib import SocketPermissionError, ping as icmp_ping
ModuleNotFoundError: No module named 'icmplib'
homeassistant@server:/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping$ exit
exit
(homeassistant) server:/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping# whoami
root
(homeassistant) server:/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping# python3 pingtest.py
True

weird error: ModuleNotFoundError: No module named 'icmplib'
net.ipv4.ping_group_range = 1 0

@bdraco
Copy link
Member
bdraco commented Dec 3, 2020

net.ipv4.ping_group_range = 1 0 means icmp is disabled as the user even with unpriv mode.

@bdraco
Copy link
Member
bdraco commented Dec 3, 2020

I'm thinking the hostname can't be resolved similar to #43785

@rds76
Copy link
Author
rds76 commented Dec 3, 2020

missed to activate venv

(homeassistant) homeassistant@server:/opt/homeassistant/lib/python3.8/site-packages/homeassistant/components/ping$ python3 pingtest.py
False

@rds76
Copy link
Author
rds76 commented Dec 3, 2020

tried to change ipv4.ping_group_range to 0 1000. Still the same. Any workaround?

@rds76
Copy link
Author
rds76 commented Dec 3, 2020

update!
ping sensor is working now in HA, this helped sysctl -w net.ipv4.ping_group_range="0 1000"
btw, test script returns False under non root user, but it works in HA now

@github-actions
Copy link
github-actions bot commented Mar 3, 2021

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.

@github-actions github-actions bot added the stale label Mar 3, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0