Non-blocking delay with X10 commands

laodice

Member
I’m currently using my webcontoller as alarm unit.
When an IP gets high an OP is set high for some time and an email is being sent.
Now I would like some wireless devices to be triggered by X10 commands.
Is het possible to use a non-blocking delay e.g. 5 minutes with the command X10 1 0 1 just like a TTL output:
SET OP1[900000] 1
 
 
ALARM:
SET OP1[900000] 1 
SET OP3[45000] 1  
EMAIL EM1  
RET
 
X10 uses the X10 plc command, not by setting OPx, rather it is a sequence command through RF to X10 RF receiver.  That X10 RF transmitter needs to be wired to OP8, X10 RF transmitter also needs to be powered by 5V from terminal 3 on either temp sensor or humidity sensor.
 
X10 command does not have non-blocking delay associated with it.
 
ALARM:
SET OP1[900000] 1 
SET OP3[45000] 1  
X10 1 0 1
EMAIL EM1  
RET   

So when IP1 is high sub-routine ALARM will set OP1 (lights) high for 15 minutes OP3 (siren ) high for 45 seconds and send an ON signal  through a transmitter to the X10 receiver that can’t be set off after e.g.15 minutes unless with a blocking DELAY
 
What do you plan to do? turn on a X10 device for the same period OP3 high?  If so, you can check OP3 status in main loop and send proper X10 command to turn that device on and off.
 
The X10 device is not always on the same period as OP3 but I could use another not used OPx to check the status.
I’ve been thinking of using a VAR to set X10 off bit I’m not so familiar with variables:
 
START   
CALLSUB INIT_OUT  
TSTLT CYEAR 2015 
GOTO START  
LOOP:
 
CALLSUB CHECK_DIS  
TSTEQ VAR1 0 
CALLSUB CK_DOORS  
TSTEQ VAR2 0
  
CALLSUB DISAB_ALM  
GOTO LOOP  
END   
INIT_OUT:
 
SET VAR1 0 
SET VAR2 0
RET   
CHECK_DIS:
TSTEQ IP8 0 
DELAY 50  
TSTEQ IP8 0 
SET VAR1 1 
TSTEQ IP8 1 
SET VAR1 0 
RET   
DISAB_ALM:

X10 1 0 0

RET  
CK_DOORS:
TSTEQ IP1[100] 1 
CALLSUB ALARM  
RET   
ALARM:
 
X10 1 0 1
EMAIL EM1  
SET VAR2[600000]  1
RET
 
If you have decided on the X10 on/off period, on what condition to start when to stop, then we can work with you to develop the PLC code.
 
The interval time between on and off would be 15 minutes and the device would be started by a digital input pulse high. During this interval one email is sent.
 
If that is the case, you can write a subroutine, in which check if that input is high and a flag for X10 device on is low, is so, then turn on the X10 device and set the flag high. In another routine, check if X10 device on flag is high. If so, check for how long that time is, if that is longer than 15 minutes, then reset that flag, turn off X10 device.
 
You can use a VAR or RAM for the flag. They normally is zero in value. You can store the CTS in it, then later on check if that is zero, if not zero, means the X10 device is on, then minus that from CTS and see if the differences is bigger than 15 minutes. If bigger, then start reset process and stopping X10 device.
 
That seems like an unnecessarily complex way to do a simple task.
 
Here's a snippet of (tested) code, as stripped down, lean, mean as I can think of:
 
It will wait for input 1 to go high for AT LEAST 100 milliseconds (ie, some debounce).
When input 1 goes high and stays high for 100ms, it will TURN ON output 1.
 
Even if input 1 goes away (goes low), input 1 will remain on.
After 60 seconds, output 1 will go off. Change the values to suit your needs.
 
 
start
     tsteq   ip1[100] 1
     set      op1 1
 
     tsteq   op1[60000] 1
     set      op1 0
end
 
Yes,
This works for OPx but does not work for X10 commands unless you set them both low maybe?
 
TSTEQ IP1 [100] 1
X10 1 0 1
TSTEQ IP1[100] 1
SET OP1 1
 
TSTEQ OP1[60000] 1
X10 1 0 0
TSTEQ OP1[60000] 1
SET OP1 0
 
It's a simple change to either use a goto, or callsub after the test, to do more than one thing.
 
start
     tsteq   ip1[100] 1
     callsub turnon
 
     tsteq   op1[60000] 1
     callsub turnoff
end
 
turnon:
     set      op1 1
     x10   1 0 1
     email em1
     return
 
turnoff:
     set      op1 0
     x10   1 0 0
     email  em2
     return
 
This seems to work:
 
START   
LOOP:
TSTEQ IP5[100] 1 
CALLSUB TURNON  
TSTEQ OP1[300000] 1 
CALLSUB TURNOFF  
GOTO LOOP  
END   
 
TURNON:
SET OP1 1 
X10 1 0 1
TSTEQ RAM1 0 
EMAIL EM2  
DELAY 500  
SET RAM1 1 
RET   
 
TURNOFF:
SET OP1 0 
X10 1 0 0
SET RAM1 0 
RET
 
I don't know if it is the most "logic"
 
I'm just wondering if
SET VAR1[300000] 1 would work
 
This seems to work as well:
START   
LOOP:
TSTEQ IP5[100] 1 
CALLSUB TURNON  
TSTEQ VAR2[300000] 1 
CALLSUB TURNOFF  
GOTO LOOP  
END   
TURNON:
SET VAR2 1 
X10 1 0 1
TSTEQ VAR1 0 
EMAIL EM2  
DELAY 500  
SET VAR1 1 
RET   
TURNOFF:
SET VAR2 0 
X10 1 0 0
SET VAR1 0 
RET
 
It sends 1 email if IP5 = 1 less then 300sec.
I can't check the X10 commands because I have no X10 device for the moment
 
laodice said:
This seems to work:
 
START   
LOOP:
TSTEQ IP5[100] 1 
CALLSUB TURNON  
TSTEQ OP1[300000] 1 
CALLSUB TURNOFF  
GOTO LOOP  
END   
 
TURNON:
SET OP1 1 
X10 1 0 1
TSTEQ RAM1 0     <------
EMAIL EM2  
DELAY 500     <------
SET RAM1 1  <------
RET   
 
TURNOFF:
SET OP1 0 
X10 1 0 0
SET RAM1 0    <------
RET
 
Can you tell me what the bits indicated in green are for??
 
The way the original code was submitted, you couldn't actually reach the "turnon" routine unless it had done an off-to-on transition and stayed on for at least 5 mins (or whatever), so the extra code to make sure it hadn't sent the email (tsteq ram1 0) is unnecessary, as is setting ram1 (because you turn op1 off, so it will not execute the same code again until it has had another transition), which renders the "turnoff" clearing of ram1 unnecessary too!
 
Back
Top