Using PLEG for closing gate.

I have now about 4 scenes to controll my gate, garage and lights when I come home and leave. Works fine , but maybe I can put it all in PLEG en declutter my scenes.

What I have now:
1 main scene which I activate when I come home or leave. This scenes activates 2 other scenes ( 2&3) and have some LUUP code that this scene cannot be activated again within 60 seconds.

scene2: activate gate , activate garage door. After 90 seconds activate gate again ( = close gate).
scene3: check if the night& day plugin is in night mode; if yes , switch on some lights , and with different delays , switch them off.

How to insert this all in PLEG.
before I start fiddling arround in PLEG I want to have a basic idea what I am doing, I was thinking like this:

Input trigger:
-virtual switch >> when switch is on (name: come_and_leave)
-Day night plugin >> when indicating night (name: day_night)

conditions:
-open_gate >> come_and_leave
-gate_lights >> come_and_leave AND day_night

actions:
-open_gate >>fibaro gate , fibaro garage >>delay 90 seconds , fibaro gate and the virtual switch which starts the sequence back to off position.
-gate_lights >> switch on some lights >> some delays , switch them off

But how do I insert the code that when the virtual switch is presses it cannot be pressed again within 60 seconds.

Does this PLEG makes sense?

Thanks,
Cor

But how do I insert the code that when the virtual switch is presses it cannot be pressed again within 60 seconds.
There's always more than one way to skin a cat... One way is to create a schedule with [b]Start Type:[/b] [i]Self Triggered[/i], [b]Stop Type:[/b] [i]Interval[/i] and time 60 seconds. Call it, say, [i]Lockout60[/i]. Add to your actions for the condition [i]open_gate[/i] an advanced action for the PLEG device to [b]Start Timer[/b] [i]Lockout60[/i]. Now add to the condition [b]open_gate[/b] the term [i]AND NOT Lockout60[/i].

When the condition open_gate fires, the action will start Lockout60 which will prevent the condition firing again for 60 seconds. You may also want to include some sequence terms to ensure things fire only events happen in the required order.

Thanx RexBeckett; I will give it a try.

One thing which just came up.
in the action auto_close, the gate is activated and also the virtual switch is reset from on to off (which should stop this PLEG) for the gate to be manually opened and stay open… ( is just a s a kind of bypass funtion)

The virtual switch will go off immediuately when auto_off is fired. Will is still work now after the 5 minutes?

This part i didn’t get:

You may also want to include some sequence terms to ensure things fire only events happen in the required order.

Cor

One thing which just came up. in the action auto_close, the gate is activated and also the virtual switch is reset from on to off (which should stop this PLEG) for the gate to be manually opened and stay open.. ( is just a s a kind of bypass funtion)

The virtual switch will go off immediuately when auto_off is fired. Will is still work now after the 5 minutes?


That depends on how you write the conditions. Try it out and, if it doesn’t do what you want, post your Status report so we can help.

This part i didn't get: Quote You may also want to include some sequence terms to ensure things fire only events happen in the required order.
With time-related events it is sometimes necessary to use sequence expressions to ensure that conditions only fire when things happen in a certain order. This can be important if a condition includes multiple triggers. It may not be required for your gate logic - we shall see.

Today I had some time to try this PLEG.

It is not working how it should be , but getting close.

The gate keeps on opening and closing. After some trouble shooting I think it is because the Virtual switch remains on after pressing it.
I tried to toggle the virtual switch back to off as an action , but this doesn’t work (probably due to the lockout_60_sec).
When I manually clicked the “off” button on the Gui , this PLEG worked fine.
I also noticed there is a unknown variable in RED “NOT” , is this normal? (see attachement 1.jpg)

Any Idea how I can get this little bug out?

Attached:
-the status in pdf (highlited in yellow the items for this instance).
-1.jpg : possible error “unknown command”

Thanks a lot ,
Cor

The logic seams a little strange to me …
You can turn the come_and_leave1 VS to OFF in the Auto_close action.

