Logo Banner

Velleman K8000 - [K8000 Standalone Usage] - [K8000 Home Automation]

Home Automation Modules

Usage of the classes

My Home Automation system has 11 different classes you can use. All of the functionality is contained within this class. For most classes you can build as many instances as you wish. You should add a new line for each required functionality in the Program.cs file, under step 3 ("Define your functionalities").

Detailed overview

1. CmdAmbiance

The CmdAmbiance is used to create a certain ambiance in a room. Pushing the button will start a number of I/O channels, and will set a number of DAC outputs to the desired level.

The CmdAmbiance class takes 4 parameters: the number of the I/O push button, the I/O channels that should be set, the DAC channels that should be set and the output level for the DAC channels. You need to pass the channels as a Group() object. A group can hold as many channels as you like

    const int BTN_AMBIANCE = 1;
    new CmdAmbiance(BTN_AMBIANCE, 
                    new Group(16, 15, 14, 13), 
                    new Group(1, 2, 3), 

2. CmdDimmer

The CmdLogger controls a dimmer (DAC output). You need 1 switch button to operate the dimmer. The mechanism is like this: A short press will turn ON/OFF the light (ON=maximal intensity). You need to keep pressing the button to start dimming. The light will then slowly start to dim. You can release the button when the desired output level is reached.

    const int IO_DIMMER_BUTTON=1;
    const int DAC_DIMMER_OUTPUT=1;

3. CmdLogger

The CmdLogger is an experimental class. You can use it to monitor some I/O channels. When a monitored channel changes, its state is written to a .CSV file on the µSD card. You really need a working RTC clock before you can use this class: use the CmdRTC for this (Requires a Fez Connect Shield with Ethernet functionalities!). Each time a channel changes this is added to an internal buffer. This buffer is written to the µSD card every minute.

The example below shows the code you need to add to log any of the 16 I/O channels of the K8000. You can pass any number of I/O channels to this function.

    new CmdLogger(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);

4. CmdPanicButton

The CmdPanicButton is used to create a state of alarm. It can be activated/ deactivated by pressing the panic button for 5 seconds. Then all of the selected I/O channels will be activated. Press the panic button again to deactivate the I/O channels.

you only need to define a CmdPanicButton() object. The first parameter is the I/O channel of the switch. Then you just need to specify the I/O channels you want to include to the Panic button function. You can specify as many channels as you like.

    const int BTN_PANIC = 1;
    new CmdPanicButton(BTN_PANIC,10,11,12,13,14,15,16);

5. CmdRTC

The CmdRTC() is an advanced class that provides date/time functionalities to your FEZ. It will make sure the clock of the FEZ is always right. During startup the RTC clock is read. Afterwards the RTC clock is synchronized with an NTP server on the Internet every few hours.

You need to have the FEZ Connect Shield (with the Ethernet module) before you can start using this class. The following example shows how you can setup an RTC clock which is updated every 12 hours:

    new CmdRTC(12);

Unfortunately there is more to it: you first need to setup the network properties of the FEZ. The Program.cs file contains the following lines. You need to modify them so they match with your network. You always need to assign a fixed IP address to the FEZ.

The NTP host is the IP address of your NTP server. I used the address of the NTP server of my Internet Provider. Probably you need to use another one. The time offset is the difference between your local time and the GMT time, in seconds. Belgium has a difference of 1 hour, thus 3600 seconds.

    // RTC timer/NTP global specifications
    CmdRTC.ip = new byte[] { 192, 168, 2, 150 };                        // fixed IP address for your FEZ
    CmdRTC.subnet = new byte[] { 255, 255, 255, 0 };                    // used subnet
    CmdRTC.gateway = new byte[] { 192, 168, 2, 1 };                     // used gateway
    CmdRTC.mac = new byte[] { 0x00, 0x88, 0x98, 0x90, 0xD4, 0xE0 };     // used MAC address
    CmdRTC.ntpHost = new byte[] { 195, 130, 132, 18 };                  // used NTP server (IP address)
    CmdRTC.dns = new byte[] { 192, 168, 2, 1 };                         // used DNS server
    CmdRTC.time offset = 3600;		

6. CmdSecurity

CmdSecurity is a security feature to fake someone is at home. It will start/stop I/O channels at random times. The class takes a few parameters: first you need to specify the channel of the push button to activate the security mode. Then you need to specify two booleans (true/false):

Last but not least you need to specify the I/O channels you want to use for the security mode. You can use as many as you like. In the sample below I defined a CmdSecurity without PowerSavingMode, for the I/O channels 10-16:

    int BTN_SECURITY = 1;
    new CmdSecurity(BTN_SECURITY, true, false, 10, 11, 12, 13, 14, 15, 16);

The CmdSecurity has some global parameters that change the behavior of the class. You can change them in the Program.cs file under step 2:

    // Security  global specifications
    // minimal burn time for a light in the security timer
    CmdSecurity.MINIMAL_BURN_TIME_sec = 1;    
    // maximal burn time for a light in the security timer          
    CmdSecurity.MAXIMAL_BURN_TIME_sec = 30; 
    // minimal press time to activate security function.             
    CmdSecurity.MINIMAL_PRESS_TIME_ms = 5000; 
    // set the chance a certain I/O will be activated (Chance=1/RANDOM_CHANCE. Evaluated 5-10 times per second).          
    CmdSecurity.RANDOM_CHANCE = 10000;                  		

7. CmdTimedEvents

The CmdTimedEvents allows you to set certain I/O channels at certain moments of the day. You really need a working RTC clock before you can use this class: use the CmdRTC for this (Requires a Fez Connect Shield with Ethernet functionalities!).

Setting up the CmdTimedEvents is easy: first you need to create a helper object of the type TimedEvents. Then you add all the desired switching times to this object, by calling the Add() property. There you can specify the switching time (HH:MM format), the channel to switch, and the switching state (true/false). A true will activate the channel at the given time, a false will do otherwise.

Then you need to define a new CmdTimedEvents object, and pass the newly created TimedEvents object to it. The following example will clear the I/O channel 2 each day at 08:00, and set it at 16:00.

    const int IO_TIMED_OUTPUT = 2;
    TimedEvents myEvents = new TimedEvents();
      myEvents.add("08:00", IO_TIMED_OUTPUT, false);
      myEvents.add("16:00", IO_TIMED_OUTPUT, true);
    new CmdTimedEvents(myEvents);		

8. CmdTimer

CmdStart will start a timed I/O output channel after a button has been pressed. The timing interval can be selected. You can stop the timer earlier by pressing the push button again. Optionally you can also activate the extended mode of the timer. Then you can disable the timer by pushing the button for a few seconds.

The example below shows how you can create a timer that runs for 10 seconds. The extended mode is enabled.

    const int BTN_TIMER1 = 1;
    const int IO_TIMEROUT_1 = 2;
    new CmdTimer(BTN_TIMER1, IO_TIMEROUT_1, 10, true);		

9. CmdStartAll

CmdStartAll will stop all I/O channels after a button has been pressed. You only need to specify the I/O channel of the button.

    const int BTN_START_ALL = 1;
    new CmdStartAll(BTN_START_ALL);

10. CmdStopAll

CmdStartAll will stop all I/O channels after a button has been pressed. You only need to specify the I/O channel of the button.

    const int BTN_STOP_ALL = 1;
    new CmdStartAll(BTN_STOP_ALL);		

11. CmdToggle

CmdToggle toggles a certain I/O output channel if you press the button. Each time you push the button, the output will change from ON-OFF-ON-OFF... Basically it is the most elementary function in a home automation system. You need to specify the I/O channel of the push button, and the I/O of the channel to toggle.

    const int BTN_TOGGLE_1 = 1;
    const int IO_TOGGLE_LIGHT=2;
    new CmdToggle(BTN_TOGGLE_1, IO_TOGGLE_LIGHT);

[Return to the Home Automation main page]

Copyright ©1998-2017 Vanderhaegen Bart - last modified: August 24, 2013