Mail notification at temperature with TG-BT5-OUT

Hi,

is it possible for me to receive an e-mail if, for example, it reaches 30 degrees Celsius?
If yes how? Many Thanks

This is what I am using on ROS 7. Will not work on 6.

1st, get the sensor name with

/system health print

2nd. edit the script and change the desired values

:local DesiredTemp 70
:local MonitoredSensor "phy-temperature"
:local NotifyTo ToEmail@domain.com"
:local NotifyFrom "RouterOS-Monitor<FromEmail@domain.com>"
:local DeviceName [/system identity get name];
:local CurrentTemp [/system/health get [find name=$MonitoredSensor] value]
:local LogMessage ""
:global IsNotifiedAbove;
:global IsNotifiedBelow;
{
:if ($CurrentTemp>$DesiredTemp) do={
      :if ($IsNotifiedAbove !=1) do= {
      :set LogMessage "Temperature for $MonitoredSensor is over the limit: $CurrentTemp Celsius"
      :log warning $LogMessage;
      
/tool e-mail 
      set from="$NotifyFrom" 
      send to="$NotifyTo" \
      subject="Temperature warning on $DeviceName" body="The current temperature for $MonitoredSensor of $CurrentTemp Celsius is over the set limit of $DesiredTemp Celsius" ;
      :set IsNotifiedAbove 1;
      :set IsNotifiedBelow 0;
      } 
}
:if ($CurrentTemp<$DesiredTemp) do={
      :if ($IsNotifiedBelow !=1) do= {
      :set LogMessage "Temperature for $MonitoredSensor is now back to normal: $CurrentTemp Celsius"
      :log warning $LogMessage;
      
/tool e-mail 
      set from="$NotifyFrom" 
      send to="$NotifyTo" \
      subject="Temperature warning on $DeviceName" body="The current temperature for $MonitoredSensor of $CurrentTemp Celsius is now under the set limit of $DesiredTemp Celsius" ;
     :set IsNotifiedAbove 0; 
     :set IsNotifiedBelow 1;
      } 
}
}

3rd. Set the script to run every n minutes.

Don’t forget to setup email server details under /Tools/Email

I don’t think it refers to the routerboard, but to the external TG-BT5-OUT…

Indeed, I admit I never bothered to look for what exactly the model is.
As it seems it is not a RouterOS device, forget what I said

Yes, the TG-BT5-OUT has a temperature sensor. I would like to use this to monitor a server room. For example, if it is more than 40 degrees, then an SMS or e-mail should be sent. Wouldn’t that be an interesting project?

Here I was also given great help by Mikrotik Support.

The script now sends an email if the temperature is higher than X.
What to note is that the CPU load is quite high.
But we only use the knot to monitor a server room when the air conditioning fails. That is completely sufficient for that.

    # POSIX regex for filtering advertisement Bluetooth addresses. E.g. "^BC:33:AC"
    # would only include addresses which start with those 3 octets.
    # To disable this filter, set it to ""
    :local addressRegex "AC:4C:6E:19:60:82"

    # POSIX regex for filtering Bluetooth advertisements based on their data. Same
    # usage as with 'addressRegex'.
    :local advertisingDataRegex ""

    # Signal strength filter. E.g. -40 would only include Bluetooth advertisements
    # whose signal strength is stronger than -40dBm.
    # To disable this filter, set it to ""
    :local rssiThreshold ""

    ####The lines below are used for the data conversion from hex to dec###

        :global invertU16 do={
            :local inverted 0
            :for idx from=0 to=15 step=1 do={
                :local mask (1 << $idx)
                :if ($1 & $mask = 0) do={
                    :set $inverted ($inverted | $mask)
                }
            }
            return $inverted
        }

        :global le16ToHost do={
            :local lsb [:pick $1 0 2]
            :local msb [:pick $1 2 4]

            :return [:tonum "0x$msb$lsb"]
        }
:local le32ToHost do={
    :local lsb [:pick $1 0 2]
    :local midL [:pick $1 2 4]
    :local midH [:pick $1 4 6]
    :local msb [:pick $1 6 8]

    :return [:tonum "0x$msb$midH$midL$lsb"]
}
        :local from88 do={
            :global invertU16
            :global le16ToHost
            :local num [$le16ToHost $1]

            # Handle negative numbers
            :if ($num & 0x8000) do={
                :set num (-1 * ([$invertU16 $num] + 1))
            }

            # Convert from 8.8. Scale by 1000 since floating point is not supported
            :return (($num * 125) / 32)
        }

    ################################## Bluetooth ##################################
    :put ("[*] Gathering Bluetooth info...")
    :global AOldestAdvTimestamp
    :if ([:typeof $AOldestAdvTimestamp] = "nothing") do={
        # First time this script has been run since booting, need to initialize
        # persistent variables
        :set $AOldestAdvTimestamp 0
    }
    :local btProcessingStart [/system clock get time]
    :local advertisements [/iot bluetooth scanners advertisements print detail \
        as-value where \
            epoch > $AOldestAdvTimestamp and \
            address ~ $addressRegex and \
            data ~ $advertisingDataRegex and \
            rssi > $rssiThreshold
    ]
    :local advJson ""
    :local advCount 0
    :local advSeparator ""
    :local lastAdvTimestamp 0

:global lastadv
###this line picks the last payload advertisment from the list
:set lastadv [:pick $advertisements ([:len $advertisements]-1)]
:global payl
###this line picks the paload from the lastadvertisment
:set payl [:pick $lastadv 4]
:put $payl
##this line converts hex to dec from the two bytes from the payload that represent temperature
global temp [$from88 [:pick $payl 28 32]]
:put $temp
 :global uptime [$le32ToHost [:pick $payl 32 40]]
:put $uptime

:if ($temp > 3600) do={
        # dividend / divisor = quotient.decimal = result

         :local dividend "$temp"
         :local divisor 1000
         :local decimalplaces 3


         # Math Calculation here
         :local quotient 0
         :local remainder 0
         :global result 0
         :global decimal 0

         :set quotient ($dividend / $divisor)

         :if ($quotient = 0) do={
                   :set dividend [:tonum ($dividend . "0")]
         }

         :set remainder ($dividend - ($divisor * $quotient))

         :log info $remainder

         :if ($remainder > 0) do={
                   :local tmpremainder [:tonum ($remainder . "0")]
                   :for x from=1 to=$decimalplaces do={
                             :local tmpdecimal [:tonum ($tmpremainder / $divisor)]
                             :set decimal [:tonum ($decimal . $tmpdecimal)]
                             :set tmpremainder [:tonum (($tmpremainder - ($tmpdecimal * $divisor)) . "0")]
                   }
                   :local decimalTens 1
                   :local leadingZeros
                   :for y from=1 to=($decimalplaces -1) do={
                             :set decimalTens ($decimalTens * 10)
                             :if ($decimal < $decimalTens) do={
                                       :set leadingZeros ($leadingZeros . "0")
                             }
                   }


:set result ($quotient . "." . $leadingZeros . $decimal)

         } else={
                   :set result $quotient
         }
         # END Math Calculation here
:put ($dividend . " / " . $divisor . " = " . $result)
:put $result;

/tool e-mail send to="mail@domain.com" subject="Temperature" body="Temperature is $result !";
:put ("[*] Temperature over set value was detected. Sending email...")} else={:put ("[*] Temperature is lower than set value - no email...")}