Hej,
Är det någon här som kan beskriva samtliga inställningar i HC2 för att få en notis på mail eller push till en iPhone ?
2 Sömnlösa nätter nu, vad gör jag för fel...bryter nog snart ihop ?
Kod: Markera allt
--[[
%% autostart
%% globals
Telegram
--]]
local telegramToken = "123123123123:123123123123123123123123123123"
local telegramchatID = "-123123123"
local doDebug = true
msgDebug = function (color, message)
if doDebug then
fibaro:debug("<span style='color: " .. color .. "'>" .. tostring(message) .. "</span>")
end
end
urlEncode = function(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "%%20")
end
return str
end
if (fibaro:countScenes() > 1) then
fibaro:abort()
end
local Message = fibaro:getGlobalValue("Telegram")
if string.len(Message) > 1 then
msgDebug("Red", "Message: " .. Message)
local selfhttp = net.HTTPClient({timeout=2000})
url = "https://api.telegram.org/bot" .. telegramToken .. "/sendMessage?chat_id=" .. telegramchatID .. "&text=" .. urlEncode(Message)
selfhttp:request(url, {
options={
headers = selfhttp.controlHeaders,
data = requestBody,
method = 'GET'
},
success = function(status)
local result = json.decode(status.data);
if result.ok == true then
msgDebug("grey", "Sucessfully sent message to Telegram Bot...")
else
print(status.data);
end
end,
error = function(error)
msgDebug("red", error)
end
})
--Reset the global Telegram variable to 0
fibaro:setGlobal("Telegram", "")
else
msgDebug("Red", "Telegram-variable is empty")
end