To control the lights I use the Fb_LatchingRelay function block from the buliding_common.lib library of WAGO.
To control a light circuit it is enough to:
In the variable definition part: LIGHT1 : Fb_LatchingRelay;
I placed the definition of the function Block controlling lights in the VAR_PERSISTENT part so that after the electricity is cut off the controller remembers the status of each light. I do not need to walk in the darkness in the search of a switch when the power is turned back on.
In the program: LIGHT1(xSwitch:=IN1); OUT1:=LIGHT1.xActuator;
IN1 is an input connected to a wall-mounted switch (i.e. one that is only pressed and returns to the same position after it is released)
OUT1 is the output controlling the given circuit/light
CONTROLL BY MANY SWICTHES
In order to control a light with many switches it is enough to place in the program:
LIGHT1(xSwitch:=IN1 OR IN2 OR IN3 OR IN4);
Where IN1 to IN4 are inputs connected to 4 different switches. Each of them can turn the light circuit (OUT1) on or of independently.
CONTROLLING THROUGH A VISUALIZATION
To control a function block through a visu, I define an additional variable:
Which I add to the function block:
LIGHT1(xSwitch:=IN1 OR VIS_LIGHT1);
In the visualization I modify a given button/object as follows: in the Input section, in Tap Variable enter PLC_PRG.VIS_LIGHT1.
CONTROLLING A FEW CIRCUITS AT ONCE
Function block Fb_LatchingRelay has ‘inputs’ xCentON i xCentOFF, which turn the given block on or off. They can be used to turn a greater number of outputs at once. Define additional variables:
And in the program bind the variables to real switches (for example inputs 98 and 99):
In the programming part in the light controlling function blocks:
LIGHT1(xSwitch:=IN1 OR VIS_LIGHT1, xCentOFF:=LIGHTS_ALL_ON, xCentON:=LIGHTS_ALL_OFF);
LIGHT2(xSwitch:=IN2 OR VIS_LIGHT2, xCentOFF:=LIGHTS_ALL_ON, xCentON:=LIGHTS_ALL_OFF);
LIGHT3(xSwitch:=IN3 OR VIS_LIGHT3, xCentOFF:=LIGHTS_ALL_ON, xCentON:=LIGHTS_ALL_OFF);
AUTOMATED SWICHING WITH A GIVEN DELAY
It happens very often that someone from my family leaves a room, closes the door and forgets to turn a light off. The problem can be solved by installing a motion sensor. It can however be handled by turning the light off after a given time.
Define a new variable:
The function block Fb_Delay is a part of the building_common.lib
In the program:
LIGHT1_DELAY(xInput:=OUT1, dwTon_10tel_s:=12000, dwToff_10tel_s:=1);
LIGHT1(xSwitch:=IN OR VIS_LIGHT1, xCentOFF:=LIGHT1_DELAY.xOutput);
The parameter dwTon_10tel_s defines the time after which the xOutput will be set to TRUE and the parameter dwToff_10tel defines how much time will pass before xOutput’s TRUE will be replaced by FALSE. In the case of the code above, the LIGHT1 will be switched off after 20 minutes, the impulse coming from LIGHT1_DELAY will last 0.1 sec.
In a more complex example we can turn the light of a dressing room off after the last light of the neighbor room is switched off. Additionally the functions of the delayed turning off is limited to situations when there are no lights in the neighbor room. Here is the code:
The variable definitions:
SIGNAL_LIGHTS_ALLOFF : F_TRIG; (*will signal lights gonig off in the neighbor room*)
LIGHTS_ALLOFF : BOOL; (*central variable to switch all the lights off*)
LIGHT4_DELAY : Fb_Delay; (*delayed switching in the dressing room*)
VIS_LIGHT4 : BOOL; (*controlling via visualization*)
In the program:
SIGNAL_LIGHTS_ALLOFF(CLK:=OUT1 OR OUT2 OR OUT3); (*OUT1-3 lights in the neighbor room*)
LIGHTS_ALLOFF:=IN99; (*turning all lights of with a switch at input 99*)
LIGHT4_DELAY(xInput:=OUT4, dwTon_10tel_s:=12000, dwToff_10tel_s:=1); (*delay timer*)
LIGHT4(xSwitch:=IN4 OR VIS_LIGHT4, xCentOFF:=LIGHTS_ALLOFF OR SIGNAL_LIGHTS_ALLOFF.Q OR (LIGHT4_DELAY.xOutput AND NOT (OUT1 OR OUT2 OR OUT3)));
The LIGHT4 is controlled by IN4 and VIS_LIGHT4, which by sending impulses switch the OUT4. Additionally if the button at IN99 is switched it flips the LIGHTS_ALLOFF briefly to TRUE and LIGHT 4 goes off. If the last light of the LIGHT1 to LIGHT3 (at OUT1 – OUT3) goes off – the function block SIGNAL_LIGHTS_ALLOFF will show TRUE at .Q output and LIGHT4 goes off. Moreover a turn-off signal will be send by the LIGHT4_Delay function block after 1 200 seconds, it will, however be ignored, if any of the lights LIGHT1 – LIGHT3 is on.
Having a centralized system controlling all circuits forces a change in the habits related to using wall-mounted switches. Traditionally one button controls one light. I needed to erase that knowledge in order to go further with configuring my system.
On the outside wall of my bathroom I have 2 double switches – a total of 4 buttons. 1 controls the light in the lobby so it is excluded from the analysis below. The remaining 3 buttons control not circuits but scenes:
1. The first turns the 4 ceiling lights (most usage)
2. The second turns the 4 ceiling lights and a mirror light (evening tasks)
3. The third turns all lights on (full illumination)
4. Pressing of the any of the buttons on the way out turns all lights off
Here is the program:
IN1, IN2, IN3 – inputs connected to the 3 keys
OUT1, OUT2, OUT3 – three light circuits
LIGHT1, LIGHT2, LIGHT3 :Fb_LatchingRelay;
LIGHT1(xSwitch:=IN1 OR IN2 OR IN3); OUT1:=LIGHT1.xActuator;
LIGHT2(xSwitch:=IN2 OR IN3, xCentOFF:=SIGNAL_LIGHT1_OFF); OUT2:=LIGHT2.xActuator;
LIGHT3(xSwitch:=IN3, xCentOFF:=SIGNAL_LIGHT1_OFF); OUT3:=LIGHT3.xActuator;
A traditional controls of the separate lights is possible from within the bathroom.