Page 1 of 1

[Solved] How to treat nil value returned by otherdevices_svalues

Posted: Friday 10 August 2018 7:29
by YellowSky
Hi everyone,
in my lua script i use this command to recover the temperature and the humidity of a DHT sensor.
line 99 T, RH = otherdevices_svalues['Kitchen']:match("([^;]+);([^;]+)")
However i would like to treat this error i receive when the sensor is disconnect:

Code: Select all

Error: EventSystem: in domoticz/scripts/lua/script_time_thermostathyst.lua:99: attempt to index field 'Kitchen' (a nil value)
Is there any command to do this?
For example if a nil value is returned, change by default value and continue to execute the code.

Thank you.

Re: How to trat nil value returned by otherdevices_svalues

Posted: Friday 10 August 2018 7:43
by freijn
instead of a calculation, first test if there is a value > 0 ?

Re: How to trat nil value returned by otherdevices_svalues

Posted: Friday 10 August 2018 9:37
by jvdz
something like this:

Code: Select all

if otherdevices_svalues['Kitchen'] ~= nil then
	T, RH = otherdevices_svalues['Kitchen']:match("([^;]+);([^;]+)")
else
	-- put here your the actions in case it is nil
end
Jos

Re: How to trat nil value returned by otherdevices_svalues

Posted: Monday 13 August 2018 17:54
by YellowSky
Thank you for your suggestion.