Using a variable for Action delay ?

Just starting to use PLEG, wanted to say thanks for a great app !

I need to use a variable for an Action delay. Is this possible at all ?

I have tried to search this forum…No idea what forum engine they are using, but the results pages aren’t exactly readable !! Just tried searching with ‘variable action delay’ and the results are almost useless !!!

OK…I am trying this from a better angle regarding the delay :slight_smile:

I’m using MultiString (Heating Control1) to hold some variables I want to use in PLEG. Specifically Variable2 is a number (of minutes).

You can see what I’m trying to do from the following, but PLEG throws an error when trying to evaluate the not_occupied condition :
Program Logic Event [28] : motion; Now > occupied_delay_mins:00: Invalid Key token: >

Clearly I can’t just use a variable in this way. Any clues on how I can achieve this ?

[code]Triggers

Name Description
motion Whenever _Motion Sensor detects motion whether is armed or disarmed

Device Properties

Name Device Name Device Variable
occupied_delay_mins Heating Control1 Variable2

Conditions

Name Repeat Expression
occupied Yes motion
not_occupied Yes motion; Now > occupied_delay_mins:00[/code]

Build occupied_delay_mins as a Self ReTrigger schedule (these kind of schedules are often called timers). Your “occupied” condition then starts the timer as its action. Condition “not_occupied” becomes sequence expression “Motion; !occupied_delay_mins”, which means only trip if motion happened then the timer stopped. The number of minutes for occupied_delay_mins can be set, but also can be variable by passing the interval value to the timer when you start it…

What @wilme2 said was a good solution.

I will expand in more detail.

Create a timer:
sVariableTimer On:SelfRetrigger Off:Interval of 10 Seconds (Does not matter because we are going to override it Later!)

Create a Condition:

Occupied Motion

Using the Advanced tab in the Action editor for cOnMotion add the PLEG device, the action is StartTimer and the interval is:
{(Occupied_Delay_Mins)}:00

Another Codition:
Not_Occupied Motion; !sVariableTimer

Got it ! :wink: :wink:

Took a bit of getting my head around, but the Self-Retrigger solution works brilliantly.

The Self-Retrigger section in PLEG Basics.pdf was also a great help in understanding the mechanism.

Thanks guys