Jump to content

Wait command inside a program


HansSolo

Recommended Posts

Posted

Hi,

I have a system that I monitor thru an X10 module(PSC01) that sends an X10 On or Off command depending on the system' s status. For every X10 command received I send a notification to my phone.

But because debouncing problems I get too many messages in 1 minute. I should have notification, lets say 1 in the morning and another one in the evening.

 

So I tried this:

 

Variable s_HQ_ON_OFF that changes every time an X10 command is received ( state variable). I want to be able to catch all X20 commands in case the system goes from ON to OFF then back ON during the " debouncing period" . ( if debounce is 5 minutes, signal goes from ON to Off>> generates a notification but gets back ON during the 5 minutes period, I want a second notification only after the 5 min. period)

 

Variable i_Debounce (integer) used to prevents program#3 of triggering while WAIT x minutes is in effect

 

Program#1:_______________________________

If

X10 'K2/Off (11)' is Received

 

Then

$s_HQ_ON_OFF = 0

$s_HQ_ON_OFF Init To 0

 

Else

- No Actions - (To add one, press 'Action')

 

 

Program#2:_______________________________

If

X10 'K2/On (3)' is Received

 

Then

$s_HQ_ON_OFF = 1

$s_HQ_ON_OFF Init To 1

 

Else

- No Actions - (To add one, press 'Action')

 

Program#3:_______________________________

 

If

$s_HQ_ON_OFF is 1

And $i_Debounce is 0

 

Then

$i_Debounce = 1 >> prevents the program to execute from here

Run Program 'Mac_X10_Hot (Else Path) >>> (send another X10 signal)

Send Notification to 'Jacques SMS Bell' content 'Mess1'

Wait 5 minute

$i_Debounce = 0 << ...to here

 

Else

$i_Debounce = 1

Run Program 'Mac_X10_Cold ' (Then Path) >>> send another X10 signal

Send Notification to 'Jacques SMS Bell' content 'Mess2'

Wait 5 minute

$i_Debounce = 0

 

 

Problem: If X10 K2/ON is received followed by a few second later by an X10 K2/OFF the program #3 sends 2 notifications back to back without the 5 minutes delay.

 

I thought that by setting i_Debounce=1 after detecting that (s_HQ_ON_OFF changes AND i_debounce=0) it would prevent the program to run again.

 

What am I missing?

I also tried to disabled Program#3 within itself in order for the wait to complete but I get the same results

 

Program#3 modified:

If

$s_HQ_ON_OFF is 1

 

Then

Disable Program 'tst var_HQ_ON_OFF'

Run Program 'Mac_X10_Eau Chaude' (Else Path)

Send Notification to 'Jacques SMS Bell' content 'Bi_Energie Cold'

Wait 1 minute

Enable Program 'tst var_HQ_ON_OFF'

 

Else

Disable Program 'tst var_HQ_ON_OFF'

Run Program 'Mac_X10_Hot (Else Path) >>> send another X10 signal

Send Notification to 'Jacques SMS Bell' content 'Mess1'

Wait 5 minute

Enable Program 'tst var_HQ_ON_OFF'

 

I don' t understand why I get the else condition 1 second later and the wait period have no effect

 

Can somebody help me understand?

 

Question on another subject:

is there a way to have a printout of all the programs ( with folder) without having to copy them individually on the clipboard?

Thanks

Posted

The following sequence does NOT stop the Program from being triggered ....

 

If

$s_HQ_ON_OFF is 1

And $i_Debounce is 0

 

 

It stops the Then clause should $i_Debounce > 0 but all that does is force a False If compare so the Else clause runs regardless of what $s_HQ_ON_OFF is set to. That is the problem with combining True and False conditions in the same Program when the False/Else runs for any False condition rather than only the one specific condition.

 

 

A collection of Programs cannot be copied to the Clipboard at once.

Posted

Thanks LeeG

I had completely forgot about what triggers a program compared to what the test portion is.

I'll modify the program to remove the ELSE clause and have a separate program for the On or OFF conditions

 

 

For my second question, it would be nice if UD implement some sort of a Global "print out" of all the programs. I don't always have access to my ISY and I'm the kind of person that likes to have a hard copy to work on. Copy to clipboard of all the programs is very long.

 

Thanks

Posted
Hi LeeG, thank you!

 

Hi HansSolo, yes, indeed!

 

With kind regards,

Michel

 

