Why does the ifdef block not get executed? If I put all the code in the else part it works flawlessly. I thought#defines are global scope and are visible to all includes if they are defined before they are referenced in the code.
An "include" means that the compiler inserts that file at that location. You can include any file anywhere in the code.
The Arduino pre-processor might interfere with it.
Is that include in the first main *.ino file ? Or do you use extra tabs with extra files in your project and is that include in one of the other files ? In a *.ino file or a *.cpp or *.h file ? Or is that include located in an other library ?
Can you provide a small test sketch ? Where is the SmartHouse library located ?
To avoid this, some prefer to set a define to 0 or 1. That gives an extra option to check if it is defined at all.
KilianB:
Why does the ifdef block does not get executed?
Pre-processor directives aren't "executed", they simply define what code is compiled (and executed at runtime).
KilianB:
I thought that#defines are global scope and are visible to all includes if they are defined before they are referenced in the code.
That is incorrect. All .cpp files are compiled separately. If one doesn't have the #define directive (either directly or through an #include), then it won't be defined.
The best solution I've found for this is to move the code which is dependent on the #define from the .cpp to the .h file.
Other options would be to set the define via a -D compiler flag or to put it in a header file which is included by the .cpp file. Although both are possible, the Arduino IDE does not make either one very simple to accomplish.