# Help with a flow: When raining, notify which doors/windows are open

**URL:** <https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331>\
**Category:** Questions & Help\
**Tags:** flow\
**Created:** [June 11, 2021, 6:57pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331 "2021-06-11T18:57:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpcams](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpcams/32/41095_2.png) [@jpcams](https://community.homey.app/u/jpcams)\
**Post date:** [June 11, 2021, 6:57pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/1 "2021-06-11T18:57:47Z")

</div>

I have several aqara sensors around the house and would like to have a flow to be notified that when it rains to get a notification on Google home (audio) and on the phone which states which doors and windows are open.

Any help appreciated! Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Joka](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@Joka](https://community.homey.app/u/Joka)\
**Post date:** [June 11, 2021, 8:01pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/2 "2021-06-11T20:01:30Z")

</div>

Please don’t get me wrong but you are asking others to do the brainwork for you in advance.

I suggest now that you are able to define your requirements and you know which devices you would like to use, you should develop the basic framework from initial flow ideas and ask specific questions about the problems where you are stuck.

Break the requirement down into individual problems:

which kind of rain detection?  
how to accumulate open aqara sensors? → Here I can give you a solution based on homeyscript.  
sending them to Google home as an audio announcement  
sending them as a phone notification

For each of these problems you will already find a solution in this forum.

---

<div class="post-metadata">

**Author:** ![jpcams](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpcams/32/41095_2.png) [@jpcams](https://community.homey.app/u/jpcams)\
**Post date:** [June 11, 2021, 8:42pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/3 "2021-06-11T20:42:46Z")

</div>

Sorry let me try and put more context.

What I’m struggling with is how to report all sensors with “contact alarm on”.

The only way I see it, would be to create several flows. Though that seems like the long way and I wondered if there was an easier way to get the status from all Aqara’s sensors? Right now I have 15 sensors.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [June 11, 2021, 9:31pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/4 "2021-06-11T21:31:29Z")

</div>

I created a HomeyScript for checking open windows.  
You could do something like this in a flow started with a rain sensor.  
As rain sensor I use a rain sensor board with a aqara window sensor (cables attached at the reed sensor and connected to the rain board.

Here is an example for a script (sorry, only german 😉)

> [@Homey Web App (Soon)](https://community.homey.app/t/homey-web-app-soon/39283/28):
>
> Hi Uwe, HomeyScript ist eigentlich nicht so schwer. Du brauchtst nur JavaScript-Kenntnisse und musst in der Homey-API-Beschreibung wühlen grin Hier mal ein Beispiel. Ich prüfe damit mehrere Fenster und gebe einen Text zurück, der über Alexa ausgegeben wird. Der Flow ist als Favorit gespeichert und kann so direkt über Alexa aufgerufen werden. Die Sktipte kann man als Flow-Bedingung verwenden (true/false-Rückgabe). Viel besser ist aber, dass man auch Flow-Tags erzeugen, im Skript füllen und i…

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [June 12, 2021, 6:55am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/5 "2021-06-12T06:55:23Z")

</div>

Have you looked at the group app? That allows you to add multiple devices into one device.

Also you could add all of the rain sensors in to one zone and use the zone is active card

---

<div class="post-metadata">

**Author:** ![jpcams](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpcams/32/41095_2.png) [@jpcams](https://community.homey.app/u/jpcams)\
**Post date:** [June 12, 2021, 8:04am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/6 "2021-06-12T08:04:39Z")

</div>

Yeah I checked this app, but what I don’t get is how to report the individual sensors that are on, so I don’t have to check each one individually.

I have;

If group active

And Raining  
And schedule is between 9:00 - 23:00

- I don’t want a Google home announcement after I’m asleep.

Then…

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [June 12, 2021, 8:10am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/7 "2021-06-12T08:10:31Z")

</div>

If you want to check each window sensor individual, you will need a flow for each sensor.  
You yould use HomeScript to do the checks and build a text with each window and then make a TTS output. That needs some JavaScript codings, but the script (linked in my answer above) is easy to unterstand. This script can be used in a flow condition (AND part) and the text is returned an flow tag for use in THEN part.

---

<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:** [June 12, 2021, 2:35pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/8 "2021-06-12T14:35:48Z")

</div>

Nice script @RonnyW  
But idk if @jpcams is ready for that at this point?

JP, a quite simple approach can be something like this. It only requires adding all of your sensors to the alert message, but it works. Maybe this gets you going to more advanced flows (and scripts)

and for TTS during daytime:

 ![Screenshot_20210612-161300_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/4/1470067dba2067dfffe29972ecdcb55fee44d2e4.jpeg)

---

<div class="post-metadata">

**Author:** ![jpcams](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpcams/32/41095_2.png) [@jpcams](https://community.homey.app/u/jpcams)\
**Post date:** [June 19, 2021, 6:55am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/9 "2021-06-19T06:55:05Z")

</div>

I finally sat down and looked at your script. Thanks a lot! At first I was a bit resistant to the idea as I thought since I’m not a dev, I would spend an obscene amount of time trying to decipher your hieroglyphics! 🙂 Glad I was wrong and thanks again for sharing this script.

I will share my version of your script below in case it helps anyone else who is looking for a similar solution:

```auto
let devices = await Homey.devices.getDevices();
let windowText = "";
let currentText = "";
let logText = "";
let windowOpen = false;
_.some(devices, device => {
if(device.class == 'sensor')
{
if( device.capabilitiesObj &&
device.capabilitiesObj.alarm_contact &&
device.capabilitiesObj.alarm_contact.value )
{
currentText = "";
if( device.name == "Living room sliding door")
currentText = "Living Room";
if( device.name == "Kitchen Window Sensor")
currentText = "Kitchen";
if( device.name == "Office Window Sensor")
currentText = "Office";
if( device.name == "Kid1 Window Sensor")
currentText = "Kid1 room";
if( device.name == "Kid2 Window Sensor")
currentText = "Kid2 room";
if( device.name == "Bedroom Window Sensor")
currentText = "Bedroom";
if( device.name == "Tall bedroom Window Sensor")
currentText = "Tall bedroom window";
if(currentText != ""){
windowOpen = true;
if(windowText=="")
windowText = currentText;
else
windowText = windowText + ", " + currentText;
}
}
}
});
if(windowOpen == true)
windowText = "Window open: " + windowText;
else
windowText = "All good";
console.log(windowText);
await tag("windowText", windowText );
return windowOpen;

```

---

<div class="post-metadata">

**Author:** ![Miroslav\_Gluch](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/miroslav_gluch/32/34842_2.png) [@Miroslav\_Gluch](https://community.homey.app/u/Miroslav_Gluch)\
**Post date:** [August 8, 2021, 4:58pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/10 "2021-08-08T16:58:28Z")

</div>

It’s great. How do I simply save the result of the script in a variable so I can send myself a notification?

---

<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:** [August 8, 2021, 5:12pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/11 "2021-08-08T17:12:49Z")

</div>

The variables are created and filled by the script already.  
First, make sure to run the script minimal 1 time in HomeyScript editor, so the variables are getting created and become available and findable from the flow editor.  
Flow:  
You can simply run the script from a AND card (go to Homeyscript in the list, and then select the script), and as action, create a notification card and select the variable [windowText], which is grouped under “Homeyscript”.

 ![Screenshot_20210808-191545_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/f/7fa06fc27715c70bb87e8cf419d66e7b043cbc94.jpeg)

Screenshot of the action card while the “share a flow” doesn’t display the variable:

 ![Screenshot_20210808-191329_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/a/4ad63d7786f5a7d7b1b1afda335e3411486a81f4.jpeg)

Result pushmessage (it reports an open door and window):

 ![Screenshot_20210808-192750_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/4/e4033df804e0023cd938526eedb6eddb3ce5b5b0.jpeg)

---

<div class="post-metadata">

**Author:** ![Miroslav\_Gluch](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/miroslav_gluch/32/34842_2.png) [@Miroslav\_Gluch](https://community.homey.app/u/Miroslav_Gluch)\
**Post date:** [August 8, 2021, 6:48pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/12 "2021-08-08T18:48:46Z")

</div>

Thanks a lot! I didn’t know exactly how it worked. Now I’m happy 🙂

---

<div class="post-metadata">

**Author:** ![timvdhoorn](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/timvdhoorn/32/55746_2.png) [@timvdhoorn](https://community.homey.app/u/timvdhoorn)\
**Post date:** [June 6, 2022, 4:37pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/13 "2022-06-06T16:37:21Z")

</div>

Sorry to reopen this thread, but the script doesn’t work for me.  
I have the following script;

```auto
// script deur_raam-nog_open.js
//
let devices = await Homey.devices.getDevices();
let windowText = "";
let currentText = "";
let logText = "";
let windowOpen = false;
_.some(devices, device => {
if(device.class == 'sensor')
 {
 if( device.capabilitiesObj &&
 device.capabilitiesObj.alarm_contact &&
 device.capabilitiesObj.alarm_contact.value )
   {
   currentText = "";
   // Vul hier al je contact sensors in, device.name == "Exacte sensornaam"
   // currenText = "Sensornaam"
   if( device.name == "Raam rechts-Wk")
   currentText = "Raam rechts-Wk";
   if( device.name == "Balkondeur-Ke")
   currentText = "Balkondeur-Ke";
     if(currentText != ""){
     windowOpen = true;
     if(windowText=="")
     windowText = currentText;
     else
     windowText = windowText + ", " + currentText;
     }
   }
 }
});
if(windowOpen == true)
windowText = "De volgende deuren of ramen staan nog open: " + windowText;
else
windowText = "Alle deuren en ramen zijn dicht";
console.log(windowText);
await tag("door_windowText", windowText );
return windowOpen;

```

But if I open a window and test the script, it says that all doors and windows are closed. Could someone maybe help?  
Thanks!

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [June 6, 2022, 7:24pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/14 "2022-06-06T19:24:36Z")

</div>

> [@timvdhoorn](#):
>
> ` if( device.name == "Raam rechts-Wk")`

Have you changed the device names in the script to the names of your sensors?

---

<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:** [June 6, 2022, 10:46pm UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/15 "2022-06-06T22:46:24Z")

</div>

And share your flow too, please.

---

<div class="post-metadata">

**Author:** ![timvdhoorn](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/timvdhoorn/32/55746_2.png) [@timvdhoorn](https://community.homey.app/u/timvdhoorn)\
**Post date:** [June 7, 2022, 6:47am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/16 "2022-06-07T06:47:25Z")

</div>

Thank you for the replies.  
The devices:  
 ![Screenshot 2022-06-07 at 08.45.42](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/0/d016b441096973f805c7de2652a8d1711e96b6c7.png)  
 ![Screenshot 2022-06-07 at 08.46.55](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/0/30f179c80f0cf7127695945657f3e596d26d2ef2.png)

The flow:

 ![Screenshot 2022-06-07 at 08.47.48](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/a/aa3ae3dde44af80caa6ad3238a4c9c28b6227ed9.jpeg)

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [June 7, 2022, 8:43am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/17 "2022-06-07T08:43:38Z")

</div>

Did you test the flow? What is the first condition? Is it true in your case that the flow is processed?  
And keep in mind: The script is returning a bool result. So your flow will continue to the Then part only if a window is open. If you would like a message if all windows are closed, you need a push messa in the Else part like “all right, alls is closed” 😉

---

<div class="post-metadata">

**Author:** ![timvdhoorn](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/timvdhoorn/32/55746_2.png) [@timvdhoorn](https://community.homey.app/u/timvdhoorn)\
**Post date:** [June 7, 2022, 11:03am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/18 "2022-06-07T11:03:06Z")

</div>

This is what happens when I run the flow with a window open.

 ![Screenshot 2022-06-07 at 12.59.47](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/8/c858df27cca6ed45c680c08feb5205d23b1aa423.jpeg)

The first AND is asking if not all the contact alarms are off. So that part is saying that there are contact alarms open. Then it stops at the Homeyscript part.  
If I run the script with a debug line, it says that all the windows and doors are closed, but this isn’t true. So the script returns false but it should be outputting true.

 ![Screenshot 2022-06-07 at 13.01.47](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/c/3c9842ac35971572fea6e61e9675f3721f7d23c9.jpeg)

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [June 7, 2022, 11:20am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/19 "2022-06-07T11:20:14Z")

</div>

Is the opened sensor included in the script?  
The script ich checking only steh sensors which are defined in the IF statements (2 in your case). Perhaps another sensor is active and is not checked in the script?  
That’s for a filtered check. In most cases you don’t want to check all sensors if they are used inside for other purposes. Inside the IF statement, a “short” name is provides to keep the output in the pushmessage short, because there are all open windows listed.

---

<div class="post-metadata">

**Author:** ![timvdhoorn](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/timvdhoorn/32/55746_2.png) [@timvdhoorn](https://community.homey.app/u/timvdhoorn)\
**Post date:** [June 7, 2022, 11:24am UTC](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331/20 "2022-06-07T11:24:27Z")

</div>

Yes, the open sensor is included in the script.  
Its the Balkondeur-Ke sensor.

![Screenshot 2022-06-07 at 13.22.29](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/f/ff98a4398f2d4e300fff6af1d2c65467fa9877d1.png)  
and alarm is true

 ![Screenshot 2022-06-07 at 13.23.59](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/e/1ebb4f4b7394a72c0854dd6a22b67c05ce59b70d.png)

[Next page](https://community.homey.app/t/help-with-a-flow-when-raining-notify-which-doors-windows-are-open/48331.md?page=2)
