Periods are intended to represent different portions of the day. By default, xPLHal comes configured with two periods: Day and night.
Detection of day and night can be via a number of methods, some of which are listed below.
- The xPL DawnDusk service can be installed. This is a service that sends out xPL messages at dawn and dusk, based on the calculated sunset and sunrise times for your current location.
- An X10 motion sensor such as the MS13, or the PR511 external floodlight can be used to detect dusk and dawn. These devices send out an X10 message which can be picked up by xPLHal and used to set the Period accordingly.
- A light sensor can be directly wired to the PC via the joystick port, or via an add-on serial I/O interface. A utility is available for free download from www.xpl.myby.co.uk which will allow up to 8 devices to be connected to a joystick port and interfaced with an xPL system.
To set the period
The following code sample demonstrates setting the period to one of the values defined in the scripts \headers\XPLHAL_SETTINGS.XPL script:
sys.setting("Period") = SYS_PERIOD_NIGHT
To determine the current period
The following code sample demonstrates how to determine the current period, and take action accordingly:
CurrentPeriod = sys.setting("Period")
If CurrentPeriod = SYS_PERIOD_NIGHT Then
The above code will cause the X10 device A1 to be switched on only if the Period is currently night.
Specifying actions to occur when a period changes
You can create sub-routines that will be executed whenever a particular period becomes active.
By default, in the scripts\headers\periods.xpl file, you will find the following code:
Any code you place in these sub-routines will be executed whenever the period is set to the appropriate value.
For example, suppose you have a light outside your house which you wish to come on at dusk, and switch off at dawn.
You could modify the above scripts as follows:
You can use the Period in combination with the Mode setting to achieve a high level of conditional logic in your scripts.