Voltage monitoring and ALARM to Telegram

Hi all …
I want to ask, could we create a script to monitor the voltage and send alarms to the Telegram?
Namely:
Enter the VoltAlarmMAX and VoltAlarmMIN script variables
to find out the current voltage
The script will sense the voltage at 10 intervals when it detects a drop below VoltAlarmMIN sends a message, then begins monitoring and each time it drops by 0.5Volt, it sends a message with current voltage, (example: WARNING, power failure - current voltage is xyVolt), and It will send it until the power comes on, ie If the voltage level is bigger to or equal to VoltAlarmMAX, then it sends a message (example: Power restored - current voltage is xyVolt), no more messages are sent, only if the voltage drops below VoltAlarmMIN, and the cycle repeats …

Hi,
here below you can see only the portion of code that will allow you to send a message to a Telegram BOT where you can be connected to a chat to receive notification.
So you can create your logic to get the value and data that you want, then you can send the pre-built message to Telegram using the fetch tool.
I use this for several warning that I receive from my MikroTik through Telegram BOT.

:local ReportMsg ("The message that you will display");

:if ($Value1 >= $Value2) do={
  /tool fetch url="https://api.telegram.org/botXXXXX/sendMessage?chat_id=YYYYY&text=MikroTik - $ReportMsg" keep-result=no
}

Where:

  • Value1 and Value2 are some values that come from your logic to determine voltage drop etc


  • botXXXXX is the string that you will obtain when you will have created your Telegram BOT


  • chat_id YYYYY is the value of the chat where your bot will send message to

Regards,
Armando.