Mikrotik HA

Hi:

I have a mikrotik router. I configure it at configuration.yaml but after reboot log show this:

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
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

I can see how user “homeassistant” connect with my mikrotik but after 3 seconds ha is disconnected.

I’m not sure if you ever got this working, but I had a similar problem and I ended up using the snmp tracker instead. It works very well, very responsive.

    - platform: snmp
      host: 192.168.1.1
      community: public
      baseoid: 1.3.6.1.2.1.17.4.3.1.1
      new_device_defaults:
              track_new_devices: False
              hide_if_away: False
1 Like

Thank you for your help. I solved problem with telegraf and inputs_snmp. Works fine… also i can send all datas to grafana. If you need some information about it, do not hesitate to conntact me.

I moved from openHAB to Home Assistant.
To track data from a remote Mikrotik, I used a script on Mikrotik:

:global Mac2 "C0:XX:00:EA:XX:DA"
:global OldChek2
:global chek2
if ([/interface wireless registration-table find mac-address=$Mac2] != "") do={set chek2 true} else={set chek2 false}

if (($chek2 != $OldChek2) and ($chek2 = true)) do={
/log warning  ($Mac2 . " -ON Name openhab")
/tool fetch mode=http url="http://192.168.15.15:8080/rest/items/Name/state" http-method=put http-content-type="text/plain" http-data="ON"
} 

if (($chek2 != $OldChek2) and ($chek2 = false)) do={
/log warning  ($Mac2 . " -OFF Name openhab")
/tool fetch mode=http url="http://192.168.15.15:8080/rest/items/Name/state" http-method=put http-content-type="text/plain" http-data="OFF"
} 

set OldChek2 $chek2

But I don’t understand how to adapt this script for Home Assistant.
How to make a virtual switch for Home Assistant?