Local variable

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Allras82
Posts: 20
Joined: Thursday 26 October 2017 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Local variable

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

Re: Local variable

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest