Skip to content

Commit 5d708cd

Browse files
committed
Add blog post about Google Home YAML automation scripts
Comprehensive guide covering script structure, starters, conditions, and actions with practical examples for cinema mode and night light automations.
1 parent ccab1ca commit 5d708cd

1 file changed

Lines changed: 365 additions & 0 deletions

File tree

Lines changed: 365 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,365 @@
1+
---
2+
layout: default
3+
title: "Automating Your Smart Home with Google Home YAML Scripts"
4+
date: 2025-12-16
5+
description: "Learn how to create powerful smart home automations using Google Home's YAML script editor with practical examples for cinema mode and night light scenes."
6+
categories: [smart-home, automation, yaml]
7+
---
8+
9+
# Automating Your Smart Home with Google Home YAML Scripts
10+
11+
Google Home's script editor offers a powerful way to create custom automations for your smart home using YAML. While the web interface provides a visual editor, understanding the YAML structure gives you more control and makes it easier to version control your automations.
12+
13+
## Getting Started
14+
15+
To create Google Home scripts:
16+
17+
1. Go to [home.google.com](https://home.google.com)
18+
2. Navigate to the **Automations** tab
19+
3. Press **+ Add new** to create a new script
20+
21+
The script editor uses YAML, which gives you full control over your automations. While it might look intimidating at first, the structured format is actually quite intuitive once you understand the basics.
22+
23+
## Understanding the YAML Structure
24+
25+
Every Google Home automation script follows this basic structure:
26+
27+
```yaml
28+
metadata:
29+
name: Script Name
30+
description: What this script does.
31+
32+
automations:
33+
- starters:
34+
- type: starter.type.here
35+
36+
condition: # optional
37+
type: condition.type.here
38+
39+
actions:
40+
- type: action.type.here
41+
```
42+
43+
**Key points to remember:**
44+
45+
- `automations:` is a list (each automation starts with `-`)
46+
- `starters:` is a list (each starter starts with `-`)
47+
- `condition:` is **NOT** a list (no `-` before it)
48+
- `actions:` is a list (each action starts with `-`)
49+
50+
## Starters: Triggering Your Automations
51+
52+
### Voice Commands
53+
54+
The most common trigger is a voice command:
55+
56+
```yaml
57+
starters:
58+
- type: assistant.event.OkGoogle
59+
eventData: query
60+
is: "activate cinema mode"
61+
```
62+
63+
This allows you to say "Hey Google, activate cinema mode" to trigger the automation. You can also run it manually from the Google Home app.
64+
65+
### Time-Based Triggers
66+
67+
Schedule automations to run at specific times:
68+
69+
```yaml
70+
starters:
71+
- type: time.schedule
72+
at: 07:30
73+
weekdays:
74+
- MONDAY
75+
- TUESDAY
76+
- WEDNESDAY
77+
- THURSDAY
78+
- FRIDAY
79+
```
80+
81+
### Device State Triggers
82+
83+
React when a device changes state:
84+
85+
```yaml
86+
starters:
87+
- type: device.state.OnOff
88+
device: Samsung The Frame 50 - Living Room
89+
state: on
90+
is: true
91+
```
92+
93+
This triggers when the TV turns on, perfect for creating automatic ambiance adjustments.
94+
95+
## Conditions: Adding Intelligence
96+
97+
Conditions make your automations context-aware. Only after sunset should your cinema mode activate automatically:
98+
99+
```yaml
100+
condition:
101+
type: time.between
102+
after: sunset
103+
before: sunrise
104+
```
105+
106+
You can also check device states:
107+
108+
```yaml
109+
condition:
110+
type: device.state.OnOff
111+
device: Samsung TV - Living Room
112+
state: on
113+
is: false
114+
```
115+
116+
### Complex Conditions
117+
118+
Combine multiple conditions with logical operators:
119+
120+
```yaml
121+
condition:
122+
type: and
123+
conditions:
124+
- type: device.state.OnOff
125+
device: Samsung TV - Living Room
126+
state: on
127+
is: true
128+
- type: or
129+
conditions:
130+
- type: time.between
131+
after: 20:00
132+
- type: time.between
133+
weekdays:
134+
- SATURDAY
135+
- SUNDAY
136+
```
137+
138+
## Actions: Making Things Happen
139+
140+
### Controlling Lights
141+
142+
Turn lights on or off:
143+
144+
```yaml
145+
- type: device.command.OnOff
146+
devices:
147+
- Living Room Lights - Living Room
148+
on: true
149+
```
150+
151+
Set brightness (0-100):
152+
153+
```yaml
154+
- type: device.command.BrightnessAbsolute
155+
devices:
156+
- Living Room Light - Living Room
157+
brightness: 25
158+
```
159+
160+
Set color temperature for the perfect ambiance:
161+
162+
```yaml
163+
- type: device.command.ColorAbsolute
164+
devices:
165+
- Living Room Light - Living Room
166+
color:
167+
temperature: 2202K
168+
```
169+
170+
### Adding Delays
171+
172+
Create sequences with pauses between actions:
173+
174+
```yaml
175+
- type: time.delay
176+
for: 5min
177+
```
178+
179+
Formats supported: `30sec`, `5min`, `2hours`
180+
181+
### Voice Announcements
182+
183+
Broadcast messages to your speakers:
184+
185+
```yaml
186+
- type: assistant.command.Broadcast
187+
devices:
188+
- Kitchen Speaker - Kitchen
189+
message: "Dinner is ready!"
190+
```
191+
192+
### Media and Volume Control
193+
194+
```yaml
195+
- type: device.command.SetVolume
196+
devices:
197+
- Living Room Speaker
198+
volumeLevel: 30
199+
200+
- type: device.command.MediaPause
201+
devices:
202+
- Living Room Speaker
203+
```
204+
205+
## Real-World Example: Cinema Mode
206+
207+
Let's look at a practical automation that creates the perfect movie-watching atmosphere. This script automatically dims your lights when you turn on the TV after sunset:
208+
209+
```yaml
210+
metadata:
211+
name: TV Cinema Auto
212+
description: Automatically dim lights to cinema mode when TV turns on after sunset.
213+
214+
automations:
215+
- starters:
216+
- type: device.state.OnOff
217+
device: Samsung The Frame 50 - Living Room
218+
state: on
219+
is: true
220+
221+
condition:
222+
type: time.between
223+
after: sunset
224+
before: sunrise
225+
226+
actions:
227+
# Turn off main lights to reduce glare
228+
- type: device.command.OnOff
229+
devices:
230+
- Ceiling Light - Living Room
231+
- Desk Light - Living Room
232+
on: false
233+
234+
# Set ambient lights to very low warm glow
235+
- type: device.command.BrightnessAbsolute
236+
devices:
237+
- Sofa Light - Living Room
238+
- Window Light - Living Room
239+
brightness: 10
240+
241+
- type: device.command.ColorAbsolute
242+
devices:
243+
- Sofa Light - Living Room
244+
- Window Light - Living Room
245+
color:
246+
name: "warm white"
247+
248+
# Turn on lava lamp for ambient effect
249+
- type: device.command.OnOff
250+
devices:
251+
- Lava Lamp - Living Room
252+
on: true
253+
```
254+
255+
## Real-World Example: Night Light
256+
257+
Safe navigation at night without blinding yourself:
258+
259+
```yaml
260+
metadata:
261+
name: Night Light Mode
262+
description: Very dim hallway light for nighttime navigation without blinding.
263+
264+
automations:
265+
- starters:
266+
- type: assistant.event.OkGoogle
267+
eventData: query
268+
is: "night light"
269+
270+
condition:
271+
type: time.between
272+
after: 22:00
273+
before: 06:00
274+
275+
actions:
276+
# Hallway lights at minimal brightness
277+
- type: device.command.BrightnessAbsolute
278+
devices:
279+
- Hallway Light 1 - Hallway
280+
- Hallway Light 2 - Hallway
281+
brightness: 5
282+
283+
- type: device.command.ColorAbsolute
284+
devices:
285+
- Hallway Light 1 - Hallway
286+
- Hallway Light 2 - Hallway
287+
color:
288+
name: "warm white"
289+
```
290+
291+
## Important Notes on Device Naming
292+
293+
Device names in Google Home scripts must **exactly match** how they appear in your Google Home app. The format is always:
294+
295+
```
296+
Device Name - Room Name
297+
```
298+
299+
For example:
300+
- `Ceiling Light - Living Room`
301+
- `Kitchen Speaker - Kitchen`
302+
- `Front Door Lock - Front Porch`
303+
304+
## Common Pitfalls and Fixes
305+
306+
| Error | Cause | Fix |
307+
|-------|-------|-----|
308+
| `Expected subfields: [is]` | OkGoogle starter missing required field | Add both `eventData: query` and `is: "phrase"` |
309+
| `Expected subfields: [devices]` | Used `device:` (singular) | Use `devices:` (plural) as a list |
310+
| `Expected subfields: [on]` | Wrong OnOff syntax | Use `on: true` or `on: false` (boolean) |
311+
| `value should be [FieldPath] but is [Map]` | Nested object where simple value expected | Use `eventData: query` not `eventData: {query: ...}` |
312+
313+
## Advanced Features
314+
315+
### Light Effects
316+
317+
Create gradual transitions with sleep and wake effects:
318+
319+
```yaml
320+
# Gradual dim over 30 minutes
321+
- type: device.command.LightEffectSleep
322+
devices:
323+
- Bedroom Lights
324+
duration: 30min
325+
sleepBrightness: 0
326+
327+
# Gradual brighten over 15 minutes
328+
- type: device.command.LightEffectWake
329+
devices:
330+
- Bedroom Lights
331+
duration: 15min
332+
wakeBrightness: 100
333+
```
334+
335+
### Robot Vacuum Control
336+
337+
Automate your robot vacuum:
338+
339+
```yaml
340+
- type: device.command.StartStop
341+
devices:
342+
- Robot Vacuum - Kitchen
343+
start: true
344+
345+
# Or send it back to dock
346+
- type: device.command.Dock
347+
devices:
348+
- Robot Vacuum - Kitchen
349+
```
350+
351+
## Tips for Success
352+
353+
1. **Start simple**: Begin with a basic voice-triggered automation before adding conditions and complex sequences
354+
2. **Test incrementally**: Add one action at a time and test to ensure each works correctly
355+
3. **Use descriptive names**: Your future self will thank you for clear metadata names and descriptions
356+
4. **Version control**: Keep your YAML files in a Git repository to track changes
357+
5. **Check device names**: The most common error is mismatched device names - always verify in the Google Home app
358+
359+
## Conclusion
360+
361+
Google Home's YAML script editor unlocks powerful automation capabilities for your smart home. By understanding the structure and available commands, you can create sophisticated routines that make your home truly intelligent. Start with simple automations and gradually build more complex scenarios as you become comfortable with the syntax.
362+
363+
Whether you're creating the perfect movie-watching ambiance, automating your morning routine, or simply making your home more convenient, YAML scripts give you the flexibility to design exactly what you need.
364+
365+
Happy automating! 🏠✨

0 commit comments

Comments
 (0)