Mikrotik Binding idea

I was thinking of making a Mikrotik Router Binding, which would be able to use the Mikrotik API to interact with the router, one use case I can think of is similar to the Network binding, to use the DHCP server on the Mikrotik to check if a device is online, as well as maybe pull some stats from the Mikrotik like throughput so one can put internet upload/download or number of devices on the network etc on the OH dashboard.

These are just a few of the ideas I have, would be nice to know if there are other people who would like to interact with their Mikrotik routers and what functionality would be expected with the binding.

1 Like

I would welcome a mikrotik binding.
But I don know if I really need one. :laughing:

Some features I could think of:

  • en/disable interfaces (especially for PoE devices)
  • status of interfaces like EoIP, L2TP, etc.
  • temperature?
  • count of wifi clients
  • signal strenght (per client?)

You might find more ideas in the topic:

So I gather there is no Mikrotik binding yet?

I was looking for some binding being able to use their API mainly for presence detection based on mobile devices and MAC registrations.

Home Assistant has it out of the box apparently:


I’m just a user of the openhab platform but currently have no idea how to implement a binding to achieve this.
As a workaround I was thinking if the generic http binding would be usable but not sure.

I would love to have a mikrotik binding!
But I’m pretty useless in coding.
I’ve got many of them, one being a main router, two separate access points + remote sites + spare ones.

If needed I can provide access to the API on one of them… Just as a though.

Here is example API code for Java:

https://wiki.mikrotik.com/wiki/API_in_Java

This might help.

I solved my presence usecase now with a push from RouterOS via the openHAB REST API.

1 Like

@Wolfgang_Rosenauer Can you please share your script?

I’m using CAPsMAN. In case of local wifi interface the command differs.
I found an example for non capsman like this:
/int wire reg find mac-address=“78:02:F8:7E:96:01”

name=“Presence” owner=“admin” policy=read,write,policy,test dont-require-permissions=no last-started=nov/19/2018 08:37:09 run-count=1487
source=
:global WolfgangON

  {
    :local exists [/caps-man reg find mac-address="08:C5:E1:BF:D6:DD"];
    :if ($exists!="") do={
       :if ($WolfgangON != 1) do={
          /tool fetch url="http://192.168.250.12:8080/rest/items/SensorPhoneWolfgang" http-content-type="text/plain" http-data="ON" ascii=yes http-method=post;
         :set WolfgangON 1
       }
    }  else={
       :if ($WolfgangON != 0) do={
          /tool fetch url="http://192.168.250.12:8080/rest/items/SensorPhoneWolfgang" http-content-type="text/plain" http-data="OFF" ascii=yes http-method=post;
          :set WolfgangON 0
       }
    }
  }
4 Likes

cool! thanks for that!

Unfortunately in V6.44 of RouterOS Mikrotik removed the option “http-content-type”. Meanwhile they at least updated the documentation accordingly, pointing to the option “http-header-field” as a replacement. I tried to rewrite my script, but whatever I send as header field results in a “bad request” response. Multiple “http-header-field” entries are not permitted, the parameters need to be listed, comma seperated.
Does anyone have the same issue, or even has a solution for that? I would be very grateful for every hint how to solve this.

Issue solved: Multiple header fields are not needed. As @Tema pointed out here (Mikrotik RouterOS HTTP request to OH) a few hours ago, the string defining the media type needs to be in lower case entirely.

/tool fetch url="http://<myserver>/rest/items/<myitem>/state" http-header-field="content-type: text/plain" http-data="CLOSED" ascii=yes

works with RouterOS v6.44, but

/tool fetch url="http://<myserver>/rest/items/<myitem>/state" http-header-field="Content-Type: text/plain" http-data="CLOSED" ascii=yes

results in a “400 Bad Request” message.
I changed my scripts on the Mikrotik router accordingly and now my presence detection works again.
Thanks, Tema!

I have started working on a binding for Mikrotik routers.
Would be great to recap what would be the most appreciated by users.

I found these:

  • System statuses (voltage, temperature, version, uptime, free memory etc…)
  • Interface status (disabled, mac address, etc…) What would make most sense for you to have for each interface? I plan to add enable/disable command also, but first I want to have everything to be working correctly and reading states only
  • Device presence based on MAC address and wireless registration table.

Basically any information could be fetched from the router (which you can access through terminal), so implementing all of them is not possible and would not make sense. Though that’s why I’m planning to add a command_execute channel where you can execute terminal commands and a json response is generated, so everyone can execute everything on the router directly from openHAB.

So did you ever publish this, would be interested to learn more and help.

1 Like