home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.69k stars 29.96k forks source link

Mikrotik device tracker broken #15257

Closed tes5884 closed 5 years ago

tes5884 commented 6 years ago

Home Assistant release with the issue: 0.72.1

Last working Home Assistant release (if known): 0.71

Operating environment (Hass.io/Docker/Windows/etc.): hassio

Component/platform: mikrotik

Description of problem: device trakcing has stopped working

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

device_tracker:
   - platform: mikrotik
    host: 192.168.1.1
    username: !secret mikrotik_user
    password: !secret mikrotik_password
    new_device_defaults:
      track_new_devices: False
      hide_if_away: False

Traceback (if applicable): Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/librouteros/connections.py", line 198, in write
    self.sock.sendall(string)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 694, in async_device_tracker_scan
    found_devices = yield from scanner.async_scan_devices()
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 138, in scan_devices
    self._update_info()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 160, in _update_info
    device_names = self.client(cmd='/ip/dhcp-server/lease/getall')
  File "/usr/lib/python3.6/site-packages/librouteros/api.py", line 79, in __call__
    self.protocol.writeSentence(cmd, *words)
  File "/usr/lib/python3.6/site-packages/librouteros/connections.py", line 155, in writeSentence
    self.transport.write(encoded)
  File "/usr/lib/python3.6/site-packages/librouteros/connections.py", line 202, in write
    raise ConnectionError('Failed to write to socket. ' + str(error))
librouteros.exceptions.ConnectionError: Failed to write to socket. [Errno 32] Broken pipe

Additional information:

subxero commented 6 years ago

Same problem tracker not working on 0.73.1

:devicetracker
 - platform: mikrotik
   host: 192.168.1.254
   username: !secret mkt_username
   password: !secret mkt_password
   new_device_defaults:
      track_new_devices: False
      hide_if_away: False
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 694, in async_device_tracker_scan
    found_devices = yield from scanner.async_scan_devices()
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 138, in scan_devices
    self._update_info()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 160, in _update_info
    device_names = self.client(cmd='/ip/dhcp-server/lease/getall')
  File "/usr/lib/python3.6/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/usr/lib/python3.6/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/usr/lib/python3.6/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/usr/lib/python3.6/site-packages/librouteros/connections.py", line 149, in readSentence
    reply_word, words = sentence[0], sentence[1:]
IndexError: tuple index out of range
mattyloo commented 6 years ago

Have you recently upgraded Mikrotik? I got this problem today when i upgraded to RouterOS 6.42.6. So maybe they have changed something in the API and not Home Assistant.

tes5884 commented 6 years ago

It's kind of weird, I had this problem after upgrading my Mikrotik. Then a couple of days later it just started working. Try rebooting your router.

subxero commented 6 years ago

The real mikrotik API change its at 6.43rc that have a new secure login process. !) api - changed authentication process (https://wiki.mikrotik.com/wiki/Manual:API#Initial_login);

But 6.42.6 dont change anything, only visual log at 6.42.5 *) api - properly classify API sessions in log;

Rebooting everything don't help

The first sessions works, but minutes later "hang ups", don't close the session at mikrotik and starts throwing errors on home assistant console.

kunago commented 6 years ago

I experience the same issue with broken pipes. It may work for hours, days, then it suddenly reports "broken pipe" and does not connect any longer.

Also as @subxero mentioned, the new API in 6.43 is likely to break the component completely.

niven01 commented 6 years ago

I'm also seeing this exact same issue librouteros.exceptions.ConnectionError: Failed to write to socket. [Errno 32] Broken pipe

Mikrotik version 6.42.6 HA Version: 0.75.3

kunago commented 6 years ago

I am wondering, is this the same issue? https://github.com/luqasz/librouteros/issues/22

subxero commented 6 years ago

Hi @kunago i think there are the same .. from time to time works .. but other days you get errors every time. Currently using routeros 6.42.7 stable and hassio 0.77.3

I tried to "relax" connections with:

   interval_seconds: 300
   consider_home: 1200

without success, even so the problem occurs less often than before.

The raspberry pi3 b+ with Home Assistant its connected directly with lan cable RJ45 to mikrotik hap ac2, both have fixed ips and its not network related, other device trackers like nmap works perfectly for "lan network devices" like computers, but wireless devices are isolated from lan and only mikrotik can track them.

Log Details (ERROR)

