Core: Error setting up platform legacy - Mikrotik

Created on 8 Aug 2019  路  10Comments  路  Source: home-assistant/core

Home Assistant release with the issue:

0.97.0

Last working Home Assistant release (if known):
0.96.x

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

Hass.io on Ubuntu Server

Component/platform:

mikrotik

Description of problem:
Since the upgrade to HA 0.97.b0 the MikroTik device tracker does not work anymore.
On the 0.96 release it was working fine and tracking as expected.
Probably related to https://github.com/home-assistant/home-assistant/pull/25194.

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

device_tracker:
  - platform: mikrotik
    host: !secret mikrotik_host
    username: !secret routeros_username
    password: !secret routeros_password

Traceback (if applicable):

Error setting up platform legacy
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 65, in async_setup_legacy
    self.platform.get_scanner, hass, {DOMAIN: self.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/homeassistant/homeassistant/components/mikrotik/device_tracker.py", line 51, in get_scanner
    scanner = MikrotikScanner(config[DOMAIN])
  File "/usr/src/homeassistant/homeassistant/components/mikrotik/device_tracker.py", line 81, in __init__
    self.success_init = self.connect_to_device()
  File "/usr/src/homeassistant/homeassistant/components/mikrotik/device_tracker.py", line 118, in connect_to_device
    routerboard_info = self.client(cmd="/system/routerboard/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 152, in readSentence
    raise FatalError(words[0])
librouteros.exceptions.FatalError: not logged in

Additional information:
NA

mikrotik stale

Most helpful comment

Hey @slackr31337, do you know how do we add device tracking configuration with the latest Mikrotik changes? For example the consider_home parameter which is very useful.

This used to be my config before 0.98

  - platform: mikrotik
    host: !secret mikrotik_host
    username: !secret mikrotik_username
    password: !secret mikrotik_password
    consider_home: 480
    new_device_defaults:
      track_new_devices: false

All 10 comments

what version of Mikrotik are you using as it looks like you may have to add plain or token as a login method depending on the version you are running. have you tried that extra setting as per documentation?

https://www.home-assistant.io/components/mikrotik/#login_method

Can't currently check but I assume <6.45.
Nevertheless I shouldn't need to add that option, per the docs:
If this option is not set, the component will try to login with the plain method first and the token method if that fails.

If this is not true than it should be mentioned as a breaking change.
Perhaps the fallback is not working as intended?

i would add the login_method option and try both, just to see if its working for you or its another problem

I'm having a similar issue:

Error setting up platform legacy
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/device_tracker/setup.py", line 65, in async_setup_legacy
    self.platform.get_scanner, hass, {DOMAIN: self.config}
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 51, in get_scanner
    scanner = MikrotikScanner(config[DOMAIN])
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 85, in __init__
    self._update_info()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/mikrotik/device_tracker.py", line 222, in _update_info
    device_names = self.client(cmd="/ip/dhcp-server/lease/getall")
  File "/srv/homeassistant/lib/python3.7/site-packages/librouteros/api.py", line 80, in __call__
    return self._readResponse()
  File "/srv/homeassistant/lib/python3.7/site-packages/librouteros/api.py", line 103, in _readResponse
    reply_word, words = self._readSentence()
  File "/srv/homeassistant/lib/python3.7/site-packages/librouteros/api.py", line 88, in _readSentence
    reply_word, words = self.protocol.readSentence()
  File "/srv/homeassistant/lib/python3.7/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.7/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.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 0xfb in position 12: invalid start byte

I enabled SSL with a certificate.
First time installation (may have been overboard with the ssl as a start...)

the same issue
HA 0.98.0b2 armv7l docker odroid-xu-homeassistant
Mikrotik fw ver: 6.45.3

2019-08-26 19:39:17 ERROR (MainThread) [homeassistant.setup] Error during setup of component mikrotik
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 172, in _async_setup_component
    component.setup, hass, processed_config  # type: ignore
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/mikrotik/__init__.py", line 66, in setup
    for device in config[DOMAIN]:
KeyError: 'mikrotik'
device_tracker:
  - platform: mikrotik
    host: !secret mikrotik_ip
    username: !secret mikrotik_user
    password: !secret mikrotik_password
    login_method: plain
    new_device_defaults:
      track_new_devices: true
      hide_if_away: false

Confirmed, have the same Problem as @buzzzzer, running 0.98.0b2, the AP is running RouterOS v6.42.7, last time i saw it working was around 0.96.x

device_tracker:
  - platform: mikrotik
    host: 172.16.3.134
    username: homeassistant
    password: !secret mikrotik_password
    ssl: false
    login_method: plain
    new_device_defaults:
      track_new_devices: true
      hide_if_away: false
2019-08-26 19:53:23 ERROR (MainThread) [homeassistant.setup] Error during setup of component mikrotik
Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/homeassistant/setup.py", line 172, in _async_setup_component
    component.setup, hass, processed_config  # type: ignore
  File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib64/python3.6/site-packages/homeassistant/components/mikrotik/__init__.py", line 66, in setup
    for device in config[DOMAIN]:
KeyError: 'mikrotik'
2019-08-26 19:53:23 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform mikrotik.device_tracker: Unable to set up component.
2019-08-26 19:53:23 INFO (MainThread) [homeassistant.setup] Setup of domain device_tracker took 0.2 seconds.

As of 0.98 the Mikrotik device tracker has been re-worked and a new hub component created. Update HA to 0.98 release and change your config to use the new hub and remove device_tracker platform.

https://www.home-assistant.io/components/mikrotik/

Example

mikrotik:
  - host: 192.168.88.1
    username: homeassistant
    password: YOUR_PASSWORD
    ssl: true

@slackr31337
work for me. tnx.

Hey @slackr31337, do you know how do we add device tracking configuration with the latest Mikrotik changes? For example the consider_home parameter which is very useful.

This used to be my config before 0.98

  - platform: mikrotik
    host: !secret mikrotik_host
    username: !secret mikrotik_username
    password: !secret mikrotik_password
    consider_home: 480
    new_device_defaults:
      track_new_devices: false

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 now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings