# Missing "everybody is asleep" condition

**URL:** <https://community.homey.app/t/missing-everybody-is-asleep-condition/31880>\
**Category:** Questions & Help\
**Created:** [June 30, 2020, 9:46pm UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880 "2020-06-30T21:46:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardovl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ricardovl/32/16441_2.png) [@ricardovl](https://community.homey.app/u/ricardovl)\
**Post date:** [June 30, 2020, 9:46pm UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/1 "2020-06-30T21:46:03Z")

</div>

Hello,

I’ve a card on the “and” column for “nobody is asleep”  
But I don’t have a card everybody is asleep  
And I would like to use it for an alarm.

I think I can reacte something myself by setting a variable on the last person is asleep event. But I think there must be a better/build in method.

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [July 1, 2020, 4:45am UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/2 "2020-07-01T04:45:53Z")

</div>

Pick the “nobody is asleep” and card, and click the “invert” checkbox inside the card.

---

<div class="post-metadata">

**Author:** ![ricardovl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ricardovl/32/16441_2.png) [@ricardovl](https://community.homey.app/u/ricardovl)\
**Post date:** [July 1, 2020, 9:36am UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/3 "2020-07-01T09:36:51Z")

</div>

This results in anyone is asleep.

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [July 1, 2020, 10:40am UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/4 "2020-07-01T10:40:00Z")

</div>

Hmm, you are right, then I guess that is a [feature request](http://go.athom.com/request-homey-feature), and until then, just add all your members with “someone specific is asleep” in the AND column, just a little bit cumbersome if you have a lot of members though.

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [July 1, 2020, 5:05pm UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/5 "2020-07-01T17:05:19Z")

</div>

> [@ricardovl](#):
>
> anyone

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/d/dd6996c26a9022badd1305d1e7fe283664b433af.png)

In Dutch it’s also **iedereen** (everyone) so probably it works!

---

<div class="post-metadata">

**Author:** ![Tycho](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tycho/32/16864_2.png) [@Tycho](https://community.homey.app/u/Tycho)\
**Post date:** [July 1, 2020, 7:47pm UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/6 "2020-07-01T19:47:24Z")

</div>

I had the same requirement and I only wanted to consider people who are currently at home. So I wrote the following script. Just copy paste it onto HomeyScript and you can use it. You cannot trigger a flow on this script, but if you trigger on “someone goes to sleep” and then run this, you get the same result.

> // returns true if everyone who is at home, is asleep  
> let allUsers = await Homey.users.getUsers();  
> let result = true;  
> \_.forEach(allUsers, user =\> {  
> if(user.present == true && user.asleep == false){  
> //there is someone at home who is awake  
> result = false;  
> }  
> });  
> return result;

---

<div class="post-metadata">

**Author:** ![Peter\_de\_Vos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_de_vos/32/151925_2.png) [@Peter\_de\_Vos](https://community.homey.app/u/Peter_de_Vos)\
**Post date:** [July 2, 2020, 10:18am UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/7 "2020-07-02T10:18:06Z")

</div>

Tested it. It doesn’t. But it quite simple to check if everybody is asleep with the card ‘a specific person is asleep’ and ad al family members in the and section

---

<div class="post-metadata">

**Author:** ![JeroenD](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroend/32/14297_2.png) [@JeroenD](https://community.homey.app/u/JeroenD)\
**Post date:** [June 3, 2023, 8:58am UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/8 "2023-06-03T08:58:48Z")

</div>

I know I react on an old topic but I think it’s better than start a new one.

The script above has helpt me so much. I was looking for it a long time.  
I’m also looking for a script that returns true if the first person thats wake up and is home.  
But if the second person wake up and there’s already someone awake and present it has to give a false. Can someone make that?

---

<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 3, 2023, 3:01pm UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/9 "2023-06-03T15:01:38Z")

</div>

> [@JeroenD](#):
>
> script that returns true if the first person thats wake up and is home.  
> But if the second person wake up and there’s already someone awake and present it has to give a false.

I thought of editing that script, and add a counter for the number of _not sleeping_ persons

### Code:

```auto
// When 1st person @home wakes up = true; when person2 @home wakes up: false.
let allUsers = await Homey.users.getUsers();
let result = true;
let count = 0;

_.forEach(allUsers, user => {
if(user.present == true && user.asleep == false) {
  // for each user who is not asleep, add 1 to the counter value
  count++;
  // if counter is higher than 1 (person), result = false
  if( count > 1 ) { 
  result = false
  };
}
});
return result;

```

### Flow:

 ![Screenshot from 2023-06-03 16-50-10](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/a/fa6df2268ddd8c0da212d0cbfb302eba4a1bd136.png)

#### When the result = false, but you also want to know who, and if he/she/it/them was the 2nd, 3rd, 4th person to wake up:

### Code:

```auto
// When 1st person @home wakes up = true; when person2 @home wakes up: false.
let allUsers = await Homey.users.getUsers();
let result = true;
let count = 0;

_.forEach(allUsers, user => {
if(user.present == true && user.asleep == false) {
  // for each user who is not asleep, add 1 to the counter value
  count++;
  // if counter is higher than 1 (person), result = false
  if( count > 1 ) { 
  //Show if it was the 2nd, the 3rd, 4th (and so forth) person to get up
  result = "No. Person #" + count + " got up"
  }
}
});
return String(result);

```

### Flow:

 ![Screenshot from 2023-06-03 16-55-47](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/d/9de7be60ffe19f11349c0a5c1ff1a55a8c104461.png)

### Result when false:

 ![Screenshot from 2023-06-03 16-54-48](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/1/516c8372a9bd251d1dc2a18133ddbff742187839.png)

---

<div class="post-metadata">

**Author:** ![JeroenD](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroend/32/14297_2.png) [@JeroenD](https://community.homey.app/u/JeroenD)\
**Post date:** [June 3, 2023, 6:47pm UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/10 "2023-06-03T18:47:24Z")

</div>

Hi Peter,  
Thank you very much for helping me out!

---

<div class="post-metadata">

**Author:** ![JeroenD](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroend/32/14297_2.png) [@JeroenD](https://community.homey.app/u/JeroenD)\
**Post date:** [June 3, 2023, 7:23pm UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/11 "2023-06-03T19:23:40Z")

</div>

@Peter_Kawa At the second part I get a message “message”:“Invalid token type: boolean. Expected: Boolean”  
Have I done something wrong?

---

<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 4, 2023, 12:46am UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/12 "2023-06-04T00:46:43Z")

</div>

YW!  
Can you show me a screenshot of the card and error?

---

<div class="post-metadata">

**Author:** ![JeroenD](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroend/32/14297_2.png) [@JeroenD](https://community.homey.app/u/JeroenD)\
**Post date:** [June 4, 2023, 4:51am UTC](https://community.homey.app/t/missing-everybody-is-asleep-condition/31880/13 "2023-06-04T04:51:04Z")

</div>

I found out my self.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/c/4ca02177cdecfbcb7428ccba1d195ea38c2ca6cb.png)

it was a wrong flow card  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/f/0f90a737f2013a8aadef6bd0e723ad36ffdecc2d.png)  
But I imported with the flow exchanger. But it works now 😄