Sat Sep 08 2018 08:58:27 GMT+0200 (Hora de verano romance)

Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/librouteros/connections.py", line 181, in write
    self.sock.sendall(string)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 692, in async_device_tracker_scan
    found_devices = await scanner.async_scan_devices()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 137, in scan_devices
    self._update_info()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 159, in _update_info
    device_names = self.client(cmd='/ip/dhcp-server/lease/getall')
  File "/usr/local/lib/python3.6/site-packages/librouteros/api.py", line 79, in __call__
    self.protocol.writeSentence(cmd, *words)
  File "/usr/local/lib/python3.6/site-packages/librouteros/connections.py", line 139, in writeSentence
    self.transport.write(encoded)
  File "/usr/local/lib/python3.6/site-packages/librouteros/connections.py", line 185, in write
    raise ConnectionError('Failed to write to socket. ' + str(error))
librouteros.exceptions.ConnectionError: Failed to write to socket. [Errno 32] Broken pipe
kunago commented 6 years ago

I really wish I could do something about tracking the bug. Could someone please advice me ass to which log level would be best and still allow the instance of Home assistant to work and not to flood the disc completely? The choices would be:

Maybe "warn" would do?

kunago commented 6 years ago

The last time I restarted I limited the interval_seconds to 30 and it seemed to help. It has been up for about 24 hrs now and no problem so far.

CoReYeDe commented 6 years ago

https://github.com/home-assistant/home-assistant/issues/16615

subxero commented 5 years ago

Still not working fine ...

Now using Hassio 0.79.3 and mikrotik version 6.42.9 'long term'

device_tracker:
  - platform: mikrotik
    host: 192.168.123.200
    username: !secret mkt_username
    password: !secret mkt_password
    interval_seconds: 30
    consider_home: 180
    new_device_defaults:
      track_new_devices: true
      hide_if_away: false

Error log:

2018-10-09 21:13:27 INFO (SyncWorker_11) [homeassistant.components.device_tracker.mikrotik] Loading capsman devices from Mikrotik (192.168.123.200) ...
2018-10-09 21:13:27 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 692, in async_device_tracker_scan
    found_devices = await scanner.async_scan_devices()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 137, in scan_devices
    self._update_info()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 162, in _update_info
    cmd='/caps-man/registration-table/getall'
  File "/usr/local/lib/python3.6/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/usr/local/lib/python3.6/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/usr/local/lib/python3.6/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/usr/local/lib/python3.6/site-packages/librouteros/connections.py", line 147, in readSentence
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/usr/local/lib/python3.6/site-packages/librouteros/connections.py", line 147, in 
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/usr/local/lib/python3.6/site-packages/librouteros/connections.py", line 164, in readWord
    return self.transport.read(length).decode(encoding=self.encoding, errors='strict')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 25: invalid continuation byte

Using Mikrotik Capsman for wireless on 4 APs

The only solution that i found stable and works always, its using direct SNMP:

device_tracker:
  - platform: snmp
    host: 192.168.123.200
    community: !secret mkt_snmp
    baseoid: 1.3.6.1.4.1.14988.1.1.1.5.1.1
    track_new_devices: true
    interval_seconds: 30
    home_interval: 5
    consider_home: 180
    new_device_defaults:
      track_new_devices: true
      hide_if_away: false

for direct wireless table (not capsman) baseoid: 1.3.6.1.4.1.14988.1.1.1.2.1.1

works much better than API .. still dont understand because not use direct calls true SSH with a shared KEY have better error treatmeant and its direct without pseudo translator you can make your own script to get information from wifi, lan or ARP table like hostnames.

B.R.

balloobbot commented 5 years ago

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 :+1:

heytensai commented 5 years ago

I suspect that https://github.com/home-assistant/home-assistant/pull/18421 (which is in 0.84) resolved this but haven't been able to test it myself.

rapiertg commented 5 years ago

I think I am having this issue:

ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform mikrotik
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/__init__.py", line 176, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 38, in get_scanner
    scanner = MikrotikScanner(config[DOMAIN])
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 70, in __init__
    self._update_info()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 184, in _update_info
    cmd='/caps-man/registration-table/getall')
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in readSentence
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in <genexpr>
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 164, in readWord
    return self.transport.read(length).decode(encoding=self.encoding, errors='strict')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 19: invalid continuation byte

HA version: 0.87.1 Mikrotik : 6.43.11

jladefoged commented 5 years ago

I tested yesterday and have the same issue in HA 0.88.0 and Mikrotik firmware 6.43.12

giantlock commented 5 years ago

