In this tutorial you will learn to:
- create simple flows, using ‘when’ and ‘then’
- learn to use tags in flows
- learn to expand your flows with ‘and’
- learn to add multiple ‘then’ and ‘and’ cards
- learn to ‘invert’ cards
Adding ‘or’ and ‘else’ will be part of the next tutorial.
First, I assume that you have a Homey (pro) installed, a few apps and devices set-up and ready to go and some basic knowledge the English language. Furthermore, I assume that you have Homey’s location enabled. There are other options for geofencing, but these will not be a part of this tutorial.
Let’s first create a basic flow. I want this flow to resume the music when I get home. To do this, we first need to define the trigger, also known as the ‘then’-card. This is always a certain situation which occurs that starts the execution of the flow. Important to remember is that this always is a point in time, for instance:
- The motion sensor was triggered
- Someone came home
- It’s 8 p.m.
So this can never be a continous situation, such as:
- Sonos is playing
- Someone is sleeping
- a zone is active
because this will cause an infinite amount of triggers and therefore start the same flow an infinite number of times, which will overload Homey. Therefore, you cannot find the Sonos is playing card or similar as a trigger.
In this case, the trigger could be ‘Someone came home’ (apologies for the Dutch cards), which looks something like this:
This means that the flow is triggered every time someone comes home. Also note that there will not appear a second ‘add card’ below the trigger. This is because there can only be one trigger in a flow. If you would like to start a flow with multiple triggers, not to worry! This is possible in Homey, but will require extra flows. It’s not very complex, but this will not be a part of this tutorial.
Next, we will create the ‘then’ card, which makes Sonos resume the music every time this flow is triggered. This can look something like this (‘Resume playing’, a Sonos card):
Note that in the ‘then’ section, there is a possibility to add extra cards (contrary to the ‘when’ section).
Our basic flow is now finished. Every time someone comes home, Sonos will resume playing.
Next, we will use a tag in a flow. To do this, we will use the same flow as above. Note that the first image had a tag in it:
This tag is called a ‘local tag’. This local tag will only be available in this specific flow. Local tags, opposed to the normal tags, have the ability that they gain a specific value, based on the trigger. In our example, when I come home, the tag will carry the value ‘Neuron’. When my girlfriend comes home, it will carry the value ‘Grumpy’. This enables us to limit the number of flows. I will explain this a bit later.
First, let’s use this local tag. I would like Homey to greet me when I come home. I created a ‘speech’ card, saying ‘Hello’, followed by that tag. When creating that card (in Chrome, this might look different on your phone, tablet or in a different browser, but the idea is the same), you get a text box where you can add the ‘Hello’ part. Above this text box, you note the same tag. When you click that tag, you get a list of the local and other tags. The local tag is always the upper tag (or tags), in this case, the name of the person who got home:
When you click the local tag, the text box should read:
![image](https://global.discourse-cdn.com/business4/uploads/athom/original/3X/8/4/84c15aab1c9f75364647fbb850f7d56881550c43.png)
Now, when I get home, Sonos starts playing and Homey says: ‘Hello Neuron’. When my girlfriend comes home, Homey says: ‘Hello Grumpy’, using only one flow. This explains my earlier statement that the tags allow us to use less flows for the same purpose. Also, note that yet another ‘add card’ has appeared. As far as I am aware, there’s no limit to the number of ‘then’ cards you can add. Perhaps other Homey users can add information in the comments. Take a minute to get some coffee and wonder how you could use tags in flows.
Next, we will adjust the flow slightly, using the ‘and’ card. As you might have noticed, my ‘Grumpy’ isn’t always that happy. She’s especially unhappy when the music starts playing when I get home while she is watching her favorite show. Remember we made a flow that triggers every time someone comes home. So, even when Grumpy is home, the flow will trigger when I get home. Let’s see if we can fix this, still using only one flow. Luckily, she always watches using Chromecast.
To do this, let’s add a ‘and’ card, called ‘Chromecast is playing’. Our flow in total now looks like this:
Let’s see if we know what this flow does:
- This flow triggers when someone comes home
- it then checks the ‘and’ part. This means that the flow will only continue to execute the ‘then’ part when the condition of the ‘and’ part is met. In this case, the flow will execute the then part only when the chromecast is playing
- the flow will then greet me and start Sonos
But wait, this flow does exactly the opposite of our goal! Instead of executing when the Chromecast is playing, we want it to not execute when the Chromecast is playing. Let’s see if we can fix this. As you might know, there is no Chromecast is not playing card. Fortunately, Athom helps us here with the ‘invert’ option in the card of 'chromecast is playing:
When we check this, the card will change to ‘Chromecast is not playing’:
This gives us the following flow:
Let’s see if we know what this flow does:
- This flow triggers when someone comes home
- it then checks the ‘and’ part. This means that the flow will only continue to execute the ‘then’ part when the condition of the ‘and’ part is met. In this case, the flow will execute the then part only when the chromecast is not playing
- the flow will then greet me and start Sonos
Now it does what we want! Let’s recap. When the event in the ‘then’ part occurs, the flow triggers. It will then check the ‘and’ part. Note that, opposite to the ‘when’ part, the ‘and’ part is always a continous condition, like Chromecast is playing in our example.
Also note that other ‘and’ cards can be added below the first ‘and’ card. When you do this, Homey will check both conditions and will only execute when both conditions are met. Be sure to never have a conflicting ‘and’ part, or your flow will never execute. This mostly happens with time. People sometimes want a flow to only execute when it’s night time, say between 22.30 and 6.30. However, when adding this in the ‘and’ part, people are likely to add this like:
- and the time is later than 22.30
- and the time is earlier than 6.30
Homey will check this on the same day. Try to think of a moment during any given day that it’s both later than 22.30 and earlier than 6.30 on that specific day. To fix this, inverting is a good idea, so it reads:
- and the time is not earlier than 22.30
or - the time is not later than 6.30
In this case, the flow will execute only before 6.30 or after 22.30. This requires the ‘or’ part. I recommend you read my second tutorial for that.
I hope this helps those beginners out there with their first steps. Be sure to check out the tutorial which explains ‘or’ and ‘else’ in flows. I’m happy to help with any questions in the comments. Happy flowing!