Xrlls / MikroTik-Home-Assistant-MQTT-telemetry

This project implements a series of MikroTik scripts to connect MikroTik RouterOS to Home Assistant and provide telemetry from the router.
GNU General Public License v3.0
15 stars 3 forks source link

Functions syntax error (line 1 column 20) #1

Closed nicopret1 closed 7 months ago

nicopret1 commented 7 months ago

@Xrlls first of all thank you for making your work available. I'm happy to test and contribute. I tried it now on my Mikrotik CRS328-24P-4S+. When I ran the script from the console I got the following:

[admin@NicoHomeCRS] > [[:parse ([/tool/fetch https://raw.githubusercontent.com/Xrlls/MikroTik-Home-Assistant-MQTT-telemetry/main/HassioInstaller.rsc output=user as-value ]->"da ta")]] HassioLib_DeviceString

HassioLib_JsonEscape

HassioLib_JsonPick

HassioLib_LowercaseHex

HassioLib_SearchReplace

Functions syntax error (line 1 column 20)

Below some screen captures to give a better idea of the status of the installation: Screenshot 2024-03-19 at 23 33 39 Screenshot 2024-03-19 at 23 33 06

Any pointers as to where the script fails or what I can check will be appreciated.

Xrlls commented 7 months ago

Hi, Firstly, which version of Router OS are the device running?

It seems it fails when trying to run HassioFirmwareEntityPublish. The “EntityPublish” files are sensitive to the hardware it is running on. They rely on the HassioLib_DeviceString.

First try running HassioLib_DeviceString: /system/script/run HassioLib_DeviceString This should return a JSON formatted string with information about your device.

Then try running HassioFirmwareEntityPublish: /system/script/run HassioFirmwareEntityPublish This will likely fail, but let me know the error.

Also, do you have the prerequisites in terms of having installed the IOT package, and configured a connection to a MQTT server?

Xrlls commented 7 months ago

I think it might be caused by your device not having the "wireless" packager or any wifi wave2 drivers installed. Since it is a switch it obviously has not wireless interfaces, but can you confirm that no wireless packages are installed?

nicopret1 commented 7 months ago

Firstly, which version of Router OS are the device running? 7.14.1

Also, do you have the prerequisites in terms of having installed the IOT package, and configured a connection to a MQTT server? Yes, IOT package is installed. I run Mosquito Broker on HA and I can publish MQTT messages. Below the json for a test scripts: {"model":"CRS328-24P-4S+","sn":"D7610D8A6F7D","ros":"7.14.1","cpu":8,"umem":71790592,"fmem":465080320,"uptime":"3d22:38:21"}

This where it fails: [admin@NicoHomeCRS] > /system/script/run HassioLib_DeviceString syntax error (line 1 column 20)

Correct, my device does not have wireless and the wireless package is not installed

nicopret1 commented 7 months ago

The wireless package was disabled, but not uninstalled. I've now uninstalled it and I then I ran the script again. It now responded with:

/system/script/run HassioLib_DeviceString cns=mac;08:55:31:92:2c:8f;mac;08:55:31:92:2c:90;mac;08:55:31:92:2c:91;mac;08:55:31:92:2c:92;mac;08:55:31:92:2c:93;mac;08:55:31:92:2c:94;mac;08:55:31:92:2c:95;mac;08:55:31:92:2c:96;mac;08:55:31:92:2c:97;mac;08:55:31:92:2c:98;mac;08:55:31:92:2c:99;mac;08:55:31:92:2c:9a;mac;08:55:31:92:2c:9b;mac;08:55:31:92:2c:9c;mac;08:55:31:92:2c:9d;mac;08:55:31:92:2c:9e;mac;08:55:31:92:2c:9f;mac;08:55:31:92:2c:a0;mac;08:55:31:92:2c:a1;mac;08:55:31:92:2c:a2;mac;08:55:31:92:2c:a3;mac;08:55:31:92:2c:a4;mac;08:55:31:92:2c:a5;mac;08:55:31:92:2c:a6;mac;08:55:31:92:2c:a7;mac;08:55:31:92:2c:a8;mac;08:55:31:92:2c:a9;mac;08:55:31:92:2c:aa;cu=http://192.168.11.1/;hw=r2;ids=D7610D8A6F7D;mdl=CRS328-24P-4S+;mf=MikroTik;name=NicoHomeCRS;sw=7.14.1 (stable)

I tried the install script again and it was now succesful

nicopret1 commented 7 months ago

Thank you so much, this is fantastic. I can report that the scripts work perfectly for the following RouterBoards that I currently use:

CRS328-24P-4S+ RB1100AHx2 RB951Ui-2HnD

I'll now go on to setup my HA dashboards and also configure the MQTT Sensors for the configuration.yaml file. Have you perhaps configured some HA sensors and dashboards that you can share?

I used "local discoverypath "MikroTik/" because I have several other MQTT interfaces. Below a screen capture from my MQTT Explorer.

Screenshot 2024-03-20 at 13 36 05
Xrlls commented 7 months ago

The code was written such that if you use the discoverypath "homeassistant, Home assistant will automatically configure alle the mqtt sensors with not work required for you. The data posted in the config topics are more less the sensor configuration though you will need to convert it from json to yaml. I have not configured any dashboards myself, as I mostly use it to get notifications about firmware updates through an automation. Maybe try https://www.json2yaml.com/ and see where that takes you :)

I have refactored the code to accommodate for situations where the wireless package is installed but disabled. I have two systems myself without wireless, but where the package happened to be installed and activated, so I had not discovered this issue myself.

nicopret1 commented 7 months ago

Thank you, that makes sense. I forgot about the auto entities that is also used for the Paradox alarm integration that I've implemented.

Thanks for the link: https://www.json2yaml.com/

nicopret1 commented 7 months ago

All working well, thank you.