Report any open doors/windows

Hi Marcel,

I use this Homeyscript script for that. It sends a timeline report, so you just have to call this script in a flow:
(I use the same script for rain/snow/storm alerts)

// Check if certain doors or windows is open?

let devices = await Homey.devices.getDevices();
let windowText = "";
let currentText = "";
let logText = "";
let windowOpen = false;
_.some(devices, device => 
{
if ( device.class == 'sensor' ) 
// device.class is found at https://tools.developer.homey.app/tools/devices
  {
  if( device.capabilitiesObj &&
  device.capabilitiesObj.alarm_contact &&
  device.capabilitiesObj.alarm_contact.value )
    {
    currentText = "";
    // to compare and see if there is no typing error
    console.log(`- Open door/window script check: ${device.name} (Zone: ${device.zoneName}), [device.class: ${device.class}, device.capabilities: ${device.capabilities}]`); 
    
      if(device.name != ""){
      windowOpen = true;
      if(windowText=="")
      //windowText = device.name + "\t(" + device.zoneName + ")";
      windowText = device.name + "\t(" + device.zoneName + ")";
      
      else
      windowText = windowText + "\n" + device.name + "\t(" + device.zoneName + ")";
      }
    }
  }
});

if(windowOpen == true)
windowText = "\nDe volgende ramen of deuren staan nog open:\n" + windowText + "\n";
else
// comment this out if you don't want a msg when all's fine:
windowText = "Alle deuren en ramen zijn dicht";

Homey.flow.runFlowCardAction({
        uri: 'homey:manager:notifications',
        id: 'create_notification',
        args: {
          text: windowText
        },
      });

//just to check
console.log("\nOutput:\n", windowText);

// Create / update HomeyScript variabele
await tag("door_windowText", windowText);

return (true);

// Initial script by RonnyW.

( Credits to @RonnyW !)

4 Likes