Logical module device for accurate darkness information

sky-583724_640If you have several presence sensors in your KNX installation,  you can use them all to get a really accurate “Is is dark in my home?” information. This can be used for instance to switch off/on the orientation LEDs of push buttons, or forbid/allow lights switch off/on.

What  you need for that is an Arduino and a TPUART! Import the KnxDevice library in Arduino IDE then copy-paste the below sketch.

The sketch bases on average luminosity value provided by 3 presence detector devices. It is assumed the values are emitted periodically, every 2 minutes for instance (period can be configured with ETS tool in devices configuration). Note that you can easily increase the number of used devices if wished. An hysteris algorithm is used to prevent unwanted rapid switching.

A B1 switch group object (adress 3.0.4 in the sketch) represents the “Is it Dark?” information, and allows to broadcast the information to the whole KNX installation. Configure in ETS the devices that will use this new group object, and that’s it!

#include <KnxDevice.h> // version v0.2 or later 

// Definition of the Communication Objects attached to the device
KnxComObject KnxDevice::_comObjectsList[] = {
/* Index 0: luminosity in corridor :  */ KnxComObject(G_ADDR(3,0,0), KNX_DPT_9_004  /* F16 Value */ , COM_OBJ_LOGIC_IN_INIT) ,
/* Index 1: luminosity in hall :      */ KnxComObject(G_ADDR(3,0,2), KNX_DPT_9_004  /* F16 Value */ , COM_OBJ_LOGIC_IN_INIT) ,
/* Index 2: luminosity in scullery :  */ KnxComObject(G_ADDR(3,0,3), KNX_DPT_9_004  /* F16 Value */ , COM_OBJ_LOGIC_IN_INIT) ,
/* Index 3: the IsItDark com object : */ KnxComObject(G_ADDR(3,0,4),  KNX_DPT_1_001 /* B1 Switch */ , COM_OBJ_SENSOR) ,
const byte KnxDevice::_comObjectsNb = sizeof(_comObjectsList) / sizeof(KnxComObject);

boolean measureUpdated = false; // set to true after each luminosity value update

void UpdateIsItDarkObject() { // Function to update IsItDark com object
  boolean isItDark = Knx.read(3); // NB : KNX library initializes com objects to 0.
                                  // So at init time it's not dark!
  unsigned int measure, sum = 0;
  for (byte i=0; i<3;i++) { Knx.read(i, measure); sum += measure;} // we sum measures
  // hysteris algorithm, thresholds are 400 lux and 250 lux average values
  if ((isItDark)&& (sum > 1200)) Knx.write(3, false); 
  if((!isItDark)&& (sum < 750)) Knx.write(3, true);

// Callback function to handle com objects updates
void knxEvents(byte index) {
  switch(index) {
    case 0 ... 2 : measureUpdated = true; // a presence detector has sent a new measure
  default : break;

void setup(){
  Knx.begin(Serial, P_ADDR(1,1,1));

void loop(){ 
  if(measureUpdated) { // a presence detector has sent a new luminosity measure
    measureUpdated = false;
    UpdateIsItDarkObject(); // so we update "IsItDark" Object
This entry was posted in Realisations. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>