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.

Telegram message with blocking
#1
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
Reply
#2
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
Reply
#3
Thank you for explanation!!

Alex
Reply


Forum Jump: