Made a script to send the text off weather alarm to Telegram, but it is sending every ten minutes the same message, how to make the script that only a new message is send?
return {
on = {
devices = {'Weeralarm'}
},
execute = function(domoticz)
local Weeralarm = domoticz.devices('Weeralarm')
local teleTok = 'teletokAPI'
local chatId = 'chatId'
if Weeralarm.state ~= 'Er zijn momenteel geen waarschuwingen van kracht.' then
os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendMessage" -d chat_id='..chatId..' -d text="'..Weeralarm.state..'"')
end
end
}
return {
on = {
timer = { 'every 10 minutes' },
httpResponses = { 'WeatherLiveDataRetrieved' },
},
logging = {
level = domoticz.LOG_ERROR,
marker = 'Weerlive DEBUG data'
},
execute = function(domoticz, item)
local teleTok = 'API'
local chatId = 'ChatID'
if (item.isTimer) then
domoticz.openURL({
url = "http://weerlive.nl/api/json-data-10min.php?key=f6s372b8&locatie=52.22234, 4.53300",
method = 'GET',
callback = 'WeatherLiveDataRetrieved'
})
elseif (item.isHTTPResponse) then
if (item.ok) then -- statusCode == 2xx
-- Display all data from weerlive with the domoticz.utils.dumpTable(item.json) statement
-- either domoticz.log(domoticz.utils.dumpTable(item.json),domoticz.LOG_DEBUG)
-- or domoticz.utils.dumpTable(item.json)
domoticz.log('weather ALARM text is ' .. item.json.liveweer[1].alarmtxt,domoticz.LOG_DEBUG)
end
if (item.json.liveweer[1].alarm == '1') then -- alarm state 0 or 1
os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendMessage" -d chat_id='..chatId..' -d text="'..item.json.liveweer[1].alarm..'"')
-- or, using domoticz notification
domoticz.notify('WHEATHER ALARM!', "you don't need to panic." .. item.json.liveweer[1].alarmtxt, domoticz.PRIORITY_HIGH)
end
end
end
}