To repeat the steps in this tutorial you will need to install a Motion Sensor and Dimmer Module on a Fibaro Home Center 2. These devices should be placed in the same room of your house.
We will create two Lua scenes. Our scenes will use a global variable to pass information between them.
One scene will monitor the light switch and toggle the value of the global variable each time it is switched.
The other scene will run continuously and monitor the value of the light sensor and the dimmer module. If the global variable is turned on, then it will increase or decrease the value of the dimmer to try and maintain a constant level of light in the room.
When you install the Fibaro Motion Sensor, three devices are created on your Home Center 2:
We are interested in the 3rd device.
By default, the level of light in a room will need to change by 200lux in order for the sensor to report it to the Home Center 2. We want to decrease this value so that the changes in light will be detected more precisely. However, keep in mind that the lower this value, the more often the device will want to send changes – the more often it wants to send changes, the more often it has to turn on its radio – the more often the radio is turned on, the quicker it will run out of batteries. For this tutorial, we will change it to a value of 20lux, but this value may not suit your purposes – adjust it accordingly.
To modify the lux level change threshold, follow these steps:
Note: As we are about to change a Z-Wave parameter, make sure you locate the master motion device, not the slave light level device!
Now your motion sensor will report changes in the light level of the room as small as 20lux.
We also need to modify the parameters of our dimmer module to enable sceneActivation.
By default sceneActivation is turned off, but this feature allows us to detect when the switch on the device is clicked. We will use this to monitor when the light is manually turned off (so that it doesn't automatically light the room at night!).
This scene will begin to work immediately. Its only job is to change the value of the global variable when the switch is clicked. If it is 1, make it 0. If it is 0, make it 1.
We will now create a scene in Lua to monitor the level of light and increase or decrease the value of the dimmer as required.
At the top of the scene you will see the li
%% autostart
This causes the scene to start running as soon as the Home Center 2 starts (or the scene is saved).
The following lines allow this scene to run only once at a time (just in case it is manually started):
Once the scene is running, it then starts (on line 50) an infinite loop which causes the remainder of the scene to repeat forever.
The steps in this forever repeating loop are as follows:
Lines 52-55:
Get the values of the global variable, the dimmer and the light sensor
Lines 58, 71 and 84 :
See if the light level is too low, to high or just right. Each of these tests has an associated block of code.
Lines 64 and 77 are the lines that are used to set the value of the dimmer. The new value is multiplied with the value of the global variable. This is going to be either 1 or 0. In this way, if the lights should be off, the value of the dimmer will be set to 0.
There are several factors which influence the settings of this scene:
For more information on programming the Home Center 2 in Lua, see our support page at lua