Mikrotik Router integration

I really wish I had found this some time ago! I have developed RouterOS scripts and schedules with MQTT to send metrics to HA. My attempt is nothing like yours! However, I do display this…

I shall have a good look at HACS. Thank you and well done to all who contribute!

looks good to me. I really like those wifi quality gauges.
my implementation of wifi components is lacking in my opinion. since I dont use mikrotik for wifi, I dont know much about it, so it depends on what people request.
if you find something missing, you can always open a feature request.

Not sure if its my implementation/configuration, but I can’t get ip address for a VLAN interface to show in HA. Any hints?

Thanks!!

Because there is nothing in arp assigned to that interface

1 Like

But there is:
image

Still, it doesn’t show up in HA:

This is not a good platform for troubleshooting. Open an issue on github and provide debugs as well. We can have a look.

1 Like

Is there a way to update traffic sensor every 5 seconds? It appears that lowest value is 30sec.

no, there is no lower limit set by integration.
but its unlikely mikrotik can process all data in 5 seconds. you are limited to how fast your router can give all required data to integration and how fast your ha device can process it.
those sensors are not snapshots tho, they are average for update period.

c’mon my power meter has 40 sensors and is updating them real time, more than every second. Mikrotik can process Gbit of data every second so few bytes every 5 sec should not be any problem.

You cannot really compare those two. API design is very different there. You can do those if API is designed to push data or is really fast. Mikrotik API is non of those. Most APIs are just not designed that way.
You would need to design an integration just around this idea with no other functionality or thread everything, but that would be risky. client traffic would still not be possible under 5 sec probably.

Thank you for clarification.
I’ll have to live with it :wink:

How did you change how to show uptime?
Because in my case it’s just say like “yesterday” “3 days ago” and so.

it is controlled by HA, not integration.

Hello, I am very new to the HA. Went here from Domoticz and having Mikrotik hardware started using your integration. Thank you for the effort and that you have created it. I faced one issue I could not find a solution. It seems that whatever I do, I cannot go below 30secs of refresh. Having regular monitoring on Tx/Rx on my WAN interface it is useless for me. e.g. executing speedtest sometimes I am hiting only end of the process. Completely loosing details.
To give brief context - I have set the scan time from 30 down to 1 sec (10secs and 5 in between). But observing status of the interface I can see it is refreshing for every 30 secs. What am I doing wrong? Other integrations are working much more frequent?

Thanks

1 Like

That depends on how fast your device can provide all the information you require from the integration.
Cant compare it to other integrations, as other devices and APIs work differently. Realtime is pretty much impossible with mikrotik, you would need to create integration dedicated just for traffic monitoring to get anywhere to 5sec resolution. Type of API mikrotik provides is not suitable for that kind of thing.

Speedtest should not affect response time in any way, unless your mikrotik hardware is really slow.

Well, i am using RB 3011 on my side. That is curious, because as I mentioned have been using domoticz for long time. And i had (i am not 100% sure exact numbers) something near realtime. Numbers of 2-5secs. I do not believe device itself is an issue. Hardware is pretty powerful
That is my concern. I observed issue than when i changed time to 45 and e.g. i am able to see timer since last update going above 1m. Weird. Cannot go below 30seconds. I am not talking about speedtest influence - rather as something that would immediately show RX/TX high values. Test itself takes few seconds. So sometimes it is even not noticeable within that 30secs window

First config page - I am having 5seconds on Scan Interval. Second screen has only two top checkbox set.
After saving config I am getting 12 devices.
Clicking at the link “12 devices” - Selecting SFP1 which has attached SFP plug. Selecting property RX, then window at the top shows something like: “SFP1 Rx” with info “xxx seconds ago” and for me the case is always exactly every 30seconds update.

if you want to investigate it, you can run integration in debug and check all API queries and how long each one takes.
Traffic is averaged over scan interval, so you cannot miss even short burst.

Ok, so I have enabled the debug. And results are what I expected (if I understand that correctly) - query and processing combined takes fraction of a single second.
Just out of curiosity: you are using 4011 as sampler for documentation - Is that something that you have on your own ? → I do not know what a platform are you using for the HA itself but I am pretty sure that issue lays somewhere on the HA side - some kind of worker configuration or so.

