# Report any open doors/windows

**URL:** <https://community.homey.app/t/report-any-open-doors-windows/77972>\
**Category:** Flows\
**Tags:** flow\
**Created:** [March 18, 2023, 11:56am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972 "2023-03-18T11:56:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maarten\_Verbunt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/maarten_verbunt/32/9447_2.png) [@Maarten\_Verbunt](https://community.homey.app/u/Maarten_Verbunt)\
**Post date:** [March 18, 2023, 11:56am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/1 "2023-03-18T11:56:06Z")

</div>

I am trying to create a flow that will tell me if there are any open door or windows when I activate my alarm, and I want to know exactly which one(s) are still open. I have created a flow for only three contact sensors, but this wil rapidly become a mess if I want to add 5 more sensors. Is there a better way of doing this?

 ![Open doors report](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/2/c2fd351ee74cc6ca34dd15ecb64288f0ad9700d1.png)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [March 18, 2023, 4:36pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/2 "2023-03-18T16:36:24Z")

</div>

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)

```auto
// 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 !)

- Flow:  

- Paste the script in the Homeyscript THEN card “Run code”

---

<div class="post-metadata">

**Author:** ![Jacques\_Derks](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jacques_derks/32/12699_2.png) [@Jacques\_Derks](https://community.homey.app/u/Jacques_Derks)\
**Post date:** [March 19, 2023, 7:06am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/3 "2023-03-19T07:06:41Z")

</div>

Zojuist de flow aangemaakt. Werkt perfect. Bedankt voor de tip en het script.

---

<div class="post-metadata">

**Author:** ![Hannes85](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@Hannes85](https://community.homey.app/u/Hannes85)\
**Post date:** [March 19, 2023, 9:58am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/4 "2023-03-19T09:58:47Z")

</div>

Nice script! Although on the new Homey it doesn’t seem to recognize Device.Zonename. Not sure how to retrieve the correct zone name on HP2023?

Ps; I can get the zone as a guid by using device.zone but that’s not very helpful

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [March 19, 2023, 3:34pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/5 "2023-03-19T15:34:32Z")

</div>

> [@Hannes85](#):
>
> Device.Zonename

make sure to use `device.zoneName`  
It’s case-sensitive

@Homeyscript tab: When you type `device.z` in the line below, like the screenshot, what’s in the dropdown which appears? You can enter every one of them in this line, and look which one returns the correct zone name:

 ![Screenshot from 2023-03-19 14-29-22](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/2/32d96d66e0fc9ccdb8dc35a32e7d06d3aef53231.png)

---

<div class="post-metadata">

**Author:** ![DaneedeKruyff](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/daneedekruyff/32/964_2.png) [@DaneedeKruyff](https://community.homey.app/u/DaneedeKruyff)\
**Post date:** [March 19, 2023, 3:54pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/6 "2023-03-19T15:54:59Z")

</div>

device.zoneName has been removed from a device, it’s back to just the zoneId. So you’ll need to get all zones, and match the zoneId to retrieve the zonename.

Like this in an app: [com.uc.heimdall/app.js at d1c329d6ed5f79907a66c52bc318ca0a2b013bda · daneedk/com.uc.heimdall · GitHub](https://github.com/daneedk/com.uc.heimdall/blob/d1c329d6ed5f79907a66c52bc318ca0a2b013bda/app.js#L562)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [March 19, 2023, 4:04pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/7 "2023-03-19T16:04:46Z")

</div>

Thanks Danee!

---

<div class="post-metadata">

**Author:** ![Hannes85](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@Hannes85](https://community.homey.app/u/Hannes85)\
**Post date:** [March 19, 2023, 5:11pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/8 "2023-03-19T17:11:39Z")

</div>

Perfect, this makes sense. Thanks Danee 🙂 !

---

<div class="post-metadata">

**Author:** ![Maarten\_Verbunt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/maarten_verbunt/32/9447_2.png) [@Maarten\_Verbunt](https://community.homey.app/u/Maarten_Verbunt)\
**Post date:** [March 20, 2023, 8:38am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/9 "2023-03-20T08:38:08Z")

</div>

Thank you so much for your quick reply. I am not familiar with coding so it will take me some time to figure this out and understand how this all works. But I was able to get this to work with your instructions at hand. Awsome!

---

<div class="post-metadata">

**Author:** ![Hannes85](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@Hannes85](https://community.homey.app/u/Hannes85)\
**Post date:** [March 20, 2023, 9:39am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/10 "2023-03-20T09:39:56Z")

</div>

1. Install homeyscript
2. Copy/paste the code into a new script.
3. Use a tag in the “then” column to grab output and do with it as you please

No need to understand the code in this case 🙂

Unless you want to get rid of the “zoneName” part that’s not working anyway. Then you’d need to comment out parts on line 24 and 27;

```
  windowText = device.name // + "\t(" + device.zoneName + ")";
  
  else
  windowText = windowText + "\n" + device.name // + "\t(" + device.zoneName + ")";