I think I am having this issue:

ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform mikrotik
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/__init__.py", line 176, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 38, in get_scanner
    scanner = MikrotikScanner(config[DOMAIN])
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 70, in __init__
    self._update_info()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/mikrotik.py", line 184, in _update_info
    cmd='/caps-man/registration-table/getall')
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in readSentence
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in <genexpr>
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 164, in readWord
    return self.transport.read(length).decode(encoding=self.encoding, errors='strict')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 19: invalid continuation byte

HA version: 0.87.1 Mikrotik : 6.43.11

Had the same trace. In my case router reports about client with non ascii host-name in /ip/dhcp-server/lease/getall response, so librouteros could not decode it. I fixed it by removing this client from router.

But I still have trace like this

2019-03-16 13:06:27 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/var/www/home-assistant/venv/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 231, in async_update_ha_state
    state = self.state
  File "/usr/local/var/www/home-assistant/venv/lib/python3.6/site-packages/homeassistant/components/upnp/sensor.py", line 144, in state
    return format(self._state, 'd')
TypeError: unsupported format string passed to NoneType.__format__
JuniorGamingTime commented 5 years ago

Is this still an issue you are experiencing? Can you please try upgrading to the latest version of Home Assistant (0.90) and report back if this is still a problem? Thanks!

dpanesso commented 5 years ago

Is this still an issue you are experiencing? Can you please try upgrading to the latest version of Home Assistant (0.90) and report back if this is still a problem? Thanks!

@JuniorGamingTime I have just tested with 0.90 and it works for me!

HA version: 0.90 Mikrotik: 6.44.1

jladefoged commented 5 years ago

I still get this error in HA 0.90.1:

2019-03-22 07:13:45 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform mikrotik
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/device_tracker/__init__.py", line 177, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/device_tracker/mikrotik.py", line 38, in get_scanner
    scanner = MikrotikScanner(config[DOMAIN])
  File "/usr/src/app/homeassistant/components/device_tracker/mikrotik.py", line 70, in __init__
    self._update_info()
  File "/usr/src/app/homeassistant/components/device_tracker/mikrotik.py", line 181, in _update_info
    device_names = self.client(cmd='/ip/dhcp-server/lease/getall')
  File "/usr/local/lib/python3.7/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/usr/local/lib/python3.7/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/usr/local/lib/python3.7/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/usr/local/lib/python3.7/site-packages/librouteros/connections.py", line 147, in readSentence
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/usr/local/lib/python3.7/site-packages/librouteros/connections.py", line 147, in <genexpr>
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/usr/local/lib/python3.7/site-packages/librouteros/connections.py", line 164, in readWord
    return self.transport.read(length).decode(encoding=self.encoding, errors='strict')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe6 in position 27: invalid continuation byte
robbiet480 commented 5 years ago

@ladefoged81 Do you have any weird characters in your DHCP lease names? Just took a look at the underlying library and found two issues that seem related to your issue. If you do have weird characters, I should be able to submit a fix for this quickly that will take care of your issue.

Related issues: https://github.com/luqasz/librouteros/issues/39 https://github.com/luqasz/librouteros/issues/30

jladefoged commented 5 years ago

I have some devices with international letters. I don't find them weird, but apparently Mikrotik does :slightly_smiling_face: Device Kælderdør shows as K-lderd-r in WinBox/SSH terminal. Device Hoveddør shows as Hovedd-r in WinBox/SSH terminal. I can remove the letters from the device names. It might fix the issue, but not the source problem.

robbiet480 commented 5 years ago

@ladefoged81 Just as a test, do you mind removing the letters? If removing them fixes this issue then I'll absolutely get a fix in for you in the next 12-24 hours.

jladefoged commented 5 years ago

@robbiet480 I'll test it this weekend.

jladefoged commented 5 years ago

@robbiet480 I've tried removing the international letters. It did not make any difference and still not working.

dpanesso commented 5 years ago

If it matters or helps I'm running Hass.io in a VM. Using a HA user on RouterOS just for this.

jladefoged commented 5 years ago

I'm using docker on a Synology NAS. I can see HA login in though the API on my Mikrotik router using the standard admin account so a connection i made, but it disconnects afterwards.

robbiet480 commented 5 years ago

@ladefoged81 Mind hopping on Discord and messaging me in #homeassistant for some quick one on one debugging?

jladefoged commented 5 years ago

@robbiet480 I'm not sure that will be possible due to the time difference. However I do respond on github.

BH4WHN commented 5 years ago

How can I solve it?

