Keep your automations clean
This image is generated using Dall-EPrompt: Generate an image of a robot performing multiple tasks at once in a minimalistic flat style
Introduction
Since Google has introduced their new automations tool, I’ve been moving everything back from Siri Shortcuts to the Google Home ecosystem. After adding all the animations one by one, the overview was completely gone. We had more than twenty automations all with different names and different starters. When an automation wasn’t working properly, for example the lights would “flash” bright and then turn to a brightness of 70%, I had to search in the overview for the correct automations and then guess which one was the cause of the problem.
As you might think yourself, this was far from what I dreamt would be the ideal smart home setup. That’s when I started Googling for a solution to add conditions to a specific starter.
Case
The first thing I wanted were the hallway lights to always turn on during the day, but at night only when either the living room lights are on or when the bedroom light is on. What I wanted was this (note, this does not work):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
metadata:
name: Motion in hallway
description: Turn on the hallway lights when motion is detected while I'm home and it's dark outside
automations:
starters:
- type: device.state.MotionDetection
state: motionDetectionEventInProgress
is: true
device: MS Hallway - Default
condition:
type: home.state.HomePresence
state: homePresenceMode
is: HOME
- type: device.state.MotionDetection
state: motionDetectionEventInProgress
is: true
device: MS Hallway - Default
condition:
type: and
conditions:
- type: home.state.HomePresence
state: homePresenceMode
is: HOME
- type: or
conditions:
- type: device.state.OnOff
state: on
is: true
device: Bedroom Light - Bedroom
- type: device.state.OnOff
state: on
is: true
device: Living room Light - Living Room
But that didn’t pass the validation step in the editor, thus I got back to Googling another solution.
Multiple starters
When Googling I came across another example from Google where I saw something that was just what I wanted. There’s an option to add multiple automations using the collection syntax from yaml (YAML Language Development Team, 2021)!
This gives us the option to have multiple different starters with their own conditions to be placed in the same automation, thus keeping our overview clean and making it easy to group automations.
Given our previous automation, we can turn that into a working automation by rewriting it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
metadata:
name: Motion in hallway
description: Turn on the hallway lights when motion is detected while I'm home and it's dark outside
automations:
# Turn on the lights during the day
- starters:
- type: device.state.MotionDetection
state: motionDetectionEventInProgress
is: true
device: MS Hallway - Default
condition:
type: and
conditions:
- type: home.state.HomePresence
state: homePresenceMode
is: HOME
- type: time.between
after: sunrise
before: sunset
actions:
- type: device.command.OnOff
on: true
devices: Hallway light - Hallway
# Turn on the lights during the night
- starters:
- type: device.state.MotionDetection
state: motionDetectionEventInProgress
is: true
device: MS Hallway - Default
condition:
type: and
conditions:
- type: home.state.HomePresence
state: homePresenceMode
is: HOME
- type: time.between
after: sunset
before: sunrise
- type: or
conditions:
- type: device.state.OnOff
state: on
is: true
device: Bedroom Light - Bedroom
- type: device.state.OnOff
state: on
is: true
device: Living room Light - Living Room
actions:
- type: device.command.OnOff
on: true
devices: Hallway light - Hallway
Categories
Related articles