Page 1 of 1

Local variable

Posted: Friday 07 January 2022 11:48
by Allras82
Hi,

I'm trying to generate a simple script to create an alarm from my ventilation system.

Iv made the alarm codes as:

Code: Select all

local ALK4 = '4- PRESSURE ; High or low pressure pressure switch'
local ALK5 = '5- DOOR ; Inspection door open'
I have a lot more local variables than shown here, this is just an example.

and then i want to put the value of the local as description in the alert device:
local AL_kode = domoticz.devices('Nilan Alarm_read code').sensorValue

Code: Select all

	   if ('ALK'..AL_kode) == 'ALK0' or 'ALK1' or 'ALK2' or 'ALK3' or 'ALK4' or 'ALK5' or 'ALK6' or 'ALK7' ' then
	       domoticz.data.svalAL = 'ALK'..AL_kode
        else 
	       domoticz.data.svalAL = 'Ikke%20kendt%20tilstand'
	       
	   end   
	       
	       
domoticz.log(domoticz.data.svalAL)	       
domoticz.log(ALK4)

	       local url = 'http://192.168.1.xx:8080/json.htm?type=command&param=udevice&idx='..idx..'&nvalue=1&svalue='..domoticz.data.svalAL
	       --domoticz.log(url)
	       domoticz.openURL(url)
The result is that i get the name of the variable in the alert device and not the value og the variable.
The two log output also shows 1: name of variable, 2: value of variable

How to i get the value of the local variable instead of the name?

Thank you in advance.
BR
AR

Re: Local variable

Posted: Friday 07 January 2022 11:59
by jvdz
Don't think that if with all those or's is valid in LUA, but if I understand you well you want something simple like this:

Code: Select all

local ALKDesc = {}
ALKDesc["4"] = '4- PRESSURE ; High or low pressure pressure switch'
ALKDesc["5"] = '5- DOOR ; Inspection door open'
local AL_kode = domoticz.devices('Nilan Alarm_read code').sensorValue

if (ALKDesc[AL_kode]) ~= nil then
	domoticz.data.svalAL = ALKDesc[AL_kode]
else 
	domoticz.data.svalAL = 'Ikke%20kendt%20tilstand'

end   
Jos