[Solved] How to treat nil value returned by otherdevices_svalues Topic is solved

Post Reply
YellowSky
Posts: 118
Joined: Tuesday 12 May 2015 12:09
Target OS: Raspberry Pi
Domoticz version: Last
Location: Belgium
Contact:

[Solved] How to treat nil value returned by otherdevices_svalues

Post by YellowSky » Friday 10 August 2018 7:29

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.
Last edited by YellowSky on Tuesday 14 August 2018 7:41, edited 2 times in total.

freijn
Posts: 402
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

Re: How to trat nil value returned by otherdevices_svalues

Post by freijn » Friday 10 August 2018 7:43

instead of a calculation, first test if there is a value > 0 ?

User avatar
jvdz
Posts: 1464
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: How to trat nil value returned by otherdevices_svalues

Post by jvdz » Friday 10 August 2018 9:37

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

YellowSky
Posts: 118
Joined: Tuesday 12 May 2015 12:09
Target OS: Raspberry Pi
Domoticz version: Last
Location: Belgium
Contact:

Re: How to trat nil value returned by otherdevices_svalues

Post by YellowSky » Monday 13 August 2018 17:54

Thank you for your suggestion.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests