Logic Machine Forum
Telegram message with blocking - 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: Telegram message with blocking (/showthread.php?tid=4335)



Telegram message with blocking - AlexLV - 30.10.2022

Hi, 

Boiler status I receive from powertag, updating periodically. I want message to telegram should be sent only once, when status changed. But my simple script not working, could not find where is the problem.. 

Can you please check where I am wrong..

Code:
require("user.telegram")

local statuss = event.getvalue('42/2/10')----Boiler status
local alarm = event.getvalue('0/0/102') ---alarm status
--log(statuss)
--log (alarm)
if statuss == true then
if alarm == false then
     message = 'Бойлер включен' ---message is not working, boiler is on
telegram(message)
grp.write('0/0/102', true)  -- trying to block next alarm
    alarm = true -- t
end
else
message = 'Бойлер выключен' --message working, boiler is off
  telegram(message)
    grp.write('0/0/102', false) -- trying to unblock next alarm when statuss is changed
  alarm = false
end



Alex


RE: Telegram message with blocking - admin - 31.10.2022

event.getvalue() does not accept any arguments. You need to use grp.getvalue() for all other groups than the event source.
Your script blocks multiple "on" messages but does not block "off" messages. Use this instead:
Code:
require('user.telegram')

key = 'boiler_status'

curr = event.getvalue()
prev = storage.get(key)

if curr ~= prev then
  message = curr and 'boiler on' or 'boiler off'
  telegram(message)
  storage.set(key, curr)
end



RE: Telegram message with blocking - AlexLV - 31.10.2022

Thank you for explanation!!

Alex