Has anyone gotten RouterOS MQTT to work with Home Assistant, preferably with autodiscovery?
Having a hard time making it work.
Has anyone gotten RouterOS MQTT to work with Home Assistant, preferably with autodiscovery?
Having a hard time making it work.
U mean run broker and ha into mikrotik docker?
To have MT publish into HA (using HA’s MQTT and Mosquitto, for example).
Brrrr, what’s the problem homie? Why u ask 'bout ha and mqtt in mikrotik forum? I ask again, are u deploy home assistant and mqtt server in docker in mikrotik?
I would like to publish MQTT from my MT devices to HA.
HA running its own MQTT server.
I’m asking about getting the MT MQTT autodiscovery working.
Thank you.
Mikrotik doesn’t automatically publish anything to any MQTT — you write script to publish data you want. And MQTT doesn’t have discovery mechanism either, you publish and/or subscribe. So the MQTT part here is what I’m not sure what you’re looking to do?
I don’t use Home Assistant, but seems the plugin https://www.home-assistant.io/integrations/mikrotik/ uses the Mikrotik API, not MQTT.
I understand that a script (or CLI) is used to tell the MT device to publish an MQTT packet.
I know extremely little about this, but it sure seems like there is indeed an MQTT discovery available:
https://www.home-assistant.io/integrations/mqtt
And, yes, there is a Mikrotik integration, but MQTT opens up more data (I think) to send to Home Assistant.
They have a schema for topics names. So you publish to the topic as in described in docs. In quick look, “Discovery” is just a device publishing a message via the “homeassistant/status” topic — which is described in the linked docs.
Since there doesn’t appear to be MQTT-based integration already, it be a lot of work to map all the HA exposed(subscribed) topic to RouterOS script that publish to HA via MQTT broker. I’d start with the existing API-based plugin and figure out if that meets your objectives first… If not, you’d know what’s missing, and then fill in with custom MQTT messages.
I have made this MQTT “integration” for Home Assistant with auto discovery:
https://github.com/Xrlls/MikroTik-Home-Assistant-MQTT-telemetry
It is made for my own purposes, so the metrics may not match your use cases, or may require modification, also it does not offer any control of the router.
Specifically for auto discovery, take a loo at these files:
…EntityPublish.rsc
HassioLib_DeviceString.rsc
Wow!
That is exactly what I needed.
The scripts work great, and are so well done.
I am eager to explore them all.
FYI, using “Hassio Firmware Entity Publish” in HA Devices, it shows the RouterOS version of the latest available in the currently used channel (instead of the currently installed one). If you click on it for more details, it shows and properly identifies both. Not sure if this is what you prefer.
Thank you so much for making and sharing this!
I’m glad you like it! To my knowledge, you are the first user beyond myself ![]()
The intention with the firmware versions is that “Hassio Firmware Entity Publish.rsc” creates the update entity, and populates the device info with the current version from
/system/resource/
and the update entitys payload data is then published by “Hassio Firmware State Publish.rsc”, which gets the current and the newest available version from:
/system/package/update/
The current version from /system/resource and /system/package/update is identical, except the first one includes both version and current channel in the returned string, while the later only shows the current version.
That’s really impressive.
When time allows, I’ll study and hopefully learn from your code and be able to have HA maintain the currently connected hosts with all associated info as well as a history of connections and activity.
Sort of like a log analyzer but with better data management.
A simple couple of scripts to send router status data to Home Assistant using MQTT.
First script uses the “auto discovery” feature of Home Assistant to configure the device.
It can be executed by scheduler at startup with interval 00:00:00 (so only once).
#config
:local broker "homeassistant"
:local topic "homeassistant/sensor/mikrotik_"
#gather info
:local model [/system routerboard get value-name=model]
:local name [/system identity get value-name=name]
:local board [/system resource get value-name=board-name]
:local version [/system resource get value-name=version]
:local serial [/system/routerboard get serial-number]
#compose message in JSON - CPU load
:local message "{\"device\": {\"mf\": \"MikroTik\", \"identifiers\": \"MT-$serial\", \"model\": \"$model\", \"sw\": \"$version\", \"name\": \"$name\"}, \"unique_id\": \"MT-$serial-cpuload\", \"state_topic\": \"$topic$name/cpuload\", \"unit_of_measurement\": \"%\", \"state_class\": \"measurement\", \"name\": \"CPU load\"}"
:put $message
/iot mqtt publish broker=$broker topic="$topic$name/cpuload/config" message=$message retain=yes
/log/info message=$message
#Up time - \"board\": \"$board\",
:local message "{\"device\": {\"mf\": \"MikroTik\", \"identifiers\": \"MT-$serial\", \"model\": \"$model\", \"sw\": \"$version\", \"name\": \"$name\"}, \"unique_id\": \"MT-$serial-uptime\", \"state_topic\": \"$topic$name/uptime\", \"unit_of_measurement\": \"s\", \"state_class\": \"total\", \"name\": \"Up time\"}"
:put $message
/iot mqtt publish broker=$broker topic="$topic$name/uptime/config" message=$message retain=yes
/log/info message=$message
The second script sends the data (only cpu load and up time). It can be runned by scheduler with an interval of some minutes.
#config
:local broker "homeassistant"
:local topic "homeassistant/sensor/mikrotik_"
#gather info
:local name [/system identity get value-name=name]
:local cpuLoad [/system resource get cpu-load]
:local upTime [:tonum [/system resource get uptime]]
#CPU load
:local message "$cpuLoad"
:put $message
/iot mqtt publish broker=$broker topic="$topic$name/cpuload" message=$message retain=no
/log/info message=$message
#Up time
:local message2 "$upTime"
:put $message2
/iot mqtt publish broker=$broker topic="$topic$name/uptime" message=$message2 retain=no
/log/info message=$message2
Adding more data is trivial and more complex script exists but I wanted to share something simple and good for learning.

