Page 1 of 1
update device status with LUA
Posted: Sunday 29 January 2017 22:08
by TheWoodenGamer
Hi,
I can't seem to update a device status with LUA script.
Situation
- I have a user variable 'var-security'
- A device named 'Alarm' setup as a 'selector' with two levels:
10: AAN
20: UIT
I try to run a LUA script to update the device status to AAN or UIT when the user variable 'var-security' is updated from 1 to 0 or the other way around.
Code: Select all
commandArray = {}
if ( uservariables['var-security'] == '1' ) then
commandArray ['Alarm'] = 'Set Level: 10'
elseif ( uservariables['var-security'] == '0' ) then
commandArray ['Alarm'] = 'Set Level: 20'
end
return commandArray
Unfortunately, the status does not change.
Using commandArray ['Alarm'] = 'AAN' or 'On' or '1' does not work either.
Any tips or solutions for this?
A completely new code is welcome too.
Thanks,
Roel
Re: update device status with LUA
Posted: Sunday 29 January 2017 22:20
by G3rard
Is your script a file in the LUA scripts folder? In that case the name should be like script_variable_name.lua.
Or is your script in the local editor in Domoticz? In that case you should select UserVariable.
Re: update device status with LUA
Posted: Sunday 29 January 2017 22:33
by jvdz
Think you need to set the value to 10 or 20 like:
Jos
Re: update device status with LUA
Posted: Sunday 29 January 2017 22:58
by TheWoodenGamer
G3rard wrote:Is your script a file in the LUA scripts folder? In that case the name should be like script_variable_name.lua.
Or is your script in the local editor in Domoticz? In that case you should select UserVariable.
I use the web editor. Do you mean to replace 'uservariables' with 'UserVariable'?
That seems wrong, but I tried it anyway. Does not work.
thanks
Re: update device status with LUA
Posted: Sunday 29 January 2017 22:59
by TheWoodenGamer
jvdz wrote:Think you need to set the value to 10 or 20 like:
Jos
Hi Jos
Tried that. Does not work
Thanks
Re: update device status with LUA
Posted: Sunday 29 January 2017 23:07
by G3rard
TheWoodenGamer wrote:
I use the web editor. Do you mean to replace 'uservariables' with 'UserVariable'?
That seems wrong, but I tried it anyway. Does not work.
thanks
I mean the pulldown menu just Above the tick box Event active, that should be set to UserVariable for this script.
So no changes to the LUA code

Re: update device status with LUA
Posted: Monday 30 January 2017 0:00
by Westcott
What you want is -
commandArray ['Alarm'] = 'Set Level 20'
without the ':'
Re: update device status with LUA
Posted: Monday 30 January 2017 9:42
by TheWoodenGamer
Westcott wrote:What you want is -
commandArray ['Alarm'] = 'Set Level 20'
without the ':'
Hi Westcott,
No, that does not matter. This is however not as documented.
Documentation says that "Set Level xx" is for dimmers and for selectors, you should use "Set Level: xx"
It seems that both work fine.
The issue was that my variable is an integer, but I used '1' in my script. Once I removed the quotes, my script went into the functions.
And as you say, then without ':' it sets the level correctly.
Thank you all for thinking with me!
Cheers,
Roel
Re: update device status with LUA
Posted: Monday 30 January 2017 9:44
by TheWoodenGamer
Final script that worked:
Code: Select all
commandArray = {}
-- print to log
print("script running: alarm");
if (uservariables['var-security'] == 1 ) then
-- set device level to 10
commandArray ['Alarm'] = 'Set Level: 10'
-- print to log
print ("Alarm Turned On");
elseif (uservariables['var-security'] == 0 ) then
-- set device level to 20
commandArray ['Alarm'] = 'Set Level: 20'
-- print to log
print("Alarm Turned Off");
end
return commandArray