Page 1 of 1

LUA instr. only at the end?!

Posted: Thursday 28 July 2016 16:04
by emme
Hi,

got a problema with a script (the speedtest sensor script... :P )

My script is triggered on time (which is not an issue) and 2 global variables (which ARE the issue):
One variable (called OnOff) must be set to 0 (do not run) or 1 (run)
the other (called OnGoing) should be set to 0 (not on going) or 1 (on going)

the script should run if the OnOff Switch is set to 1 and the OnGoing is set to 0
based on this... the first instruction is to set the OnGoing to 1 in order to prevent the script to run another time.

Could it be that LUA does not update the variable in the moment it compute the instruction but only at the end of the script?
because the script runs 3 times before updating (and it has inside a bash script to run the Speedtest which takes a while)

I tried to add a sleep function.... no success...
Tried to debug :

Code: Select all

[...]
commandArray['Variable:SpeedTest-InCorso']= "1"
print ("Switches: on "..uservariables['SpeedTest-OnOff'].." in corso "..uservariables['SpeedTest-InCorso'])
the status shows:
2016-07-28 15:50:50.378 LUA: Switches: on 1 in corso 0
I really don't know where to find a fix for this.... :roll: :roll: :oops: :oops:

ciao
M

Re: LUA instr. only at the end?!

Posted: Thursday 28 July 2016 17:32
by jvdz
Correct on the update at the end of the script finding: You fill the Table commandArray with actions you want to have performed and you return the array at the end of the script back to the Event system, which then processes each of these updates in the table.

Re: LUA instr. only at the end?!

Posted: Thursday 28 July 2016 17:37
by emme
is there a way to get this done?
maybe calling another script which would have its own commandArray table done before the caller one?

thanks

Re: LUA instr. only at the end?!

Posted: Thursday 28 July 2016 18:48
by jvdz
Not sure I understand why you would need to have to update the variable during the event run?

Jos

Re: LUA instr. only at the end?!

Posted: Thursday 28 July 2016 21:19
by G3rard
Just use the LUA script to start the bash script as mentioned in my post on http://www.domoticz.com/forum/viewtopic ... 834#p91832.

The LUA script will finish even when the speedtest from the bash script is still running. That is no problem.
Set the LUA script to only start at certain times so the speedtest will have enough time to finish.