I have the following script to switch on a Fan (433 KAKU switch) if the temperature reaches a certain level.
The script will also send a Telegram message, but.... it looks like "commandArray['Solar: Fan'] = "On" is executed 5 times, so i will receive the message also 5 times.
Does someone have a solution for this issue?
Thanks!
Regards Twoink

Code: Select all
function Telegram(message)
local bot = 'XXXX'; -- Telegram Bot ID
local token = 'XXXXX'; -- Telegram Bot Token
local chatId = 'XXXXX'; -- Telegram Chat ID
os.execute('curl --data chat_id='..chatId..' --data-urlencode "text='..message..'" "https://api.telegram.org/bot'..bot..':'..token..'/sendMessage" ')
return
end
-------------DEVICES----------------
local fan = otherdevices['Solar: Fan']
local temp = otherdevices_temperature['Solar: Temperature']
-------------SETTINGS----------------
local Set_switch_off_temp = 35
local Set_switch_on_temp = 43
-----------------------------------------
-- START SCRIPT
commandArray = {}
if (temp >= Set_switch_on_temp and fan == "Off") then
commandArray['Solar: Fan'] = "On"
Telegram("Fan is switched ON")
elseif (omvormer_temp <= Set_switch_off_temp and fan == "On") then
commandArray['Solar: Fan'] = "Off"
Telegram("Fan is switched OFF")
end
return commandArray