HA 0.98 - Mikrotik and device tracking question

Hi there I just updated to latest 0.98 version, so far so good except for Mikrotik changes.

I’m having trouble finding out how to configure the consider_home and track_new_devices parameters I used to have for device tracking.

This was my device_trackers.yml file 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

On 0.98, my mikrotik hub configuration is:

mikrotik:
  - host: !secret mikrotik_host
    username: !secret mikrotik_username
    password: !secret mikrotik_password

The integration works OK but I can’t configure consider_home nor track_new_devices. I’m not sure what’s the default values for those now or how to change them.

I followed the HA 0.9 release post and also checked the PR and could not find anything about this topic.

If you have any tips please do tell!

1 Like

This is what worked for me:

device_tracker:
  - platform: mikrotik
    interval_seconds: 30
    consider_home: 180
    new_device_defaults:
      track_new_devices: true
      hide_if_away: false
1 Like

I’m having the exact same issue. Not clear how to tweak it as “consider_home” isn’t accepted as a valid configuration.
It pretty much made my device tracking useless.
I’m thinking of using the “wait” option for track depended automation until i’ll get a better picture how to change it.

Thanks! I’ll try it out later when I get home and report back.

To trigger a action based on my phone I use the following in automations.yaml

- id: '1539016025565'
  alias: Light On Arriving Home After Dark
  trigger:
  - entity_id: device_tracker.myphone
    from: not_home
    platform: state
    to: home
  action:
  - entity_id: switch.living_room_light_switch
    service: homeassistant.turn_on

So I tried it with no success. Looking into a solution, this is the error message I get in case anyone else is also stuck here:

homeassistant_1  | 2019-08-30 21:56:30 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy
homeassistant_1  | Traceback (most recent call last):
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 65, in async_setup_legacy
homeassistant_1  |     self.platform.get_scanner, hass, {DOMAIN: self.config}
homeassistant_1  |   File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
homeassistant_1  |     result = self.fn(*self.args, **self.kwargs)
homeassistant_1  |   File "/usr/src/homeassistant/homeassistant/components/mikrotik/device_tracker.py", line 35, in get_scanner
homeassistant_1  |     return scanner if scanner.success_init else None
homeassistant_1  | UnboundLocalError: local variable 'scanner' referenced before assignment

Im facing the same issue since 0.98 in 0.98.1 is still no fixed how can I revert hassio to 0.97?

I could not find a way to solve it without editing component files. I wrote to the devs on the github repo on a related issue. I’ll post back here if/when I get an answer.

I tried creating another tracker (ping the gateway) to be able to set the global values for the device tracker. Unfortunately only the ping tracker obeyed the configured interval, the frequency which the mikrotik was queried did not change (appears to be around 12s). I didn’t experiment to see if the consider_home value was used.

Hi @ski522, can you confirm that this is working for you on 0.98 / 0.98.1 ?

Are there fixes in 0.98.2 for this problem ?

I was on 0.98 and it was working, I just upgraded to 0.98.2 and it’s working.

But in the past I was using SNMP to track as I found that method more reliable and have added that method back in. I just took my Pixel off wi-fi and within a few minutes my device went into “not_home”. Turned wi-fi back on and within changed back to “home”…so working for me.

Obviously you have to have SNMP enabled on the Mtik if you go this route.

mikrotik:
  - host: 192.168.1.1
    username: myusername
    password: mypassword
    method: wireless

    
device_tracker:
  - platform: mikrotik
    interval_seconds: 30
    consider_home: 180
    new_device_defaults:
      track_new_devices: true
      hide_if_away: false
 
  - platform: snmp
    host: 192.168.1.1
    community: public
    baseoid: 1.3.6.1.4.1.14988.1.1.1.2.1.1

I have entered the settings as above but now I am getting this error

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 35, in get_scanner
    return scanner if scanner.success_init else None
UnboundLocalError: local variable 'scanner' referenced before assignment

But it works

hi. Does anyone knows how to track devices with Mikrotik, if they are connected via wifi, Ethernet and some of them has static IP not dhcp.

For now device tracker tracks only devices that are wireless and with enabled dhcp. I cannot track wired devices and static IP devices.

Maybe someone has some advice :slight_smile:

well, out of wireless, capsman and dhcp, nothing will catch ethernet connections with statically configured ip addresses on the host.

is static ip assignment via dhcp an option? dhcp would cover that then.

yeah, looks like only option is to assign all via dhcp or to use ping option for static ip devices. Thanks. for answer.

But to stay on topic: also missing track_new_devices and consider_home for the mikrotik component.

consider_home can be worked around by using dhcp method and setting a corresponding lease timeout. As for track_new_devices, I don’t see a solution.

Anyone aware of why mikrotik device scanning has moved out of the device_tracker domain, where it seems to fit nicely, into a separate hub component?

Enable SNMP on the Mtik and track that way, this has been for me the most reliable method of tracking devices whether DHCP or static, but this is only for wi-fi.

    
device_tracker:
  - platform: mikrotik
    interval_seconds: 30
    consider_home: 180
    new_device_defaults:
      track_new_devices: true
      hide_if_away: false
 
  - platform: snmp
    host: 192.168.1.1
    community: public
    baseoid: 1.3.6.1.4.1.14988.1.1.1.2.1.1

Not sure if changing out the baseoid to 1.3.6.1.2.1.4.22 will work for all devices including those on ethernet.

2 Likes

Thanks. Played a little with oids and found ot that 1.3.6.1.2.1.17.4.3.1.1 works, with your mentioned configuration.

It seems like the developers are aware of the issue and working on a PR to include the missing options, see here for more details.