Hi Richard,

The “auto_close” action is NOT part for this instance , the auto_close is used for the scenes I use now untill I get this to work. I checked if they interfere with the PLEG I am trying now , but they don’t. After I get this to work I delete the “auto_close” and “Auto_gate1”

Only the in yellow highlited are used as in the pdf file from my previous post.

As RexBeckett explained I tried this:

reate a schedule with Start Type: Self Triggered, Stop Type: Interval and time 60 seconds. Call it, say, Lockout60. Add to your actions for the condition open_gate an advanced action for the PLEG device to Start Timer Lockout60. Now add to the condition open_gate the term AND NOT Lockout60.

When the condition open_gate fires, the action will start Lockout60 which will prevent the condition firing again for 60 seconds. You may also want to include some sequence terms to ensure things fire only events happen in the required order.

What I did:

I have:
Trigger:
come_and_leave1:This is a trigger for a virtual switch ( the idea is that this will fire the whole sequence)
day_night: to activate some lights (not relevant for the moment)

Schedule:
Lockout_60_sec Self Trigger None Interval:60 None

conditions:
open_gate: come_and_leave1 AND NOT Lockout_60_sec
This condition gives me a “unknown variable” (NOT is in red, see 1.jpg in my previous post, is this normal and OK?)

actions:
open_gate:
immediate:

fibaro module togles off (opens gate)
fibaro module togles off (garage)
Program Logic Event Generator >>StartTimer >>Lockout_60_sec
after 5 seconds:
Virtual switch to off ( But this doesn’t work)
after 90 seconds:
fibaro module togles off (closes gate)

What I basically want is:
I toggle the virtual switch to on:
-gate and garage opens (fibaro switches)
-after 5 seconds the virtual swich goes back to off)
-after 90 seconds the gate closes again ( fibaro switch toggles off)

During the first 60 seconds i don’t want anything to happen when I (accidentally) press the virtual switch “on” again. (reason for this is that sometimes I have a bad connection (3G) and authomation app fires the “scene” or in this instance PLEG multiple times. When this happends, my gate does not open or opens partially. When the sequence is started , it should not start again untill complted. Thinking about this , I will change the Lockout_60_sec in 90 seconds when the whole sequence is completed, but this is for later , when the basics work and I can finetune).

Hope it is more clear now,

thanks,
Cor

Move the action that resets Gate open and close VS to off into the Immediate section of open_gate. Once the action has triggered, there should be no need to delay this any further.

RTS can confirm but I suspect that PLEG’s delayed actions run consecutively so, in you current configuration, the timer completes before the VS is reset.

@RexBeckett:

I moved the “toggling virtual switch to off” to immediate. It worked … almost.

first test":
Clicking the virtual switch to on, did exactly all it ment to do.

The second test was to click the vitual switch again after 30 seconds. What I saw:
-virtual switch changed to “on”
-after about 20 seconds (after clicking the switch for the second time! it turned back to off, nu clue what switched it to off)
-after 90 seconds the gate nicely closed as it expected it to do.
-BUT… the gate opened again after about 10 seconds. I gues this is due to pressing the virtualswitch a second time and a delay by the “lockout_60_sec”

Any idea how to tackle this issue?

Cor

Right, yes, you will need to cancel the VS if it is turned on during the lockout period.

Conditions
IgnoreVS come_and_leave1 AND Lockout_60_sec

Actions
IgnoreVS Gate open and close VS SetTarget newTargetValue=0

YES!!!

It’s working good now, exactly how I want it … I was also able to import some PLEG I used to close the gate when it was not closed automatically.

Thanks a lot for your help guys!,
Cor

Crap!

I need some more help.

Opening and closing and checking , double checking, notifications , all works fine. Just the lights don’t behave how I expected.

There is a condition “gate_lights_on” when it is night and “the virutal switch for the gate has been switches on”
3 lights go on imidiately
1 light goes off after 5 minutes, the other 2 lights should go off after 15 minutes. But they go after after about 5 minutes.

