# The flow with i million thenssss

**URL:** <https://community.homey.app/t/the-flow-with-i-million-thenssss/65004>\
**Category:** Flows\
**Tags:** flow\
**Created:** [June 22, 2022, 9:10pm UTC](https://community.homey.app/t/the-flow-with-i-million-thenssss/65004 "2022-06-22T21:10:56Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Cuprum](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/cuprum/32/41409_2.png) [@Cuprum](https://community.homey.app/u/Cuprum)\
**Post date:** [July 7, 2022, 7:35am UTC](https://community.homey.app/t/the-flow-with-i-million-thenssss/65004/11 "2022-07-07T07:35:00Z")

</div>

Khmm 😉

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/9/19978f87b5474a4bf198db19a78fae492dec3026.png)  
With:

```auto
// Get all devices
const devices = await Homey.devices.getDevices();

// Initiate the message string as empty
let openrooms = [];

// The counter of open windows
let count = 0;

// Text message, if it required
let message = "";;

// Regexp to find out all the interesting windows 
const regexWindow = new RegExp('^window', 'i');

// Loop over all devices
for (const device of Object.values(devices)) {
  if ( device.class == 'sensor' || device.virtualClass == 'sensor'){ // The device is a sensor

    if ( regexWindow.test(device.name) ){ // Device name starts with "window..."
        // Remember there the 'device.id' value and use it in quicker script to loop over only the interesting sensors
        if ( device.capabilitiesObj.alarm_contact.value){ // So, was the contact alarm there
			count ++;
			if ( ! (openrooms.includes(device.zoneName)) ){ openrooms.push(device.zoneName); }
			if ( openrooms.length > 8 ) { return "More than "+count+" windows in "+openrooms.length+" rooms are open!"; }			
        }
    }  
  }
}  

if ( count === 0 ) { return "All windows closed"; }
if ( count === 1 ) { return "The window in "+openrooms[0]+" is opened"; }

message = "There are "+count+" windows in ";

openrooms.forEach(room => message += room+" ");
message += " opened";

return message;

```

---

_[View the full topic](https://community.homey.app/t/the-flow-with-i-million-thenssss/65004)._
