HowTo: FHEM: Check if all windows are closed when leaving

As I’m always worried if all my windows are closed when I leave my house, I decided to let FHEM check if they are closed.
My windows are monitored with MAX! Shutter contacts, which are compatible with FHEM, so it can always see if they are open or closed.

To do the job, I wrote a script which sends me a push-message, stating if all windows are closed and if not, telling me which windows are open. In FHEM you put that script into a notify, with this notify we can then trigger the script whenever we want. For your setup you need to change the device names and add/delete devices in the script. Things you have to change are in bold and brackets:

define checkWindows notify checkWindows {
 my $winKitchen=Value("[Name of the Shutter contact in the Kitchen]");
 my $winSleepingroom=Value("[Name of the Shutter contact in the Sleepingroom]");
 my $winLivingroom=Value("[Name of the Shutter contact in the Livingroom]");
 my $winBath=Value("[Name of the Shutter contact in the Bathingroom]");
 if (($winKitchen ne "closed") || ($winSleepingroom ne "closed") || ($winLivingroom ne "closed") || ($winBath ne "closed")) {
  my $openWindows="";
  if ($winKitchen ne "closed") { $openWindows="Kitchen "; }
  if ($winSleepingroom ne "closed") { $openWindows=$openWindows . "Sleepingroom "; }
  if ($winLivingroom ne "closed") { $openWindows=$openWindows . "Livingroom "; }
  if ($winBath ne "closed") { $openWindows=$openWindows . "Bathingroom"; }
  fhem("set push msg 'ATTENTION: Window(s) open!' '" . $openWindows . "' '[Push Device]' 1 ''");
 } else {
  fhem("set push msg 'SAVE' 'All windows are closed.' '[Push Device]' -1 ''");

After we created the notify we need to trigger the script when we leave. To check if you are at home or not, we can use presence and check the bluetooth address of our smartphone, because we always take our smartphone with us :). Just fill in the bluetooth address of your smartphone instead of the bold text:

define Smartphone PRESENCE local-bluetooth [Bluetooth address of your Smartphone]
attr Smartphone absenceThreshold 2

For example:

define Smartphone PRESENCE local-bluetooth 01:23:45:67:89:AB
attr Smartphone absenceThreshold 2

The absenceThreshold set to 2 tells FHEM to check twice before saying that your smartphone is away.
Now we need to trigger our checkWindows script as soon as our smartphone goes absent with a DOIF:

define di_WindowChecker DOIF ([Smartphone] eq "absent") (trigger checkWindows)

That’s it! Now you always get a message telling you the state of your windows when leaving!

Simply different!