Error: EventSystem: in *event: [string " ..."]:18: attempt to compare number with nil

Moderator: leecollings

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

Error: EventSystem: in *event: [string " ..."]:18: attempt to compare number with nil

Post by Evelen »

Hi.
I try to make my first LUA script to warn me if the temperature is bellow/ower a number
the script works perfect in my LUA editor ZeroBrane Studio (with temp as a variable), but when I try it in Domoticz I got this message:

Error: EventSystem: in Kjøleskap alarm: [string " ..."]:18: attempt to compare number with nil

Code: Select all


--- Configuration
local temp = 'Kjøleskap'
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 " .. upper_temp_limit .. "ºC er nådd!"

--commandArray = {}

temp = tonumber(temp)

if (warning_sent == nil) then
    warning_sent = false
end

if (upper_temp_limit < temp and warning_sent ~= true) then
  print(upper_temp_limit_warning_msg)
  warning_sent = true
  
elseif (lower_temp_limit > temp and warning_sent ~= true) then
  print(lower_temp_limit_warning_msg)
  warning_sent = true
  
elseif (upper_temp_limit > temp and lower_temp_limit < temp) then
    print("Temp ok")
  warning_sent = false

end

--return commandArray

Anyone se what's wrong? also, do I need the CommandArray thing? (gives the same result with and without)
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Error: EventSystem: in *event: [string " ..."]:18: attempt to compare number with nil

Post by zicht »

Just a quick view :

Is it possible that your temp is a string set in the beginning of a script to a name ?

Code: Select all

local temp = 'Kjøleskap'
So in the comparisation you are compairing a number with a string in the if-then ?

Code: Select all

if (upper_temp_limit < temp and warning_sent ~= true) then
maybe it should be local temp = otherdevices['Kjøleskap'] to get the value of 'Kjøleskap' but thats just an assumption.
(You need to compare numbers with numbers and strings with strings.)
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: Error: EventSystem: in *event: [string " ..."]:18: attempt to compare number with nil

Post by Evelen »

thanks :)
Also, another mistake was that the name of the device was wrong..

this gives me the value:

Code: Select all

local temp_device = "29 - Kjøleskap"
local temp = tonumber(otherdevices_svalues[temp_device])
print(temp)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest