Mikrotik Router integration

image
Available in languages:
English Arabic Czech Dutch French German Greek Hindi Hungarian Italian Polish Portuguese Russian Slovak Spanish

Monitor and control your Mikrotik device from Home Assistant.

  • Interfaces:
    • Enable/disable interfaces
    • Monitor RX/TX traffic per interface
    • Monitor device presence per interface
    • IP, MAC, Link information per an interface for connected devices
  • Enable/disable NAT rule switches
  • Enable/disable Simple Queue switches
  • Enable/disable Mangle switches
  • Monitor and control PPP users
  • Kid Control
  • Mikrotik Accounting traffic sensors per hosts for RX/TX WAN/LAN
  • Device tracker for hosts in network
  • System sensors (CPU, Memory, HDD, Temperature)
  • Check firmware update
  • Execute scripts
  • View environment variables
  • Configurable update interval
  • Configurable traffic unit (bps, Kbps, Mbps, B/s, KB/s, MB/s)
  • Supports monitoring of multiple mikrotik devices simultaneously

Features

Interfaces

Monitor and control status on each Mikrotik interface, both lan and wlan. Both physical and virtual.



Interface Sensor

NAT

Monitor and control individual NAT rules.

More information about NAT rules can be found on Mikrotik support page.

NAT switch

Mangle

Monitor and control individual Mangle rules.

More information about Mangle rules can be found on Mikrotik support page.

Simple Queue

Control simple queues.

More information about simple queues can be found on Mikrotik support page.

NOTE: FastTracked packets are not processed by Simple Queues.

PPP

Control and monitor PPP users.

PPP switch
PPP tracker

Host Tracking

Track availability of all network devices. All devices visible to Mikrotik device can be tracked, including: LAN connected devices and both Wireless and CAPsMAN from Mikrotik wireless package.

Host tracker

Scripts

Execute Mikrotik Router scripts.
You can execute scripts by automatically created switches or using services.

Script Switch

Kid Control

Monitor and control.

Kid Control

Accounting

RouterOS 7+ no longer support accounting

Monitor per-IP throughput tracking based on Mikrotik Accounting.

Feature is present in Winbox IP-Accounting. Make sure that threshold is set to reasonable value to store all connections between user defined scan interval. Max value is 8192 so for piece of mind I recommend setting that value.

More information about Accounting can be found on Mikrotik support page.

NOTE: Accounting does not count in FastTracked packets.

Accounting sensor

8 Likes

My integration goes to unavailable immediately after the setup.
this is the log

