Dynamic display of devices

Read this thread, please:
https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/11?u=peter_kawa

Here’s the script I use:

// 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: \nName: ${device.name} \nZone: ${device.zone} \n(ZoneName: ${device.zoneName}) \n[device.class: ${device.class} \ndevice.capabilities: ${device.capabilities}]`); 

      if(device.name != ""){
      windowOpen = true;
      if(windowText=="")
      windowText = device.name + "\t(Zone: " + device.zoneName + ")";
      
      else
      windowText = windowText + "\n" + device.name + "\t(Zone: " + device.zoneName + ")";
      }
    }
  }
});

if(windowOpen == true)
windowText = "\nThese windows/doors are still open:\n" + windowText + "\n";
else
// comment this out if you don't want a msg when all's fine:
windowText = "All windows & doors are closed.";

Homey.flow.runFlowCardAction({
        uri: 'homey:manager:notifications',
        id: 'create_notification',
        args: {
          text: String(windowText) + '\n[Peter Away - window/door Open Notif]'
        },
      });

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

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

return (true);

// Initial script by RonnyW.


The script is called with a flow like this:


Maybe this indicator is useful as well


Check out this post for the flow and howto:

1 Like