Logic Machine Forum
Notification of exceeding wind speed threshold - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Notification of exceeding wind speed threshold (/showthread.php?tid=4242)



Notification of exceeding wind speed threshold - JRP - 15.09.2022

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


RE: Notification of exceeding wind speed threshold - RomansP - 15.09.2022

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).


RE: Notification of exceeding wind speed threshold - JRP - 16.09.2022

thanks i will try it.

Greetings


RE: Notification of exceeding wind speed threshold - JRP - 23.09.2022

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


RE: Notification of exceeding wind speed threshold - admin - 24.09.2022

Post your full script. Most likely your telegram call is outside of "if" block.


RE: Notification of exceeding wind speed threshold - JRP - 24.09.2022

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



RE: Notification of exceeding wind speed threshold - JRP - 27.09.2022

Any suggestion?
Greeting


RE: Notification of exceeding wind speed threshold - Daniel - 27.09.2022

Check errors on telegram like this
res, err = telegram(message)
log(res, err)


RE: Notification of exceeding wind speed threshold - admin - 27.09.2022

Check that you don't have any other telegram() calls in Common functions, user library or in a duplicate script.