Remember & Reset State

I have the following scenario that I need to program in PLEG:

  1. Wait for a certain condition c1. This condition WILL GO AWAY and then might go through a few cycle of coming back and going away. Once it has happened I need to remember it has happened. No action will happen at that time, though.
  2. I need to wait for a second condition c2. Note that the above condition for c1 WILL NOT be satisfied when c2 happens. They are mutually exclusive. Hence, I only evaluate if c1 every happened before c2. Now, when c2 happens then
    a) if c1 DID NOT happen before then do nothing.
    b) if c1 DID happen before then execute an action and reset c1.

I could do c1 with a schedule but none of the stop options seem to be appropriate to reset its state, i.e. I cannot reset c1 based on when a different conditions (c2) becomes true (or at least I have seen a way to do this). I also looked at the regular evaluations of conditions but it seems everything will reset c1 before c2 happens.

One solution would be to add a device variable to PLEG or another device that you use to indicate that the c1 event has occurred. If you define a Device Property for this variable, you can use it in your Condition.

Something like this:

Device Properties
SeenX “SeenX”

Conditions
c1 … Expression for event …
c2 … Expression for event …
c3 c2 and (SeenX != 0)

Actions
c1 PLEG SetVariable ServiceId=“urn:maja-com:serviceId:Custom” VariableName=“SeenX”
Value=1 Device=
c3 PLEG SetVariable ServiceId=“urn:maja-com:serviceId:Custom” VariableName=“SeenX”
Value=0 Device=
… Other required actions …

You could also do it by using a Conditional expression to retain the fact that c1 fired and reset itself when c3 fires:

Conditions
c1 … Expression for event …
c2 … Expression for event …
c3 c2 and c1Seen
c1Seen c3 ? 0 : (c1 ? 1 : c1Seen)

Actions
c3 … Required action …

That’s what sequence expressions are for.

You need:
c2 and (c1;c2)

Your description is a little vague … maybe you can post the real work scenario and current status report.

Rex, I first was going with your first approach which lead me to learn more about creating variables, naming conventions from UPnP, etc.

I finally ended doing your second suggestion, though. I created some testing environment and preliminary results indicate it works. The only thing that puzzled me is that c1 is triggered multiple times even if the input t1 for c1 did not change (t1 = More than 100W, c1 = t1 and (t1;Now>1:00) ). I thought that conditions are only evaluated when the state/input changes but that does not seem to be the case.

Anyways, thanks a lot!

The only thing that puzzled me is that c1 is triggered multiple times even if the input t1 for c1 did not change (t1 = More than 100W, c1 = t1 and (t1;Now>1:00) ). I thought that conditions are only evaluated when the state/input changes but that does not seem to be the case.

Conditions are, as you thought, evaluated when one of their terms changes. Using Now in an expression will cause it to be evaluated every minute.

There is no great harm in this - the processing load is quite small. If you want to avoid it you could use a SelfReTrigger Schedule (timer) instead of Now.

c1 = t1 and (t1;Now>1:00)

Will be evaluated EVERY minute as well as when t1 changes.
It will only go true once and evaluate actions once UNLESS you set the REPEATS flag.