Missing "everybody is asleep" condition

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.

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

This results in anyone is asleep.

Hmm, you are right, then I guess that is a feature request, 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.

image

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

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;

3 Likes

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

1 Like

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?

1 Like

I thought of editing that script, and add a counter for the number of not sleeping persons

Code:

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


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:

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

Result when false:

Screenshot from 2023-06-03 16-54-48

1 Like

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

1 Like

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

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

I found out my self.

it was a wrong flow card
image
But I imported with the flow exchanger. But it works now :smile:

2 Likes