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

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!

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.

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.

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 :wink:)

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

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…

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.

2 Likes

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:

1 Like

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! :slight_smile: 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:

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;
5 Likes

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

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 of the action card while the “share a flow” doesn’t display the variable:

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

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

1 Like

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

// 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!

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

And share your flow too, please.

Thank you for the replies.
The devices:
Screenshot 2022-06-07 at 08.45.42
Screenshot 2022-06-07 at 08.46.55

The flow:


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” :wink:

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

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.

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.

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

Screenshot 2022-06-07 at 13.22.29
and alarm is true