Hi guys,
I have an easy question for the novice user, but i spend a week to get this working so please help me....
The simple thing is that i want to set a variable in the first LUA script to a certain number, lets say 1, then want to read it in the second script and set this variable to another number 2.
It sounds easy but i strangle with the correct notation.
below are parts of the scripts to get an idea:
first script:
if (devicechanged['Status alarm panel'] == 'On' and uservariable['alarm_status'] ~= '2') then
commandArray['Variable:alarm_status'] = tostring(2)
end
second script:
if (devicechanged['test'] == 'On' and uservariables['alarm_status'] == '2') then
commandArray['Variable:alarm_status']= tostring(5)
end
I have made an user variable "alarm_status" as an integer but get error messages like "attempt to index global 'uservariable' (a nil value)"
i have tried things like uservariable == alarm_status or alarm_variable ==2 or uservariable['alarm_variable'] == 2 but nothing works.
It will be much apriciated if someone could setup the basis code.
Thanks in advance
Greetz, Paul
Easy question about variables
Moderator: leecollings
Re: Easy question about variables
Hi,
Can you start by changing "uservariable" to "uservariables" in the if-statement of your first script and then try again?
Can you start by changing "uservariable" to "uservariables" in the if-statement of your first script and then try again?
- BartdaMan
- Posts: 20
- Joined: Sunday 22 May 2016 22:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Amersfoort
- Contact:
Re: Easy question about variables
You are sending a string, but the variable is an integer...
Try commandArray['Variable:alarm_status'] = tonumber(2)
Try commandArray['Variable:alarm_status'] = tonumber(2)
-
- Posts: 28
- Joined: Sunday 19 June 2016 9:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Easy question about variables
@mrf68: was a typo but thanks.
@BartdaMan, i have changed the script to:
event 1:
and
event 2:
this will do the trick, but to be honest i find it all quite devious.
It is of no influence if a change the uservariable to "string" or "integer" in setup/more options.
is there somewhere a complete overview of all domoticz LUA commands and their syntax?
Thanks both for your help.
Greetz, Paul
@BartdaMan, i have changed the script to:
event 1:
Code: Select all
if (devicechanged['Status alarm panel'] == 'On') then
commandArray['Variable:alarm_status'] = tostring(2)
event 2:
Code: Select all
if (devicechanged['Voordeur sensor'] == "Open" and uservariables['alarm_status'] == 2) then
commandArray['Variable:alarm_status'] = tostring (5)
It is of no influence if a change the uservariable to "string" or "integer" in setup/more options.
is there somewhere a complete overview of all domoticz LUA commands and their syntax?
Thanks both for your help.
Greetz, Paul
- BartdaMan
- Posts: 20
- Joined: Sunday 22 May 2016 22:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Amersfoort
- Contact:
Re: Easy question about variables
Paul,
This is a start:
https://www.domoticz.com/wiki/LUA_commands
Not complete, but these examples will give you some ideas:
https://www.domoticz.com/wiki/Event_script_examples
And off course you could study from here also:
https://www.lua.org/manual/5.3/
This is a start:
https://www.domoticz.com/wiki/LUA_commands
Not complete, but these examples will give you some ideas:
https://www.domoticz.com/wiki/Event_script_examples
And off course you could study from here also:
https://www.lua.org/manual/5.3/
Who is online
Users browsing this forum: No registered users and 1 guest