Advertisement
EvertJob

Untitled

Jan 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. -- Global Telegram settings
  2. telegramAPI                         = ""
  3. telegramChatID                      = ""
  4. telegramGroupID                     = ""
  5.  
  6. -- Set weahter alarm colors
  7. weatherAlarmColorsData = {
  8.     ["1"]   = "groen",
  9.     ["2"]   = "geel",
  10.     ["3"]   = "oranje",
  11.     ["4"]   = "rood"
  12. }
  13.  
  14. weatherAlarmWarningsData = {
  15.     ["Wind"]            = "Wind",
  16.     ["Snow/Ice"]        = "Sneeuw/ijs",
  17.     ["ThunderStorm"]    = "Onweer",
  18.     ["Fog"]             = "Mist",
  19.     ["High Temp"]       = "Hoge temperaturen",
  20.     ["Low Temp"]        = "Lage temperaturen",
  21.     ["Coastal Event"]   = "Kustgebeurtenis",
  22.     ["Forestfire"]      = "Bos/weide brand",
  23.     ["Avalanches"]      = "Lawines",
  24.     ["Rain"]            = "Regen",
  25.     ["Flood"]           = "Overstromingen",
  26.     ["Rain-Flood"]      = "Regen overstromingen"
  27. }
  28.  
  29. -- Global's
  30. json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
  31. json.strictTypes = true
  32.  
  33. -- Prepare raw data to json
  34. weatherAlarmColors                  = json:encode(weatherAlarmColorsData)
  35. weatherAlarmWarnings                = json:encode(weatherAlarmWarningsData)
  36.  
  37. function sendTelegram(Message, Channel)
  38.      
  39.       if(Channel == "private") then
  40.           chatID = telegramChatID
  41.       else
  42.           chatID = telegramGroupID
  43.       end
  44.      
  45.         local prep = assert(io.popen('curl -s -X POST https://api.telegram.org/bot'..telegramAPI..'/sendMessage -d chat_id='..chatID..' -d parse_mode=Markdown -d text="'.. Message ..'"'))
  46.         local data = prep:read('*a')
  47.         prep:close()
  48.         local jsonData = json:decode(data)
  49.        
  50.         if(jsonData['ok'] == false) then
  51.             print("Telegram kon niet verstuurd worden!: "..jsonData['error_code'].." "..jsonData['description'])
  52.         end
  53.        
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement