I try to output "temp is ok" in log each time the script runs if the temp is ok.
And I want to output a warning if it is higher or lower if that is the case, but I only want to output this warning one time until the temp is back to normal.
So I try to use a variable to do this and use this in the if/elseif's:
Code: Select all
and uservariables[warning_sent_uservar] ~= true
complete script:
Code: Select all
--- Configuration
local temp_device = "29 - Kjøleskap"
local warning_sent_uservar = "var_kjoleskap_advarsel_sendt"
local upper_temp_limit = 15
local lower_temp_limit = 2
local upper_temp_limit_warning_msg = "Øvre temperaturgrense " .. upper_temp_limit .. "ºC er nådd!"
local lower_temp_limit_warning_msg = "Nedre temperaturgrense " .. lower_temp_limit .. "ºC er nådd!"
local temp = tonumber(otherdevices_svalues[temp_device])
print(temp_device .. " = " .. temp .. " | " .. warning_sent_uservar .. " = " .. uservariables[warning_sent_uservar])
commandArray = {}
temp = tonumber(temp)
if (upper_temp_limit < temp and uservariables[warning_sent_uservar] ~= true) then
print(upper_temp_limit_warning_msg)
commandArray['Variable:' .. warning_sent_uservar]='true'
elseif (lower_temp_limit > temp and uservariables[warning_sent_uservar] ~= true) then
print(lower_temp_limit_warning_msg)
commandArray['Variable:' .. warning_sent_uservar]='true'
elseif (upper_temp_limit > temp and lower_temp_limit < temp) then
print("Temp is ok")
commandArray['Variable:' .. warning_sent_uservar]='false'
end
return commandArray
Any Ides?
My first lua script btw,