Introduction
In my household everyone goes to sleep and wakes up at different times. Also, not everyone sleeps at home every day, or some people might arrive while others are already asleep. This creates some tricky challenges when it comes to automating presence based behavior. Here are the problems I faced and how I tackled them.
Problem 1: Reliable presence detection
In many phones, but mainly iPhones, apps don’t have the same access level to location services, or will not always keep their background privileges. For instance when apps update, when phones update or restart, or when an app isn’t used and the phone needs the RAM for other tasks. This is why location services in apps can’t be trusted for critical task that always need to work. This is also why, during the COVID pandemic, Apple and Google decided to build their own system level algorithms to detect peoples exposure to infected persons. For this reason, I didn’t want to use presence detection of the Homey App, but wanted to find a way to utilize iOS’s native system level location services. Here’s how I did it:
Step 1: Create actions to update presence in Homey
In order for iOS to be able to update people presence in Homey, we need actions available that can be called for each of the presence stated for every person in the household. Here’s how these would look:
Step 2: Setup Automations in Shortcuts
I used the Shortcuts app to reliably automate the presence in Homey. Simply create 4 automations that trigger the actions in homey. here’s how it looks:
Problem 2: Calculating presence
As you can see, in order to keep the presence automation simpel and reliable I simply update the Home/Away states based on location, and the Awake/Asleep based on bedtime. This means that the Presence states keep being updated independently from each other. People will still be marked Awake and Asleep when they are Away, And are marked Home and Away when bedtime has started and are marked Asleep. This could create a problem when you want to keep track of how many people are Asleep at Home or Awake at Home. Here’s how I created a simple homey script for that. The following Homey scripts creates 3 tags to use in your flow for the number of persons at home, the number of persons asleep, and the number of persons asleep at home:
const users = await Homey.users.getUsers();
const userArray = Object.values(users);
await Promise.all([
tag('Persons At Home', userArray.filter(({present}) => present).length),
tag('Persons Asleep', userArray.filter(({asleep}) => asleep).length),
tag('Persons Asleep At Home', userArray.filter(({present, asleep}) => present && asleep).length)
]);
How to implement it all
Here’s how I implemented it all into my advanced presence based flows:






