Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on Rules#Timer=5 do
- event,ControlZ3=[VAR#7]
- endon
- on Rules#Timer=6 do
- TaskValueSet,4,4,0
- endon
- on ControlZ3 do
- //control?cmd=event,ControlZ3=0
- // both shutters of the room controlled at the same time, value in percent; [Z3#S] = room state (in percent), [Z3#SL] = State of left shutter, [Z3#SR] = right shutter
- // each shutter is controlled by 2 relays, the first relay to give the second one power (by closing NO), the second one NC to close, NO to open. need this to avoid giving the shutter drive on both directions power at the same time.
- // additionally in front of the first relay there is a power relay which first needs to be closed, to have power on the cabled relays. GPIO = 2
- // delay of 250 milliseconds is needed because of the shutter drive (they do not like to drive instantly into the other direction)
- // VAR#6 is used to decide, what needs to be done. driving a shutter in percent (if value is between 1 and 99), opening a shutter (value = 0), closing a shutter (value = 100); some special states like -1 (drive both shutters to the same position first, afterwards drive both to the requested position), 101, 102 and 103 are not done yet.
- // used temporary for calculations: VAR#10, VAR#11, VAR#12, VAR#13, VAR#14, VAR#15
- // used temporary to preserve the requested position: VAR#7
- // used timers: TimerSet,6 for locking ([Z3#M]), TimerSet,5 for driving after syncing both shutters to the in VAR#7 preserved position.
- if [Z3#SL] != [Z3#SR]
- logentry,"Z3SL=[Z3#SL] and Z3SR=[Z3#SR] not in same state. Sync first."
- Let,6,-1
- Let,7,%eventvalue%
- else
- Let,6,%eventvalue%
- endif
- if [VAR#6] > 0 and [VAR#6] < 100 and [Z3#M] = 0
- //open/close both in percent; 20 = seconds for a complete close or open. as I use LongPulse I need to calculate always seconds out of the percent.
- Let,10,(20/100)*[VAR#6]
- Let,11,(20/100)*[Z3#S]
- if [VAR#11] > [VAR#10]
- // open a bit
- Let,12,[VAR#11]-[VAR#10]
- logentry,Z3_o_secs=[VAR#12]
- gpio,2,0
- TimerSet,8,[VAR#12]+2
- delay,250
- LongPulse,17,0,[VAR#12]
- LongPulse,21,0,[VAR#12]
- LongPulse,18,0,[VAR#12]
- LongPulse,19,0,[VAR#12]
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- endif
- if [VAR#11] < [VAR#10]
- //close a bit
- Let,12,[VAR#10]-[VAR#11]
- logentry,Z3_c_secs=[VAR#12]
- gpio,2,0
- TimerSet,8,[VAR#12]+2
- delay,250
- LongPulse,17,0,[VAR#12]
- gpio,21,1
- LongPulse,18,0,[VAR#12]
- gpio,19,1
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- endif
- TaskValueSet,4,1,[VAR#6]
- TaskValueSet,4,2,[VAR#6]
- TaskValueSet,4,3,[VAR#6]
- else
- if [VAR#6] = 0 and [Z3#M] = 0
- // open complete. always 20 seconds, as it is a kind of "now I am very sure it is opened" status.
- logentry,Z3_o_comp
- gpio,2,0
- TimerSet,8,20+2
- delay,250
- LongPulse,17,0,20
- LongPulse,21,0,20
- LongPulse,18,0,20
- LongPulse,19,0,20
- TimerSet,6,20
- TaskValueSet,4,4,1
- TaskValueSet,4,1,[VAR#6]
- TaskValueSet,4,2,[VAR#6]
- TaskValueSet,4,3,[VAR#6]
- endif
- if [VAR#6] = 100 and [Z3#M] = 0
- // close complete. always 20 seconds, as it is a kind of "now I am very sure it is closed" status.
- logentry,Z3_c_comp
- gpio,2,0
- TimerSet,8,20+2
- delay,250
- LongPulse,17,0,20
- gpio,21,1
- LongPulse,18,0,20
- gpio,19,1
- TimerSet,6,20
- TaskValueSet,4,4,1
- TaskValueSet,4,1,[VAR#6]
- TaskValueSet,4,2,[VAR#6]
- TaskValueSet,4,3,[VAR#6]
- endif
- if [VAR#6] = 101
- //stop both
- logentry,Z3_stop
- LongPulse,17,0,0
- LongPulse,21,0,0
- LongPulse,18,0,0
- LongPulse,19,0,0
- TimerSet,6,1
- endif
- if [VAR#6] = 102
- //special state
- endif
- if [VAR#6] = 103
- //special state
- endif
- if [VAR#6] = -1 and [Z3#M] = 0
- //sync shutters; set timer for drive both to requested position afterwards
- Let,14,([Z3#SL]-[VAR#7]) // needed for compare below
- Let,15,([Z3#SR]-[VAR#7]) // needed for compare below
- if [VAR#15] > [VAR#14]
- logentry,"Sync R to L"
- // Left shutter is near to the requested position. so first drive right shutter to the position of the left
- Let,13,(20/100)*([Z3#SR]-[Z3#SL])
- event,ControlZ3R=[Z3#SL]
- Let,13,abs([VAR#13])+1
- TimerSet,5,[VAR#13]
- else
- logentry,"Sync L to R"
- // Right shutter is near to the requested position. so first drive left shutter to the position of the right
- Let,13,(20/100)*([Z3#SL]-[Z3#SR])
- event,ControlZ3L=[Z3#SR]
- Let,13,abs([VAR#13])+1
- TimerSet,5,[VAR#13]
- endif
- endif
- endif
- endif
- endon
- on ControlZ3L do
- //control?cmd=event,ControlZ3L=0
- // control only left shutter, in percent.
- Let,6,%eventvalue%
- if [VAR#6] > 0 and [VAR#6] < 100 and [Z3#M] = 0
- //open/close percent
- Let,10,(20/100)*[VAR#6]
- Let,11,(20/100)*[Z3#SL]
- if [VAR#11] > [VAR#10]
- // open a bit
- Let,12,[VAR#11]-[VAR#10]
- logentry,Z3L_o_secs=[VAR#12]
- gpio,2,0
- TimerSet,8,[VAR#12]+2
- delay,250
- LongPulse,18,0,[VAR#12]
- LongPulse,19,0,[VAR#12]
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- endif
- if [VAR#11] < [VAR#10] and [Z3#M] = 0
- //close a bit
- Let,12,[VAR#10]-[VAR#11]
- logentry,Z3L_c_secs=[VAR#12]
- gpio,2,0
- TimerSet,8,[VAR#12]+2
- delay,250
- LongPulse,18,0,[VAR#12]
- gpio,19,1
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- endif
- TaskValueSet,4,2,[VAR#6]
- if [Z3#SL] = [Z3#SR]
- TaskValueSet,4,1,[VAR#6]
- else
- TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
- endif
- else
- if [VAR#6] = 0 and [Z3#M] = 0
- // open left shutter complete
- logentry,Z3L_o_comp
- gpio,2,0
- TimerSet,8,20+2
- delay,250
- LongPulse,18,0,20
- LongPulse,19,0,20
- TimerSet,6,20
- TaskValueSet,4,4,1
- TaskValueSet,4,2,[VAR#6]
- if [Z3#SL] = [Z3#SR]
- TaskValueSet,4,1,[VAR#6]
- else
- TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
- endif
- endif
- if [VAR#6] = 100 and [Z3#M] = 0
- // close left shutter complete
- logentry,Z3L_c_comp
- gpio,2,0
- TimerSet,8,[VAR#12]+2
- delay,250
- LongPulse,18,0,20
- gpio,19,1
- TimerSet,6,20
- TaskValueSet,4,4,1
- TaskValueSet,4,2,[VAR#6]
- if [Z3#SL] = [Z3#SR]
- TaskValueSet,4,1,[VAR#6]
- else
- TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
- endif
- endif
- if [VAR#6] = 101
- //stop Z3L
- logentry,Z3L_stop
- LongPulse,18,0,0
- LongPulse,19,0,0
- TimerSet,6,1
- endif
- if [VAR#6] = 102
- //special state
- endif
- if [VAR#6] = 103
- //special state
- endif
- endif
- endon
- on ControlZ3R do
- //control?cmd=event,ControlZ3R=0
- // same as above for the left shutter now for the right shutter
- Let,6,%eventvalue%
- if [VAR#6] > 0 and [VAR#6] < 100 and [Z3#M] = 0
- //open/close percent
- Let,10,(20/100)*[VAR#6]
- Let,11,(20/100)*[Z3#SR]
- if [VAR#11] > [VAR#10]
- // open a bit
- Let,12,[VAR#11]-[VAR#10]
- logentry,Z3R_o_secs=[VAR#12]
- gpio,2,0
- TimerSet,8,[VAR#12]+2
- delay,250
- LongPulse,17,0,[VAR#12]
- LongPulse,21,0,[VAR#12]
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- endif
- if [VAR#11] < [VAR#10]
- //close a bit
- Let,12,[VAR#10]-[VAR#11]
- logentry,Z3R_c_secs=[VAR#12]
- gpio,2,0
- TimerSet,8,[VAR#12]+2
- delay,250
- LongPulse,17,0,[VAR#12]
- gpio,21,1
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- endif
- TaskValueSet,4,3,[VAR#6]
- if [Z3#SL] = [Z3#SR]
- TaskValueSet,4,1,[VAR#6]
- else
- TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
- endif
- else
- if [VAR#6] = 0 and [Z3#M] = 0
- logentry,Z3R_o_comp
- gpio,2,0
- TimerSet,8,20+2
- delay,250
- LongPulse,17,0,20
- LongPulse,21,0,20
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- TaskValueSet,4,3,[VAR#6]
- if [Z3#SL] = [Z3#SR]
- TaskValueSet,4,1,[VAR#6]
- else
- TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
- endif
- endif
- if [VAR#6] = 100 and [Z3#M] = 0
- logentry,Z3R_c_comp
- gpio,2,0
- TimerSet,8,20+2
- delay,250
- LongPulse,17,0,20
- gpio,21,1
- TimerSet,6,[VAR#12]
- TaskValueSet,4,4,1
- TaskValueSet,4,4,1
- TaskValueSet,4,3,[VAR#6]
- if [Z3#SL] = [Z3#SR]
- TaskValueSet,4,1,[VAR#6]
- else
- TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
- endif
- endif
- if [VAR#6] = 101
- //stop Z3R
- logentry,Z3R_stop
- LongPulse,17,0,0
- LongPulse,21,0,0
- TimerSet,6,1
- endif
- if [VAR#6] = 102
- //special state
- endif
- if [VAR#6] = 103
- //special state
- endif
- endif
- endon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement