commandArray = {}--funzione tempofunction timebetween(s,e) timenow = os.date("*t") year = timenow.year month = timenow.month day = timenow.day s = s .. ":00" -- add seconds in case only hh:mm is supplied e = e .. ":00" shour = string.sub(s, 1, 2) sminutes = string.sub(s, 4, 5) sseconds = string.sub(s, 7, 8) ehour = string.sub(e, 1, 2) eminutes = string.sub(e, 4, 5) eseconds = string.sub(e, 7, 8) t1 = os.time() t2 = os.time{year=year, month=month, day=day, hour=shour, min=sminutes, sec=sseconds} t3 = os.time{year=year, month=month, day=day, hour=ehour, min=eminutes, sec=eseconds} sdifference = os.difftime (t1, t2) edifference = os.difftime (t1, t3) isbetween = false if sdifference >= 0 and edifference <= 0 then isbetween = true end--~ print(" s:" .. s .. " e:" .. e .. " sdifference:" .. sdifference.. " edifference:" .. edifference) return isbetweenend
--lettura variabililocal energia = tonumber(uservariables['energia giornaliera'])local setenergia = tonumber(uservariables['set energia giornaliera'])
--dati per invio messaggi telegram
local bot = ''; -- Telegram Bot IDlocal token = ''; -- Telegram Bot Tokenlocal chatId = ''; -- Telegram Chat IDlocal message = 'consumi eccessivi '; -- messaggio di testo --aggiornamento variabile set a 0 nell orario prestabilitoif timebetween("00:00:00","00:01:00") thencommandArray['Variable:set energia giornaliera']='0'end
--confronto energia giornaliera tenendo conto variabile setif (energia > 5) and (setenergia == 0) then --invio messaggio di testoos.execute('curl --data chat_id='..chatId..' --data-urlencode "text='..message..'" "https://api.telegram.org/bot'..bot..':'..token..'/sendMessage" ')--aggiornamneto variabile set a 1commandArray['Variable:set energia giornaliera']='1'end
return commandArray