2019-04-04 12:13:12 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform mikrotik
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/__init__.py", line 177, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 38, in get_scanner
    scanner = MikrotikScanner(config[DOMAIN])
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 70, in __init__
    self._update_info()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 181, in _update_info
    device_names = self.client(cmd='/ip/dhcp-server/lease/getall')
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in readSentence
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in <genexpr>
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 164, in readWord
    return self.transport.read(length).decode(encoding=self.encoding, errors='strict')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 9: invalid start byte

HA 0.91.0

mattyloo commented 5 years ago

Check your comments at DHCP leases so you dont have any bad charachers, when i deleted "ä" it worked again.

Den tor 4 apr. 2019 06:20BH4WHN notifications@github.com skrev:

How can I solve it? 2019-04-04 12:13:12 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform mikrotik Traceback (most recent call last): File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/init.py", line 177, in async_setup_platform platform.get_scanner, hass, {DOMAIN: p_config}) File "/usr/lib/python3.5/asyncio/futures.py", line 380, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run result = self.fn(*self.args, **self.kwargs) File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 38, in get_scanner scanner = MikrotikScanner(config[DOMAIN]) File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 70, in init self._update_info() File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 181, in _update_info device_names = self.client(cmd='/ip/dhcp-server/lease/getall') File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 80, in call return self._readResponse() File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 103, in _readResponse reply_word, words = self._readSentence() File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/api.py", line 88, in _readSentence reply_word, words = self.protocol.readSentence() File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in readSentence sentence = tuple(word for word in iter(self.readWord, b'\x00')) File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 147, in sentence = tuple(word for word in iter(self.readWord, b'\x00')) File "/srv/homeassistant/lib/python3.5/site-packages/librouteros/connections.py", line 164, in readWord return self.transport.read(length).decode(encoding=self.encoding, errors='strict') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 9: invalid start byte

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/home-assistant/home-assistant/issues/15257#issuecomment-479744333, or mute the thread https://github.com/notifications/unsubscribe-auth/AJqGnzE0OYiAV1LEGe8ZfnQ8m8gHwYG-ks5vdX2pgaJpZM4U-gqR .

nasked commented 5 years ago

I still get this error...

HA - 0.91.0b5 MKT - 6.44.1

Error setting up platform mikrotik
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/device_tracker/__init__.py", line 177, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 38, in get_scanner
    scanner = MikrotikScanner(config[DOMAIN])
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 70, in __init__
    self._update_info()
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 181, in _update_info
    device_names = self.client(cmd='/ip/dhcp-server/lease/getall')
  File "/usr/local/lib/python3.7/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/usr/local/lib/python3.7/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/usr/local/lib/python3.7/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/usr/local/lib/python3.7/site-packages/librouteros/connections.py", line 147, in readSentence
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/usr/local/lib/python3.7/site-packages/librouteros/connections.py", line 147, in <genexpr>
    sentence = tuple(word for word in iter(self.readWord, b'\x00'))
  File "/usr/local/lib/python3.7/site-packages/librouteros/connections.py", line 164, in readWord
    return self.transport.read(length).decode(encoding=self.encoding, errors='strict')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 32: invalid continuation byte
Conexión perdida. Reconectando ...
robbiet480 commented 5 years ago

Based on @mattyloo's response, I've implemented the quick fix I mentioned the other week as #22715. Might try to sneak it into 0.91.1, no promises.

tarmacx commented 5 years ago

I'm not getting what the encoding should I set this to ? I have an applicance with a chinese hostname and it breaks the whole thing. Tried a couple of encoding but the best IÉ can achieve is ...welll no errors but no devices tracked either. There is also missing in the doc on what to set it to.

hsmain commented 4 years ago

I tried to remove international characters (á, ã, ç and others) from dhcp leases comments and finally got mikrotik device tracking working.

HA 0.103.6 RouterOS v6.45.1

a-x- commented 4 years ago

I have new error: ValueError: Unable to determine type for mikrotik: None

Logger: homeassistant.setup
Source: components/device_tracker/setup.py:112 
First occurred: 1:52:15 PM (1 occurrences) 
Last logged: 1:52:15 PM

Error during setup of component device_tracker
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 171, in _async_setup_component
    hass, processed_config
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/__init__.py", line 129, in async_setup
    legacy_platforms = await setup.async_extract_config(hass, config)
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 112, in async_extract_config
    f"Unable to determine type for {platform.name}: {platform.type}"
ValueError: Unable to determine type for mikrotik: None

I have default config:

device_tracker:
  - platform: mikrotik
    host: 192.168.88.1
    username: !secret mikrotik_username
    password: !secret mikrotik_password