This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Notification of exceeding wind speed threshold
#1
hello

I need to send a notification to telegram that a certain wind speed threshold has been exceeded.

To get started, create the following script as a proof of principle

Code:
require("user.Telegram")                         -- Requiere la librería de usuario

valor_actual_viento = grp.getvalue('1/0/3')
valor_umbral_viento = grp.getvalue('32/1/7')


if valor_actual_viento >= valor_umbral_viento then
message = 'Alarma de viento ' ..valor_actual_viento.. 'm/s'         -- Texto del mensaje a enviar
telegram(message)                             -- Se pasa a la biblioteca de usuario el mensaje
log(message)
 
end

The problem is that while the wind alarm signal is above the threshold, notifications are sent continuously, I only want it to be sent once and require user action to dismiss the alarm.

How could I do it?

Thank you
Reply
#2
Hello JRP!

You can make a script for current wind speed object. You will have three objects 1.)current wind speed, 2.)wind speed threshold 3.)alarm (boolean object)

Code:
local wind_current = grp.getvalue('34/1/57')
local wind_treshold = grp.getvalue('34/1/59')
local alarm = grp.getvalue('34/1/60') -- if alarm was already running do not send new telegram

if ( (wind_current >= wind_treshold) and not alarm ) then
  grp.write('34/1/60', true) -- set alarm true
  message = 'Alarm wind speed is ' .. wind_current .. ' m/s'
  log(message)
end

Every time when wind speed changes, script will check the value of wind speed, if it is above threshold value (and alarm was off) it sets alarm object value to true and sends log. Next time if alarm was on (alarm object value was true) it will not send any log (till you unset the alarm object).
Reply
#3
thanks i will try it.

Greetings
Reply
#4
Hello
The script does not work, the message to telegram says sending.

The funny thing is that once the alarm has been activated and the notification is not supposed to be sent to Telegram, the log does not appear, but the notification is sent.

I have put the else statement, a variable with a fixed text and a log and the first time the text is not shown in the log (notification 1), the second time the text is shown and the notification continues to be sent.

Very rare indeed.

Any ideas?

Thank you
Reply
#5
Post your full script. Most likely your telegram call is outside of "if" block.
Reply
#6
Hello

That's what I thought, but it's the same script as the one proposed but with my variables and addresses.

This is the script


Code:
require("user.Telegram")                                       -- Requiere la librería de usuario

local valor_actual_viento = grp.getvalue('1/0/3')
local valor_umbral_viento = grp.getvalue('32/1/7')
local alarma = grp.getvalue('32/2/25')

if ( (valor_actual_viento >= valor_umbral_viento) and not alarma ) then
  grp.write('32/2/25', true) -- set alarm true
  message = 'Alarma de viento ' ..valor_actual_viento.. 'm/s' -- Texto del mensaje a enviar
  telegram(message)                                           -- Se pasa a la biblioteca de usuario el mensaje
  log(message)
  else
saltado = "saltado"
log(saltado)
end
Reply
#7
Any suggestion?
Greeting
Reply
#8
Check errors on telegram like this
res, err = telegram(message)
log(res, err)
------------------------------
Ctrl+F5
Reply
#9
Check that you don't have any other telegram() calls in Common functions, user library or in a duplicate script.
Reply


Forum Jump: