I thought it was finally time to share my flows that I use to automatically control my lights. The setup I have is a bit more advanced than the suggestions I have seen on this forum, which is the reason for this tutorial. Some features of my setup:
- Automatically turn on and off lights based on motion (doh!)
- Only turn lights on when it’s dark
- Configuration of various scenes (e.g. Normal scene, Movie scene, Dinner scene, Romantic scene etc)
- Memory ability that will remember the brightness of a light that you have manually set (either through a pulse switch, the homey app or any other app).
- Configurable duration of the countdown, which makes it easy to dynamically configure the ‘light on time’ of a room.
I will be showing you how I set this up in my bedroom, but I also use this in all the other rooms of my apartment.
Let’s get started!
In order to follow along with this tutorial, you’ll need to following things:
- A sensor that is capable of measuring motion and lux (light intensity). For example, a NEO Coolcam
- A light that can be controlled by Homey
- The countdown app by Ralf van Dooren
- Make sure all the apps are installed that are required to control your sensor and lights
- (Optional) The simple log app by Niels de Klerk to log which flows are executed. This is optional, but I like this app because it gives me an overview of everything that is happening in my apartment and makes it easy to debug any issues I come across.
Flow naming convention
Before we dive into all the cool stuff, let me explain how I setup and name my flows. I divide my flows into two categories: events (ev) and actions (ac). I also prefix my flows with a code that identifies the room the flow is used in (BR for bedroom, LR for living room etc). For example, the flow that turns the lights on in my bedroom is called ‘BR_ac_LightsOn’. The reason for this is abstraction and re-usability. You can image you’d want to turn the lights on from multiple flows. Instead of turning on each individual light in every single flow, you would just call the flow ‘BR_ac_LightsOn’. Another benefit is that you can add these ‘action flows’ to your favourites so that you can quickly execute them.
Dark / Light detection
Let’s start with the first component of our setup: detecting whether it’s light or dark in our room. Obviously we only want to turn our lights on when it’s dark and not during the day (except on those miserable rainy days). Dark / Light detection can be used for many other use cases as well. For example, whenever I open the curtains in my bedroom on a weekend-day, Homey detects it’s light, marks me as awake and automatically starts my weekend playlist on my Sonos.
Create the following variables in the Homey app (more > logic). Obviously you can use your own names:
- Bedroom_DarkLux (number). Configure this number to the threshold value (in lux) of dark/light. For example, I have set this value to 20, meaning every value below 20 is dark and every value above 20 is light. This value can differ depending on your room and the position of your sensor.
- Bedroom_DarkLight (text). This is the variable that will keep track of whether your room is ‘dark’ or ‘light’. Set this to either ‘dark’ or ‘light’, since we will use flows to automatically set this value.
Create the following flows to enable dark / light detection:
- BR_ev_LumChanged_Dark. This flow checks if the luminance is below our configured threshold and then sets the light state to ‘dark’. Note how I verify whether the variable isn’t already set to dark in order to prevent this flow from firing over and over again.
- BR_ev_LumChanged_Light. This flow checks if the luminance is above our configured threshold and then sets the light state to ‘light’. Note how I check whether one of my lights is turned off, before I tell Homey that the room is actually ‘light’. This is because we don’t want to tell Homey that the room is light when we have a light turned on.
Memory function for the brightness of our lights
Imagine you are doing something in your room that requires a lot of light. Whether it is hanging up new curtains or doing some overdue cable management behind your TV. I find it really annoying that Homey dims the lights back to its pre-configured value when I have put it all the way up in order to see what I am actually doing. This is why I have come up with a memory function that remembers the dim level of a light, so that value can be used to turn the light on based on motion. The idea is that you store the dim level of the light in a variable and use that variable to dim the light whenever you want to turn that light on.
Go ahead and create the following variables in the Homey app (more > logic):
- BR_DimLevel_BedLeft (number). This variable is used to store the dim level of the light ‘Bed left’.
- BR_DimLevel_BedRight (number).
- … repeat for every light in your room
- BR_ev_DimBedLeftChanged. This flow triggers when the brightness of your light has changed and stores the value in the appropriate variable. It doesn’t matter whether you use Homey, a physical switch or the native app (hue, lifx, ikea etc) to dim the light.
- …repeat for all the lights in your room.
Flow actions to turn the lights on and off
We need some ‘action flows’ that allow us to turn our lights on and off before we can link our lights to our motion sensor.
- BR_ac_LightsOn. This flow dims our lights to our configured variable. I guess there is a bug in ‘flow sharing’ (note the NaN%s). Make sure to use the variables (BR_DimLevel_BedLeft and Right) we created in the previous section. Make sure to include all the lights in your room.
- BR_ac_Lights_off. This flow turns our lights off.
Setting up our motion sensor flows
We can finally start with the fun stuff, now that all our building blocks are in place. Before we create our variables and flows, let’s head over to the Countdown app to create our timer:
- Go to the countdown app in the Homey app
- Click configure
- Add a timer with the name ‘Bedroom’
The idea of using the timer to control our lights is as follows. Our sensor will send us two events: a motion on and a motion off event. Motion on is sent whenever the sensors detects motion. Motion off is sent whenever no motion has been detected for a certain period by the sensor. To make sure the lights do not turn off too soon, we start a timer and only turn the lights off when that timer hits 0.
- Bedroom_LightTime (number). The amount of seconds the timer will run before turning off the lights. Set it to 60 for now or adjust to your liking.
- BR_ev_Motion_on_dark. This flow will turn the lights on when motion has been detected and when it is dark. Note that I also check that nobody is sleeping, since this flow is used in my bedroom. You can omit this check if you are using this flow in any other room.
- BR_ev_Motion_off.. This flow starts our timer with our pre-configured timeout when no motion has been detected for a while.
- BR_ev_timer_0. This flow turns our lights off when our timer hits zero. Note how we are using our ‘action flows’ we defined in the previous section.
Now that everything is setup we can start defining our scenes. I use scenes to set my lights to a specific ‘mood’ that’s appropriate for that time. In my bedroom I use a ‘normal scene’ for ordinary use, a ‘movie scene’ for when I am watching Netflix and a ‘romantic scene’ for when I… well you can fill in the blank . We will be using ‘Virtual switches’ to define our scenes. A virtual switch is a virtual (non physical) device that can be added to Homey. It will show up as a device under the ‘devices tab’, just like any physical devices do. This feature is still marked as experimental (although I have never had any issues with it), so you need to head over to more > settings > experiments to enable ‘Virtual devices’ in the Homey app. After enabling this, go to devices > + > Homey > Virtual Switch to add a switch. I have added the following switches:
- Normale scene
- Movie scene
- Candle scene (aka my romantic scene)
Add as many (or as few) as you’d like. Note that you can completely skip this section if you only need one ‘scene’ in your room.
It’s extremely easy to implement scenes in our setup. Define a flow for every scene you have added and make sure to turn off the switches for all the other scenes. Also note the ‘Else’ part where I do not turn on my lights, but just set the brightness levels of my variables whenever a scene is activated when it’s light in the room. This will make sure then whenever it gets dark, the appropriate dim levels are used when turning on the lights. Also note that I dynamically increase the light time whenever I enable the romantic scene and change it back when either the normal scene or movie scene are enabled.
- BR_sc_LightsNormal. This flow activates the normal scene.
- BR_sc_LightsMovie. This flow activates the movie scene.
- BR_sc_LightsCandle. This flow activates the romantic scene.
Inspiration for using scenes in other flows
Now that we have setup our scenes, we can use them in other flows to control our lights. I will show you how I use a chromecast in order to automatically turn on the movie scene. You can of course use anything you like to trigger the scenes we have just created.
- BR_ev_NetflixStarted. This flow triggers when Netflix is started on my chromecast. Note how easy the setup of this flow is because of our modular setup.
- BR_ev_NetflixStopped. This flow triggers when Netflix is stopped on my chromecast.
Whenever I have manually set the brightness of my lights, I eventually want them to automatically return to their default values, so that the next day, when it gets dark, the lights turn to my ‘normal scene’ again. The way I do this is by using, what I call, ‘reset flows’. The idea is to fire a flow at a specific time to restore your home back to its default state. For example, I fire my ‘reset flow’ at 2pm and also mark me and my girlfriend as ‘awake’ (in case we forget to use our flic buttons), clear my log, reset my light times etc.
Alright, that’s all folks! I hope you find this tutorial useful or hopefully you can at least draw some inspiration from it to automate your own home. Feel free to post any messages if you have any questions regarding this tutorial.