Michel,

 

Kind of blurring together two threads, but this is what I am talking about. This user might have been reminded of what the triggers were if things were color coded.

Posted

Not sure if this will work for your case but a simple wait can handle some cases.

 

if cond1

or cond2

or cond3

 

 

then

wait 5 min

do something

 

if the conditions can trigger multiple times or in varying orders then the wait will trap the multiple events in that if another one occurs during the wait it will just restart the wait. The problem with this approach is that it doesn't bound the debounce period in that if you have a condition triggering every 4 minutes you will never get the action done. Still for some cases I've had it does handle things and is simpler that the explicit approach of multiple programs to create the debounce window.

 

By the way - a simple example of when this works is if the if simply has a number of state variables in the if all of which may change in a very short interval due to other programs running and you simply want to collapse any change into a single execution of the action.

Posted

Hi everyone,

 

I've just came up with a solution to my problem. There are other ways to do it but i've just wanted to share my solution.

I've tested the solution with alternating changes in the trigger signal and it works great. :D

 

 

System that monitors an electronic circuit and sends a notification when it changes state.The problems is that sometimes changes are too rapid and too many in a short term but usually the system changes state few times a day.

The rapids changes are probably due to switches bouncing or undesirable states.

 

Program that checks the reception of an On/OFF X10 command and send a Notification of the new status

after sending the notification, a debounce window prevents further notification but the current status is still updated

After the debounce timer the current status, if changed will trigger another Notification with its debounce period

 

Programs 1 &2 keep the current status in a state variable $s_HQ_Cur_Status

State variable $s_HQ_Debounce_TmrON is a flag that when 1 prevents the THEN clause of program#3 to run. It is set to 1 by program#3 indicating that a notification was sent and reset to 0 when timer $s_HQ_Timer reaches 0

Program#3 compares current signal status $s_HQ_Cur_Status with its previous status $i_HQ_Prev_status. This previous status is updated only when a notification sequence is executed.

 

Adjust Wait period (Program#4) and $s_HQ_Timer (Program#3) to get the desired debounce period (here the debounce period is 15sec.)

 

 

------------------------------------------------------

Program#1: Detect_sig HQ_OFF is received

If

X10 'K2/Off (11)' is Received

 

Then $s_HQ_Cur_Status = 0

$s_HQ_Cur_Status Init To 0

 

Else

- No Actions - (To add one, press 'Action')

 

Every time an X10 command OFF is received update Current status

s_HQ_Cur_status is State variable in order to trigger program "Test if HQ status changed

------------------------------------------------------

Program#2: Detect_sig HQ_ON is received

If

X10 'K2/On (3)' is Received

 

Then

$s_HQ_Cur_Status = 1

$s_HQ_Cur_Status Init To 1

 

Else

- No Actions - (To add one, press 'Action')

 

Every time an X10 command ON is received update Current status

 

------------------------------------------------------

Program#3: Test if HQ status changed

If

$s_HQ_Debounce_TmrON is 0

And $i_HQ_Prev_status is not $s_HQ_Cur_Status

 

Then

Run Program 'xmit HQ status' (If)

Disable Program 'HQ_Timer_pgm'

$s_HQ_Timer = 15

$i_HQ_Prev_status = $s_HQ_Cur_Status

Enable Program 'HQ_Timer_pgm'

$s_HQ_Debounce_TmrON = 1

 

Else

- No Actions - (To add one, press 'Action')

 

Test if HQ status changed while debouncetimer OFF

Only when debounce timer is OFF AND HQ status as changed from its previous status

A notification is sent

And Debounce timer is started and the timer value initialized

 

------------------------------------------------------

Program#4: HQ_Timer_pgm

If

$s_HQ_Timer is not 0

 

Then

Wait 1 second

$s_HQ_Timer -= 1

 

Else

$s_HQ_Debounce_TmrON = 0

 

 

------------------------------------------------------

Program#5: xmit HQ status

If

$i_HQ_Prev_status is 1

 

Then

Run Program 'Mac_X10_HOT' (Then Path)

Send Notification to 'SMS xyz' content 'system Hot'

 

Else

Run Program 'Mac_X10_HOT' (Else Path)

Send Notification to ' SMS xyz' content 'system Cold'

 

Always disabled, Run by tst

 

 

Every comments/suggestions would be appreciated

 

thanks

Guest
This topic is now closed to further replies.

×
×
  • Create New...