only print if uservar=false Topic is solved

Moderator: leecollings

Post Reply
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

only print if uservar=false

Post 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,
User avatar
jvdz
Posts: 2266
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: only print if uservar=false

Post by jvdz »

So what exactly is the value of the UserVariable? is it true or is it "true"?
Which type is the Uservariable?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: only print if uservar=false

Post 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 1162 times
User avatar
jvdz
Posts: 2266
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: only print if uservar=false

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: only print if uservar=false

Post by Evelen »

thanks, it works 8-)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest