Logic Machine Forum
“staircase function” - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: “staircase function” (/showthread.php?tid=2463)



“staircase function” - Boris - 11.02.2020

Hello,

As a "newcomer" to LM5 as well as Lua scripting, I am struggling with a script, that features kind of a staircase function and that could be parametrised separately to implement a time-controlled lighting of a staircase or similar applications.

- The script would be triggered by a “1 bit object” originating from a motion-sensor
- The script would then dim-on the corresponding lights by sending a “1 byte object” to the dimmer
- Then the script would wait a delay time, after that it would dim down the lights by sending several decreasing values, also with some short delay in between

Well, so far, this was straight forward to implement.

Code:
value = event.getvalue()

if value==true then

  grp.write('9/1/3',100)
 
  sleep(90)

  grp.write('9/1/3',50)
 
  sleep(15)

  grp.write('9/1/3',30)
 
  sleep(3)
 
  grp.write('9/1/3',15)
 
  sleep(3)
 
  grp.write('9/1/1',false)
 
  end


Only, there would be some “extra features” needed:

a) When an another 1 bit object = 1, originating from a motion-sensor would be received during the script-execution, it should reset the initial delay time —> “staircase function” (means, restarting the script immediately)

b) When an object = 1 originating from a wall-switch would be received during the script-execution, it should stop the script, dim up the lights and disable the motion-sensor

c) When an object = 0 originating from a wall-switch would be received during the script-execution, it should stop the script, dim down the lights and disable the motion-sensor


Thank you very much.


RE: “staircase function” - Erwin van der Zwart - 11.02.2020

Hi,

Well there are quite some improvements to make as you can’t use event based scripts like this as they will run in parallel if you don’t take care of it.

Here is a sample to start with that already does a lot you need only needs to be modified for your dimming steps, restart and blocking is already implemented.

See: https://forum.logicmachine.net/showthread.php?tid=1789&pid=15442#pid15442

BR,

Erwin


RE: “staircase function” - Boris - 12.02.2020

(11.02.2020, 20:23)Erwin van der Zwart Wrote: Hi,

Well there are quite some improvements to make as you can’t use event based scripts like this as they will run in parallel if you don’t take care of it.

Here is a sample to start with that already does a lot you need only needs to be modified for your dimming steps, restart and blocking is already implemented.

See: https://forum.logicmachine.net/showthread.php?tid=1789&pid=15442#pid15442

BR,

Erwin
Hello Erwin

Thank you very much for your quick and helpful reply, critic and valuable suggestion, which I will be happy to try out this Friday. Am I right, by assuming, that your suggested script shall run as a "Resident Script"?

KR, Boris


RE: “staircase function” - Erwin van der Zwart - 12.02.2020

Hi,

No you need to run it as event based attached to the input object.

BR,

Erwin


RE: “staircase function” - alexgleyzer - 29.02.2020

Works great. Thank you, Erwin