Page 1 of 1

only print if uservar=false

Posted: Sunday 24 September 2017 15:20
by Evelen
okey, I made this script to print to the log if a temp sensor is higher, lower or in middle of two values (to monitor fridge and freezer ect)

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
meening: only do this if the uservare value is not equal to "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
All thins works except that it output the warning message no matter if it is true, false or somthing else..

Any Ides?
My first lua script btw,

Re: only print if uservar=false

Posted: Sunday 24 September 2017 15:44
by jvdz
So what exactly is the value of the UserVariable? is it true or is it "true"?
Which type is the Uservariable?

Jos

Re: only print if uservar=false

Posted: Sunday 24 September 2017 15:54
by Evelen
jvdz wrote: Sunday 24 September 2017 15:44 So what exactly is the value of the UserVariable? is it true or is it "true"?
Which type is the Uservariable?

Jos
the type is "string" and the value is true
Uten navn.png
Uten navn.png (58.66 KiB) Viewed 1214 times

Re: only print if uservar=false

Posted: Sunday 24 September 2017 16:16
by jvdz
I guess Streng means String. :)
That means that the test needs to be a test for a literal string:

Code: Select all

uservariables[warning_sent_uservar] ~= "true"
Jos

Re: only print if uservar=false

Posted: Sunday 24 September 2017 17:37
by Evelen
thanks, it works 8-)