LUA instr. only at the end?!

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

LUA instr. only at the end?!

Post 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
The most dangerous phrase in any language is:
"We always done this way"
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA instr. only at the end?!

Post 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.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: LUA instr. only at the end?!

Post 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
The most dangerous phrase in any language is:
"We always done this way"
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA instr. only at the end?!

Post by jvdz »

Not sure I understand why you would need to have to update the variable during the event run?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: LUA instr. only at the end?!

Post 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.
Not using Domoticz anymore
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest