Khmm
With:
// 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;