Hello Friends my first post
trying this integration
https://github.com/Xrlls/MikroTik-Home … -telemetry
works nice.
However.
I have a mikrotik KNOT i would like to get the IoT Bluethoot to show up in HA "for telemetr “i have mikrotik bacons” + so somekind of script “decode” needs to be run on the serverside “HA” MT has a script yes but how to integrate it in HA ..
then i have the MT WapLora gateway “for lorawan” that i would like to get to work with HA..
Is here anyone that can give me advice how to "modify Xrlls integration so i could test this out ?
THANX
Hi! I am happy that you like my project!
I have not looked at the KNOT and Bluetooth before, and I have not had a use case for these device in my setup yet. So I am starting from scratch.
On the Bluetooth side, if using Mikrotik beacons with the Knot, it seems like the payload is decoded on the device (https://help.mikrotik.com/docs/display/ROS/Bluetooth#Bluetooth-PeripheralDevices) taking this doing a bit of reformatting, and wrapping it in MQTT along with some Home Assistant auto discovery protocol is definitely doable and is mostly what my project is doing.. It gets a bit harder if you want the beacons to serve as a device tracker in a setup with multiple KNOTs. It should be possible to handle all on this on the Mikrotik device, no coding on Home Assistant required.
Right now I am working on adding UPS support. This could be kind-off relevant, as it exposed the UPS as a separate device with its own entities, connected through a Mikrotik router in Home Assistant. So some of this could architecturally be reused for the Bluetooth Beacons.
Lora is definitely a no-go. The Lora implementation on Mikrotik is designed to talk to a server back-end, and there seems to be no information available on the Mikrotik device itself regarding data received on Lora. So integrations with Lora should be between the server back-end and Home Assistant.
Hi i tryed to decode on the Knot but its taking to much cpu power, so the decoding should be done on server side “running proxmox with HA” as mikrotik suggest.
If it would be possible to have two knots "would be perfect
" but to get attleast 1 to connect to Ha would be awesome..
but as im kind of new to this i would like to know how to decode the payloads from mt on the serverside.
what kind of ups support do you implement ?
"i have a network apc ups running with NUT integration in Ha.
Well i think the lora works like this mt —>tts–>Ha ..as cloud.. must check out what kind of integration i need to get, so Ha understands what TTS is pushing to HA ?"?
I put in an order on the KNOT and a few BLE tags. I guess that in the end the Temptation was to big ![]()
It is now in my desk!
The Knot really does a lot of stuff!
For now I have added support of firmware update notification for the NB/CAT-M radio.
I think on my program next is support of the GPIOs. as sensors, binary sensors and switches respectively.
I am starting to wrap my head around the Bluetooth trackers and what telemetry they report, abut also for device tracking. I am trying to work out a decentralized scheme where multiple Knots can work out which of them are closest to a BLE tag in case it is in range of multiple Knots at the same time.
Regarding decoding on the payload, it should be pretty straight forward to create some Jinja templates that enables Home Assistant to decode it server side, so it can forwarded raw. How many tags were you using and were you decoding all payloads when you consumed all CPU? The process seems very trivial, so I thought it shouldn’t be too hard for even a low power device.
I don’t think I will spend time on the Lora and the Modbus at the moment. There seems to be an existing Things Network integration for Home Assistant, so there is probably not a lot of value to add. The same goes for Modbus, where there is a Modbus over TCP integration. Also, I have no Modbus devices.
The UPS integratiion is (of course) when you have a support UPS connected to your Mikrotik router through USB or RS232. it is nice to get some telemetry from it.
If your KNOT is a LoRa-enabled one… I’ll note there are a lot of fun LoRaWAN sensors available, for a lot weird things, that likely be cool in some HA dashboard
. And if you already have a HomeAssistant container/server… you can run ChripStack to on own server too, to avoid needing the Things Network cloud.
for now i have 4 MT bluethoot tags..
I did run the decoder on the MT “as mikrotik documention” and with one mt ble bacon. and the cpu did go 100% when its decoding.
Things Network integration for Home Assistant <— i use this integration its fine , but its allways cloud based.. so would be nice to have it as lan only sending parameters to Ha derectly humm.?!?
“have mt outdoor lora gateway”
would be wery nice if you would get the telemetry to work with multiple knots…
i have one Knot, but i would order a second for my basement if its somehow possible to track the tags in the house.
how is bluethoot integration going so far , cant wait to test it out ![]()
Cheers: Niklas
@Ammo The KNOT is Lora enabled. I guess I am “future proofing” Something more to explore later ![]()
@niklaswelin I have something working now with Home Assistant auto discovery and decoding of the payload server side through Jinja templates. There is a lot missing though in terms of logic to keep the MQTT traffic reasonable. The current implementation is pretty brute force. Anyway, an appetizer:

As it can be seen something is wrong with the device tracker entity. I will see if I can get it packaged into something I feel comfortable sharing ![]()