I expect this happends when the virtual switch of the gate ( comming_and_leaving1) switches to off. If this is the case, how can I change this. I have to insert for this also something like:

Conditions IgnoreVS come_and_leave1 AND Lockout_60_sec

Actions
IgnoreVS Gate open and close VS SetTarget newTargetValue=0

Thanks,
Cor

attached the report in pdf

I don’t see how turning off the VS would result in the lights going off early - unless you have some other logic or scenes elsewhere. Try deleting the delayed actions for the lights and recreating them with shorter times - say 5 minutes and 8 minutes. Do you still get the problem?

I just removedthe hole conditions and action ,and inserted it again … working fine now.

Most likely I think it happened due to multiple activating this PLEG for troubleshooting purposeswithin the "15 minutes ", so the light would go out sooner due to the previous activation of this PLEG.

Nonetheless I found an error. When I re-inserted the conditon and actions I used the little arrow “revert to previous setting” , but with this I get a LUA PLEG startup failure.

Why doesn’t it work?

thanks,
Cor

Time to improve some PLEG of my gate…

On my gate I have a sensor which senses if the gate is open or close. But it is not working as it should be, sometimes the sensor activates when the gate is still closed. I am not sure if this is an electronic malfunction or the the wind pushing the gate slightly open. I expect it is the wind pushing the gate slightly.

I am not changing the sensor now , I will improve the sensor itself when I will build a new gate next year.

So … time to do some PLEG :slight_smile:

Objective: Send a notification when the sensor is active for more than 3 seconds.

Trigger:
Sensor_is_activated
Sensor_is_DEactivated
Schedule timer self-trigger - interval 3 sec. “Timer_x_sec_for_sensor”

Condition:
timer_start_gate_sensor >> expression : gate_sensor_is_activated

action:
advanced >> start timer “Timer_x_sec_for_sensor”

So… when the sensor is activated , the timer start. But now I am stuck.

How do I insert in PLEG to fire the notification when after the 3 seconds the sensor is still activated , but not when the sensor is deactivated.

Thanks,
Cor

StillActivated Sensor_is_activated and not Timer_x_sec_for_sensor and (Sensor_is_activated; !Timer_x_sec_for_sensor)

@ RexBeckett… thanks I am trying to understand this condition , but I don’t. :-\

In the previous condition-action (timer_start_gate_sensor) I have started the timer for the 3 seconds.

Now the seconds part (StillActivated) sends the notification.
When I try to write it in words: Sensor_is_activated and not Timer_x_sec_for_sensor and (Sensor_is_activated; !Timer_x_sec_for_sensor)

Sensor_is_activated but not the Timer_x_sec_for_sensor, which means the 3 seconds have passed. ( and is for that reason false)
AND, (Sensor_is_activated; !Timer_x_sec_for_sensor) this last part I don’t get. the ! is the same as NOT I read in your PLEG manual .

I don’t need the Sensor_is_DEactivated trigger?

Cor

Read it as: The sensor is tripped, the timer has stopped and the timer stopped after the sensor last tripped.

I don't need the Sensor_is_DEactivated trigger?
Not any more. Recent PLEG versions allow [b]!terms[/b] in sequence expressions as well as in boolean ones so there is no value in defining complimentary triggers.

Thanks, I see the logic now … not able to think off it myself , but at least I am understanding it :slight_smile:

Cor

Oh … I found an annoying error in my Gate PLEG.

I also inserted a notification when the gate is closed,
Sensor_long_DEativated Sensor_is_DEactivated AND NOT Timer_xsec_for_sensor AND (Sensor_is_DEactivated; !Timer_xsec_for_sensor)

It is working a bit too good , everytime LUA starts , and everynight arround 0200AM >:( I recieve a “gate is closed…” message.

Why is this? , Is this due to the Timer_start_for_sensor and the checkbox repeat is checked? can I uncheck it without any consequences?

thanks,
Cor