Notification highlighting specific device using logic

Hi!

I have an idea I want to execute in a flow, but cant seem to wrap my head around solving this one:

In my apartment i have several windows, all outfitted with contact sensors. I have made a flow that tells me via a push notification if any of these windows are open when I leave home. So far so good. What I CANT figure out though, is if there is any way to use logic in Homey to tell me which one of the contact sensors are triggering, straight in the push-notification?

Any takers?

Cheers,
Haakon

I did it with a script, which can be started with the condition “Not all contact alarms are turned off”
Flow:

The push messages can send these kind of texts, mentioning the open windows or doors:

Screenshot from 2024-08-22 01-07-46

When all is closed (might be handy when testing):

Screenshot from 2024-08-22 01-07-59



The script, called “deur_raam-nog_open”

// 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: windowText + '\n[Peter Away - window/door Open Notif]'
        },
      });

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

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

return (true);

// Initial script by RonnyW.
1 Like

Wow, this is way beyond my skillset in Homey @Peter_Kawa , thank you for taking the time for such an elaborate post!!

1 Like