Logger: homeassistant.util.logging
Source: util/logging.py:108
First occurred: 7:21:46 PM (20 occurrences)
Last logged: 7:23:46 PM

  • Exception in update_controller when dispatching ‘mikrotik_router-update-Mikrotik’: () Traceback (most recent call last): File “/config/custom_components/mikrotik_router/sensor.py”, line 149, in update_controller update_items(inst, mikrotik_controller, async_add_entities, sensors) File “/config/custom_components/mikrotik_router/sensor.py”, line 174, in update_items sensors[item_id].async_schedule_update_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 441, in async_schedule_update_ha_state self.async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 292, in async_write_ha_state raise NoEntitySpecifiedError( homeassistant.exceptions.NoEntitySpecifiedError: No entity id specified for entity Mikrotik Temperature
  • Exception in update_controller when dispatching ‘mikrotik_router-update-Mikrotik’: () Traceback (most recent call last): File “/config/custom_components/mikrotik_router/binary_sensor.py”, line 48, in update_controller update_items(inst, mikrotik_controller, async_add_entities, sensors) File “/config/custom_components/mikrotik_router/binary_sensor.py”, line 71, in update_items sensors[item_id].async_schedule_update_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 441, in async_schedule_update_ha_state self.async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 292, in async_write_ha_state raise NoEntitySpecifiedError( homeassistant.exceptions.NoEntitySpecifiedError: No entity id specified for entity Mikrotik Firmware update
  • Exception in update_controller when dispatching ‘mikrotik_router-update-Mikrotik’: () Traceback (most recent call last): File “/config/custom_components/mikrotik_router/switch.py”, line 89, in update_controller update_items(inst, mikrotik_controller, async_add_entities, switches) File “/config/custom_components/mikrotik_router/switch.py”, line 138, in update_items switches[item_id].async_schedule_update_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 441, in async_schedule_update_ha_state self.async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 292, in async_write_ha_state raise NoEntitySpecifiedError( homeassistant.exceptions.NoEntitySpecifiedError: No entity id specified for entity Mikrotik port ether1
  • Exception in update_controller when dispatching ‘mikrotik_router-update-Mikrotik’: () Traceback (most recent call last): File “/config/custom_components/mikrotik_router/device_tracker.py”, line 91, in update_controller update_items( File “/config/custom_components/mikrotik_router/device_tracker.py”, line 142, in update_items tracked[item_id].async_schedule_update_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 441, in async_schedule_update_ha_state self.async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 292, in async_write_ha_state raise NoEntitySpecifiedError( homeassistant.exceptions.NoEntitySpecifiedError: No entity id specified for entity Mikrotik ether1

Any idea?

No idea, this needs closer look.
Open an issue on github and also include debugs. You can find how to enable debug on github page as well.

Hi there Im using the component mikrotik for device tracking but even when disconnected from network is reporting home anyone know how to fix that? i have a mikrotik hap ac.

Open an issue on github. There is no way to discuss and track issues in single thread.

Im using now the component and is working good the official component don´t work they should replace by yours thank you.

I will probably offer it to HA once everything is rock solid. But there is still lot of work on it :slight_smile:

Device track work like a charm and in official one dosen´t so think you should at least give it a try

@Tomaae I’ve been using this integration for a couple of months without any real problems. Installed it with HACS. Thanks a lot for your work :slight_smile:

Quick question though. How is the firmware update sensor supposed to work? It keeps displaying ‘off’ while there’s a new firmware version available for my router. I’m not sure whether it’s a setting in HA or of the router itself.

By the way, an uptime sensor would be a nice addition. Currently using an SNMP-sensor which works well too. So if anyone needs it, here’s the code that’s working for me.

The template will display the uptime in this format: 95d 11hr 9min

- platform: snmp
  host: !secret mikrotik_ip
  name: mikrotik_uptime
  baseoid: .1.3.6.1.2.1.1.3.0
  version: '2c'
  value_template: >
    {%- set time = value | int // 100 %}
    {%- set minutes = ((time % 3600) // 60) %}
    {%- set minutes = '{}min'.format(minutes) if minutes > 0 else '' %}
    {%- set hours = ((time % 86400) // 3600) %}
    {%- set hours = '{}hr '.format(hours) if hours > 0 else '' %}
    {%- set days = (time // 86400) %}
    {%- set days = '{}d '.format(days) if days > 0 else '' %}
    {{ 'Less than 1 min' if time < 60 else days + hours + minutes }}

Thats good to hear :slight_smile:
Firmware update sensor is /system/package/update/status
It is working without issues for me. If its not for you, just open a issue on github and add details + debugs.

Sure, I can add uptime sensor. What are you using that for?

I’m looking for testers for device tracking. Specially people who use mikrotik wireless as I’m not able to properly test that.
If you are having any issues with device tracking or are just interested in helping out, join conversation in following github issue:

Hey, could you tell me why I can enable/disable only main (eth1) interface? On eth2 i get message that device_tracker/turn_off. Service not found. Should I used other option?

Cant really investigate that here. Open an issue on github and include all details.

Hey tomaae. Thank you for the integration.

I have multiple mikrotik APs running. Is it possible to do device tracking over multiple APs?

Should be, I have no way to test it since mikrotik wifi never worked reliably for me.
Give it a try, if there are problems, just open an issue on github and we can have a look.

Big update 1.6 released:

  • Support for RouterOS 7+ beta

  • Granular selection for available sensors

  • Added Firewall Mangle control

  • Added PoE control for PoE capable ports

  • Added PPP users tracking and control

  • Added CPU and Board temperatures for more systems

  • Added Kid Control

  • Added Uptime sensor

  • Added Environment sensors

  • Resolve tracked device manufacturer based on MAC address

  • Added Latvian translation

  • Improved handling of duplicate NAT entries

  • Fixed conflict with aggregatied interfaces

  • Fixed crash when wrong permissions were set

  • Integration will no longer override manufacturer and model for existing devices

upon upgrade all my connection is pushing out with error

you have to enable which sensors you want in integration option now.

heem where is the options menu?

Configuration>Integrations>Mikrotik Router>Options