```

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [March 20, 2023, 1:37pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/11 "2023-03-20T13:37:26Z")

</div>

> [@Hannes85](#):
>
> the “zoneName” part that’s not working anyway

(STILL) Working fine on Pro 201x models 🙃

> [@Hannes85](#):
>
> ```auto
> windowText = device.name // + "\t(" + device.zoneName + ")";
>   
> else
> windowText = windowText + "\n" + device.name // + "\t(" + device.zoneName + ")";
> 
> ```

Hmmm, shouldn’t that be like:

```auto
//windowText = device.name + "\t(" + device.zoneName + ")";
windowText = device.name;  
  else
  //windowText = windowText + "\n" + device.name + "\t(" + device.zoneName + ")";
  windowText = windowText + "\n" + device.name;

```

[/quote]

```auto

```

---

<div class="post-metadata">

**Author:** ![DaneedeKruyff](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/daneedekruyff/32/964_2.png) [@DaneedeKruyff](https://community.homey.app/u/DaneedeKruyff)\
**Post date:** [March 20, 2023, 1:42pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/12 "2023-03-20T13:42:01Z")

</div>

Just wait till you get firmware 10.x.x 🕶

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [March 20, 2023, 1:42pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/13 "2023-03-20T13:42:27Z")

</div>

Ah hehe, didn’t count on that to happen 🤪

---

<div class="post-metadata">

**Author:** ![Hannes85](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@Hannes85](https://community.homey.app/u/Hannes85)\
**Post date:** [March 20, 2023, 1:57pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/14 "2023-03-20T13:57:41Z")

</div>

patato potata 🙂

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [March 20, 2023, 2:06pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/15 "2023-03-20T14:06:49Z")

</div>

Well no, with your way, the ending " `;`" sign gets lost when you comment out halfway the line 😉  
(regardless if it is truly needed or not 🤪 )

---

<div class="post-metadata">

**Author:** ![Hannes85](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@Hannes85](https://community.homey.app/u/Hannes85)\
**Post date:** [March 20, 2023, 2:28pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/16 "2023-03-20T14:28:19Z")

</div>

Nerd 😘!

ASI fixes it so; “potato, potata” still stands firm 🙂

---

<div class="post-metadata">

**Author:** ![Marc\_Jurriens](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marc_jurriens/32/11951_2.png) [@Marc\_Jurriens](https://community.homey.app/u/Marc_Jurriens)\
**Post date:** [March 25, 2023, 3:49pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/17 "2023-03-25T15:49:02Z")

</div>

You could do something with variables, create a seperate flow for every door / window just to monitor open/close status.

In that flow set a boolean variable “any window open” and set it to open if a window is open and set it to closed it a window is closed and all other windows are also closed.

Then in the flow you wanted to create you only have to monitor that variable.

---

<div class="post-metadata">

**Author:** ![Davy\_Manderveld](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/davy_manderveld/32/31337_2.png) [@Davy\_Manderveld](https://community.homey.app/u/Davy_Manderveld)\
**Post date:** [March 31, 2023, 12:57pm UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/18 "2023-03-31T12:57:04Z")

</div>

Use the Heimdall app

---

<div class="post-metadata">

**Author:** ![Maarten\_Verbunt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/maarten_verbunt/32/9447_2.png) [@Maarten\_Verbunt](https://community.homey.app/u/Maarten_Verbunt)\
**Post date:** [April 2, 2023, 10:59am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/19 "2023-04-02T10:59:13Z")

</div>

I am not willing to give any app full control of my homey, no matter how helpfull those apps might be. Esspecially when there are alternative ways of reaching my goals. I am sure I would enjoy the Heimdall app as it gets great reviews and it adds a lot to the Homey system, but for now I am not ready to hand over full control to any app.

---

<div class="post-metadata">

**Author:** ![Hannes85](https://avatars.discourse-cdn.com/v4/letter/h/e79b87/32.png) [@Hannes85](https://community.homey.app/u/Hannes85)\
**Post date:** [April 2, 2023, 11:13am UTC](https://community.homey.app/t/report-any-open-doors-windows/77972/20 "2023-04-02T11:13:44Z")

</div>

It also cannot do what you’ve been looking for (the heimdall app includes all sensors, not just contact sensors) so I wouldn’t spend any energy on it. Just use the script.

[Next page](https://community.homey.app/t/report-any-open-doors-windows/77972.md?page=2)
