Alternate device_tracker component for ASUSWRT

I have a WIP seemingly working update: https://github.com/petermnt/home-assistant/blob/feature/asus_wrt_http/homeassistant/components/device_tracker/asuswrt.py

I combined the old tracker and most of the code from the OP. The http method is enabled by using ‘http’ as protocol in the configuration.

I can’t get my environment set up properly for pylint and the dependency script so I can’t get it to a mergeable state for now.

Seems working for me too. Hopefully will get integrated into the HASS

The latest versions of Asus router software block access to SSH after five successful login attempts in few minutes

May 14 10:24:35 syslog: Detect [192.168.1.20] abnormal logins many times, system will block this IP 5 minutes

also the component using http is a very good idea.

1 Like

It looks like your component via http works very well. Can you merge it to the HA repository?

Unfortunately, on the latest router software (Merlin AsusWrt 380.66) the component does not work and displays every few seconds an error:

2017-05-16 10:24:53 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/__init__.py", line 698, in async_device_tracker_scan
    found_devices = yield from scanner.async_scan_devices()
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 385, in scan_devices
    self._update_info()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 303, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 408, in _update_info
    data = self.get_asuswrt_data()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 435, in get_asuswrt_data
    r"fromNetworkmapd: '(.*?)'", data)[0].split('<')
IndexError: list index out of range

I can send you a update_clients.asp file if you want.

I have this same problem. Did you find a fix/work around?

It looks like a new feature was implemented in the firmware:

May 18 14:08:49 syslog: Detect [xxxxxxxxx] abnormal logins many times, system will block this IP 5 minutes.

I’m having this same problem. Temporary workaround for me was

interval_seconds: 20

Might be able to go more frequent, but I tried 20 and dropbear was happy. 10 seconds still got me blocked.

1 Like

Dont know how the ssh component is coded, but perhaps it can stay connected to get what it needs, rather than reconnecting every second.

1 Like

Thanks for sharing this. Setting 20 seconds seems to have worked for me too.

That’s a good idea. It is coded, I’ll look into updating the code to keep it connected.

Had to increase the interval to 30. Anyway, I looked into the code of the component, and made the changes required to maintain the connection. PR (https://github.com/home-assistant/home-assistant/pull/7728) submitted, hopefully it’s accepted soon and the issue will be behind us.

3 Likes

Awesome, thanks aronsky!

I have tried the component with your changes and it works very well. Only during restart of the router generates a lot of errors in the HA log:

2017-05-23 19:29:40 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/__init__.py", line 698, in async_device_tracker_scan
    found_devices = yield from scanner.async_scan_devices()
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 154, in scan_devices
    self._update_info()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 303, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 177, in _update_info
    data = self.get_asuswrt_data()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 191, in get_asuswrt_data
    result = self.connection.get_result()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 321, in get_result
    self.connect()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/device_tracker/asuswrt.py", line 359, in connect
    password=self._password, port=self._port)
  File "/home/homeassistant/.homeassistant/deps/pexpect/pxssh.py", line 279, in login
    spawn._spawn(self, cmd)
  File "/home/homeassistant/.homeassistant/deps/pexpect/pty_spawn.py", line 273, in _spawn
    assert self.pid is None, 'The pid member must be None.'
AssertionError: The pid member must be None.

@aronsky Yes, the connection after the restart was resumed and the component was still working properly. I just updated the router software so the restart took longer than usual and in the HA log there were several dozens of errors as in my previous post.

Thanks for the report! I tried handling the AssertionError, and it helps. However, there are a lot of other unhandled errors from various failing connections to sensors, etc. due to the network being down. So, not sure if it makes a lot of sense to fix this, but I made a pull request with the handled error, nonetheless.

Sorry for the withdrawn message, I thought I’ll write an updated message since there’s a fix. You can find the change in the pull request here: https://github.com/home-assistant/home-assistant/pull/7750/files.

Strange, the component with the latest PR doesn’t re-connect after rebooting the router. The Home Assistant still displays:

2017-05-24 23:14:52 ERROR (Thread-4) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.
2017-05-24 23:15:05 ERROR (Thread-4) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.
2017-05-24 23:15:18 ERROR (Thread-12) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.
2017-05-24 23:15:31 ERROR (Thread-7) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.
2017-05-24 23:15:44 ERROR (Thread-6) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.
2017-05-24 23:15:56 ERROR (Thread-9) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.
2017-05-24 23:16:09 ERROR (Thread-3) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.
2017-05-24 23:16:22 ERROR (Thread-3) [homeassistant.components.device_tracker.asuswrt] Connection to router unavailable.

There is no information about connection attempt in the router log. This evening I will check the previous version of the component again.

Strange, indeed. I tested it at home, and it reconnected successfully once the router booted up. Let me know if anything changes, I’ll close the PR for now, until we know for sure it works properly.

EDIT: Can confirm, same thing happens here. Might be a statistical thing (sometimes happens, sometimes doesn’t). I’m trying out some changes to the code to make a consistent fix.

@Bieniu,

OK, I think I fixed it. I changed the way the pxssh object lifetime is handled, and now it seems to work properly, and the AssertionError handling is redundant (it never happens). I’ll leave the handling, just in case, but regardless, I’m pushing a PR with the fix (it’s the same PR from the previous message, you can get the updated version from there). Let me know if it works for you - I tried it several times in a row, and haven’t run into any problems.

@aronsky I’ll check tonight how it works with my config and I’ll let you know.

EDIT:
I have tried three times and so far so good. Moment after reboot component reconnect to the router. Greate job.

Excellent. Waiting for the PR to get accepted.