I investigated it a bit and what I have found:

  • Open the log and look for some pattern - for me e.g. “[custom_components.mikrotik_router.apiparser] Processing source [{’.id’: ‘*174’, ‘mac-address’: ‘REDACTED’,”
  • press ctrl-f many times.
    What can I see? It repeats every 5 secs! => It seems that plugin is at some point working perfectly.
    What is the reason to report to HA within 30 seconds only?

Sample logs cut off on the right side:

Summary
2023-02-14 14:08:13.765 DEBUG (SyncWorker_2) [custom_components.mikrotik_router.mikrotikapi] API query: /system/resource
2023-02-14 14:08:13.771 DEBUG (SyncWorker_2) [custom_components.mikrotik_router.apiparser] Processing source [{'uptime': '1d2h53m4s', 'version': '6.49.7 (stable)', 'build-time': 'Oct
2023-02-14 14:08:13.772 DEBUG (SyncWorker_2) [custom_components.mikrotik_router.apiparser] Processing entry {'uptime': '1d2h53m4s', 'version': '6.49.7 (stable)', 'build-time': 'Oct/1
2023-02-14 14:08:13.773 DEBUG (SyncWorker_2) [custom_components.mikrotik_router.mikrotikapi] API query: /system/package/update
2023-02-14 14:08:14.778 DEBUG (SyncWorker_2) [custom_components.mikrotik_router.mikrotikapi] API query: /system/package/update
2023-02-14 14:08:14.781 DEBUG (SyncWorker_2) [custom_components.mikrotik_router.apiparser] Processing source [{'channel': 'stable', 'installed-version': '6.49.7', 'latest-version': '
2023-02-14 14:08:14.782 DEBUG (SyncWorker_2) [custom_components.mikrotik_router.apiparser] Processing entry {'channel': 'stable', 'installed-version': '6.49.7', 'latest-version': '6.
2023-02-14 14:08:14.785 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.mikrotikapi] API query: /system/health
2023-02-14 14:08:14.789 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.apiparser] Processing source [{'voltage': 24, 'temperature': 43}]
2023-02-14 14:08:14.789 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.apiparser] Processing entry {'voltage': 24, 'temperature': 43}
2023-02-14 14:08:14.792 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.mikrotikapi] API query: /ip/dhcp-client
2023-02-14 14:08:14.797 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.apiparser] Processing source [{'.id': '*2', 'interface': 'WAN1', 'add-default-route': False, 'use-pee
2023-02-14 14:08:14.798 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*2', 'interface': 'WAN1', 'add-default-route': False, 'use-peer-
2023-02-14 14:08:14.798 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*5', 'interface': 'WAN2', 'add-default-route': False, 'use-peer-
2023-02-14 14:08:14.802 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface
2023-02-14 14:08:14.845 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'.id': '*1', 'name': 'WAN1', 'default-name': 'ether1', 'type': 'ether',
2023-02-14 14:08:14.846 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*1', 'name': 'WAN1', 'default-name': 'ether1', 'type': 'ether', '
2023-02-14 14:08:14.846 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*6', 'name': 'WAN2', 'default-name': 'sfp1', 'type': 'ether', 'mt
2023-02-14 14:08:14.847 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*2', 'name': 'ether2', 'default-name': 'ether2', 'type': 'ether',
2023-02-14 14:08:14.847 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*3', 'name': 'ether3', 'default-name': 'ether3', 'type': 'ether',
2023-02-14 14:08:14.848 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*4', 'name': 'ether4', 'default-name': 'ether4', 'type': 'ether', 
2023-02-14 14:08:14.848 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*5', 'name': 'ether5', 'default-name': 'ether5', 'type': 'ether', 
2023-02-14 14:08:14.848 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*7', 'name': 'ether6', 'default-name': 'ether6', 'type': 'ether', 
2023-02-14 14:08:14.849 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*8', 'name': 'ether7', 'default-name': 'ether7', 'type': 'ether', 
2023-02-14 14:08:14.849 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*9', 'name': 'ether8', 'default-name': 'ether8', 'type': 'ether', 
2023-02-14 14:08:14.850 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*A', 'name': 'ether9', 'default-name': 'ether9', 'type': 'ether', 
2023-02-14 14:08:14.850 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*B', 'name': 'ether10', 'default-name': 'ether10', 'type': 'ether'
2023-02-14 14:08:14.853 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.925 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'.id': '*1', 'name': 'WAN1', 'default-name': 'ether1', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.926 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*1', 'name': 'WAN1', 'default-name': 'ether1', 'mtu': 1500, 'l2mtu
2023-02-14 14:08:14.927 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*6', 'name': 'WAN2', 'default-name': 'sfp1', 'mtu': 1500, 'l2mtu':
2023-02-14 14:08:14.927 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*2', 'name': 'ether2', 'default-name': 'ether2', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.928 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*3', 'name': 'ether3', 'default-name': 'ether3', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.928 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*4', 'name': 'ether4', 'default-name': 'ether4', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.929 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*5', 'name': 'ether5', 'default-name': 'ether5', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.929 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*7', 'name': 'ether6', 'default-name': 'ether6', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.929 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*8', 'name': 'ether7', 'default-name': 'ether7', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.930 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*9', 'name': 'ether8', 'default-name': 'ether8', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.930 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*A', 'name': 'ether9', 'default-name': 'ether9', 'mtu': 1500, 'l2m
2023-02-14 14:08:14.931 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'.id': '*B', 'name': 'ether10', 'default-name': 'ether10', 'mtu': 1500, 'l
2023-02-14 14:08:14.932 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.932 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*1', 'once': True}
2023-02-14 14:08:14.944 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'WAN1', 'status': 'link-ok', 'auto-negotiation': 'done', 'rate': 
2023-02-14 14:08:14.944 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'WAN1', 'status': 'link-ok', 'auto-negotiation': 'done', 'r
2023-02-14 14:08:14.945 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.945 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*6', 'once': True}
2023-02-14 14:08:14.954 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'WAN2', 'status': 'no-link', 'auto-negotiation': 'done', 'advert
2023-02-14 14:08:14.954 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'WAN2', 'status': 'no-link', 'auto-negotiation': 'done', 'adver
2023-02-14 14:08:14.954 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.955 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*2', 'once': True}
2023-02-14 14:08:14.959 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether2', 'status': 'link-ok', 'auto-negotiation': 'don
2023-02-14 14:08:14.959 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether2', 'status': 'link-ok', 'auto-negotiation': 'do
2023-02-14 14:08:14.959 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.960 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*3', 'once': True}
2023-02-14 14:08:14.964 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether3', 'status': 'no-link', 'auto-negotiation': 'don
2023-02-14 14:08:14.964 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether3', 'status': 'no-link', 'auto-negotiation': 'don
2023-02-14 14:08:14.964 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.964 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*4', 'once': True}
2023-02-14 14:08:14.968 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether4', 'status': 'link-ok', 'auto-negotiation': 
2023-02-14 14:08:14.969 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether4', 'status': 'link-ok', 'auto-negotiation
2023-02-14 14:08:14.969 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.969 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*5', 'once': True}
2023-02-14 14:08:14.973 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether5', 'status': 'link-ok', 'auto-negotiation': '
2023-02-14 14:08:14.974 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether5', 'status': 'link-ok', 'auto-negotiation':
2023-02-14 14:08:14.974 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.974 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*7', 'once': True}
2023-02-14 14:08:14.978 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether6', 'status': 'link-ok', 'auto-negotia
2023-02-14 14:08:14.978 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether6', 'status': 'link-ok', 'auto-negoti
2023-02-14 14:08:14.979 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.979 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*8', 'once': True}
2023-02-14 14:08:14.982 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether7', 'status': 'no-link', 
2023-02-14 14:08:14.983 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether7', 'status': 'no-link', '
2023-02-14 14:08:14.983 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.983 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*9', 'once': True}
2023-02-14 14:08:14.987 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether8', 'status': 
2023-02-14 14:08:14.988 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether8', 'status': 
2023-02-14 14:08:14.988 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.988 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor, {'.id': '*A', 'once': True}
2023-02-14 14:08:14.992 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether9', 
2023-02-14 14:08:14.993 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether9',
2023-02-14 14:08:14.993 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet
2023-02-14 14:08:14.993 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/ethernet, monitor,
2023-02-14 14:08:14.997 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing source [{'name': 'ether10', 
2023-02-14 14:08:14.997 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.apiparser] Processing entry {'name': 'ether10', 
2023-02-14 14:08:15.000 DEBUG (SyncWorker_3) [custom_components.mikrotik_router.mikrotikapi] API query: /caps-man/regist
2023-02-14 14:08:15.003 DEBUG (SyncWorker_0) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/wireless
2023-02-14 14:08:15.005 DEBUG (SyncWorker_1) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/wirel
2023-02-14 14:08:15.007 DEBUG (SyncWorker_7) [custom_components.mikrotik_router.mikrotikapi] API query: /interface/bridge

4011 is my personal router. I used it for documentation as it show real life data.
I own 4 more mikrotik devices and 2 VMs I use for development.
For HA, I use NUC-like box based on Celeron N4100 and 8GB of ram.

You will see processing source message got every API query. But if you want to go into more detail, open an issues on github. This is not a good place for such a thing.

1 Like

I just found and installed this integration and all I can say is wow! This is so robust - and it worked out of the box. Thank you so much for putting in the time and your talent to create this!

Also - and there’s not really any way to ask this without sounding lazy - but has anyone designed a full dashboard for displaying all of this data in a nicely organized way - that they wouldn’t mind sharing? There is a lot of data exposed and I don’t have a clue what the best way to present/organize it would be and would appreciate it if someone who does would be willing to share theirs?

Thanks in advance!