Community discussions

MikroTik App
 
vaio73
just joined
Topic Author
Posts: 7
Joined: Mon Aug 14, 2023 6:05 pm

Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Mon Aug 14, 2023 6:49 pm

Hello,

I have been running a voltage monitoring script with great success for a while now.

I am now trying to run this same script on the latest firmware (7.10.2) and it is not running at all.
Where I have problem?

Here is my script:


#set lowvoltalarm to desired alarm voltage in tenths of a volt. 125 = 12.5v
:global lowvoltalarm 255
:global highvoltalarm 260
:global highvolt
:global lowvolt
:global starttime
:global hivolttime
:global lovolttime
:global vh
:global lastvoltage
:local thisbox [/system identity get name]
:global voltage [/system health get voltage]
:local thistime [/system clock get time]
:local thisdate [/system clock get date]
:local thishour [:pick $thistime 0 2]

:local emessage ($thisbox . " !!!_POWER is UP_!!! - current voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])
:local emessage1 ($thisbox . " !!!_POWER is DOWN_!!! - SYSTEM RUNS ON THE BACKUP - current voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])

:if ([:len $lowvolt] < 1) do={:set lowvolt 999; :set highvolt 0}

# set your Telegram ID in the next line
# Configure Telegram
:local CHID "-XXXXXXXXXX";
:local BotID "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

:if ($voltage <= $highvoltalarm) do={/tool fetch "https://api.telegram.org/bot$BotID/send ... $emessage1" keep-result=no;}

:if ($voltage > $highvolt) do={:set highvolt $voltage; :set hivolttime ($thistime . " " . $thisdate)}
:if ($voltage < $lowvolt) do={:set lowvolt $voltage; :set lovolttime ($thistime . " " . $thisdate)}
:if ([:len $vh] > 0) do={:set vh ([:toarray $voltage] + $vh)} else={:set vh [:toarray $voltage]}
:if ([:len $starttime] < 1) do={:set starttime ($thistime . " " . $thisdate)}
:set $lastvoltage $voltage
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Mon Aug 14, 2023 7:35 pm

🤮
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM  [SOLVED]

Mon Aug 14, 2023 8:07 pm

I am now trying to run this same script on the latest firmware (7.10.2) and it is not running at all.
Where I have problem?
change this:
:local voltage [/system health get voltage]
by:
:local voltage [/system health get [find name=voltage] value]
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Mon Aug 14, 2023 8:50 pm

Simpler script without using so many global variables.
/system health
:local tempSystem [:tonum ([get [find where name=temperature]]->"value")]
:local voltSystem ([get [find where name=voltage]]->"value")
:local tempMax    55
:local voltMin    20

# Check Temperature
:if ($tempSystem >= $tempMax) do={
    :log error "HIGH Temperature: $tempSystem\C2\BA\43"
    # put here telegram or email script
} else={
    :log info "Temperature OK: $tempSystem\C2\BA\43"
}

# Check Voltage
:if ($voltSystem <= $voltMin) do={
    :log error "LOW Voltage: $voltSystem V"
    # put here telegram or email script
} else={
    :log info "Voltage OK: $voltSystem V"
}
 
vaio73
just joined
Topic Author
Posts: 7
Joined: Mon Aug 14, 2023 6:05 pm

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Tue Aug 15, 2023 9:26 am

Simpler script without using so many global variables.
/system health
:local tempSystem [:tonum ([get [find where name=temperature]]->"value")]
:local voltSystem ([get [find where name=voltage]]->"value")
:local tempMax    55
:local voltMin    20

# Check Temperature
:if ($tempSystem >= $tempMax) do={
    :log error "HIGH Temperature: $tempSystem\C2\BA\43"
    # put here telegram or email script
} else={
    :log info "Temperature OK: $tempSystem\C2\BA\43"
}

# Check Voltage
:if ($voltSystem <= $voltMin) do={
    :log error "LOW Voltage: $voltSystem V"
    # put here telegram or email script
} else={
    :log info "Voltage OK: $voltSystem V"
}

this easy script is nice, but I need it to send me to the right about the power outage and it's conctternally

-if it records a power outage, it sends it to the right
-so at regular intervals, for example, every 15 minutes. it will send me a message about the power state even with the current Volts
-until the electricity is turned on, then it will send me only one message that the device is UP,
-it no longer sends more messages until the caretaker has run out of electricity...
 
vaio73
just joined
Topic Author
Posts: 7
Joined: Mon Aug 14, 2023 6:05 pm

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Tue Aug 15, 2023 8:20 pm

I am now trying to run this same script on the latest firmware (7.10.2) and it is not running at all.
Where I have problem?
change this:
:local voltage [/system health get voltage]
by:
:local voltage [/system health get [find name=voltage] value]
work fine... :-)
 
vaio73
just joined
Topic Author
Posts: 7
Joined: Mon Aug 14, 2023 6:05 pm

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Fri Aug 25, 2023 6:28 pm

Simpler script without using so many global variables.
/system health
:local tempSystem [:tonum ([get [find where name=temperature]]->"value")]
:local voltSystem ([get [find where name=voltage]]->"value")
:local tempMax    55
:local voltMin    20

# Check Temperature
:if ($tempSystem >= $tempMax) do={
    :log error "HIGH Temperature: $tempSystem\C2\BA\43"
    # put here telegram or email script
} else={
    :log info "Temperature OK: $tempSystem\C2\BA\43"
}

# Check Voltage
:if ($voltSystem <= $voltMin) do={
    :log error "LOW Voltage: $voltSystem V"
    # put here telegram or email script
} else={
    :log info "Voltage OK: $voltSystem V"
}
hallo...
how to set text in the telegram message as BOLD FONT in the script???
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Fri Aug 25, 2023 7:32 pm

You are able to use Google? For me is the 1st result...
https://www.google.com/search?q=script+telegram+bold+font
 
User avatar
sniper113
just joined
Posts: 16
Joined: Fri Nov 09, 2018 4:40 am
Location: Cancun Mexico

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Fri Aug 25, 2023 7:36 pm

Hello, this script itself, what would its function be? Do you use it to warn if you have low voltage in direct current? I mean, do you have battery modules or something like that?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Fri Aug 25, 2023 7:36 pm

this script itself
🤮
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Fri Aug 25, 2023 9:20 pm

how to set text in the telegram message as BOLD FONT in the script???
In your code:
:local emessage ($thisbox . " !!!_POWER is UP_!!! - current voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])
use HTML code for bold type: <b>text</b>

Example:
:local emessage ($thisbox . " <b>!!!_POWER is UP_!!!</b> - current voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])

To do this, enable Parse mode to HTML in the FETCH.
/tool fetch url="https://api.telegram.org/botXXXXXXXXXX/sendMessage\?chat_id=XXXXXXXX&parse_mode=HTML&text=$emessage" keep-result=no;
 
vaio73
just joined
Topic Author
Posts: 7
Joined: Mon Aug 14, 2023 6:05 pm

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Sat Aug 26, 2023 1:20 pm

how to set text in the telegram message as BOLD FONT in the script???
In your code:
:local emessage ($thisbox . " !!!_POWER is UP_!!! - current voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])
use HTML code for bold type: <b>text</b>

Example:
:local emessage ($thisbox . " <b>!!!_POWER is UP_!!!</b> - current voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])

To do this, enable Parse mode to HTML in the FETCH.
/tool fetch url="https://api.telegram.org/botXXXXXXXXXX/sendMessage\?chat_id=XXXXXXXX&parse_mode=HTML&text=$emessage" keep-result=no;
great, it works, except I used it " &parse_mode=markdown " ( *bold* )
 
vaio73
just joined
Topic Author
Posts: 7
Joined: Mon Aug 14, 2023 6:05 pm

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Sat Aug 26, 2023 1:26 pm

Hello, this script itself, what would its function be? Do you use it to warn if you have low voltage in direct current? I mean, do you have battery modules or something like that?
Yes, I use to monitor the power outage and send the current state to the battery
 
vaio73
just joined
Topic Author
Posts: 7
Joined: Mon Aug 14, 2023 6:05 pm

Re: Voltage Monitoring in ROS v.7 and send message to TELEGRAM

Sat Aug 26, 2023 1:55 pm

updated (modified) script...

/system health

:local voltMin 24

:global highvolt
:global lowvolt
:global starttime
:global hivolttime
:global lovolttime
:global vh
:global lastvoltage
:local thisbox [/system identity get name]
:local voltSystem ([get [find where name=voltage]]->"value")
:local thistime [/system clock get time]
:local thisdate [/system clock get date]
:local thishour [:pick $thistime 0 2]

# set your Telegram ID in the next line
# Configure Telegram
:local CHID "-XXXXXXXXX";
:local BotID "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

# Check Voltage

:if ($voltSystem >= $voltMin and $lastvoltage < $voltMin) do={:log warning "!!!_POWER is UP_!!! - Current Voltage is: $voltSystem V";}
:if ($voltSystem >= $voltMin and $lastvoltage < $voltMin) do={/tool fetch "https://api.telegram.org/bot$BotID/send ... n&text=%0A*.::: $thisbox :::.*%0A*!!!_POWER is UP_!!!*%0A%0Current Voltage is: *$voltSystem V*%0A" keep-result=no;}
:if ($voltSystem <= $voltMin and $lastvoltage > $voltMin) do={:log error "!!!_POWER is DOWN_!!! - SYSTEM is run from the battery - Current Voltage is: $voltSystem V";}
:if ($voltSystem <= $voltMin and $lastvoltage > $voltMin) do={/tool fetch "https://api.telegram.org/bot$BotID/send ... n&text=%0A*.::: $thisbox :::.*%0A*!!!_POWER is DOWN_!!! %0ASYSTEM is run from the battery%0A*%0ACurrent Voltage is: *$voltSystem V*%0A" keep-result=no;}

:if ($voltSystem > highvolt) do={:set highvolt $voltSystem; :set hivolttime ($thistime . " " . $thisdate)}
:if ($voltSystem < $lowvolt) do={:set lowvolt $voltSystem; :set lovolttime ($thistime . " " . $thisdate)}
:if ([:len $vh] > 0) do={:set vh ([:toarray $voltSystem] + $vh)} else={:set vh [:toarray $voltSystem]}
:if ([:len $starttime] < 1) do={:set starttime ($thistime . " " . $thisdate)}
:set $lastvoltage $voltSystem

Who is online

Users browsing this forum: diamuxin, Nullcaller and 6 guests