Start with Google Home Automation#

Home automation is a great way to put your home to work for you. With Google Home, you can build your own automated routines to make your home smarter and more comfortable. You can also use the Google Home app to control your smart home devices from anywhere. And while other solutions exist, Google Home is a platform that is easy to use by most people. The options were only limited but now you can use the Google Home Automation editor to create your own automations.

Steps for creating a Google Home automation#

Let’s get started with an example to turn on the lights at sunset, but only if you are at home and the television is on. The first part of the script is the metadata. This is where you define the name and description of the automation. The name should be short and descriptive, while the description should be detailed and include everything the automation does.

Example YAML for Sunset lights automation#
---
# ------------------------------------------------------------------------------------------ #
# Lines starting with “#” are comments and will be ignored by the automation.
# Indentation determines hierarchy within the script.
# Visit g.co/home/script-editor-docs for full documentation.
# ------------------------------------------------------------------------------------------ #

metadata:
  name: Sunset lights # Choose a short name that summarizes important starters and actions, like “Sunset lights”.
  description: Scripted automation # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”

The next part of the script is the automations. This is where you define the starters, conditions, and actions. Starters describe events that will start the automation. Conditions will prevent an automation from starting if the conditions aren’t met. Actions will start when a starter event takes place and all conditions are met. In the example below, the starter is a time.schedule event that will start the automation at sunset on weekdays.

Example YAML for Sunset lights automation#
automations:
  # “starters” and “actions” are required; “conditions” are optional.
  # Use Ctrl + Space to see autocomplete suggestions.

  # ---- STARTERS ---- #
  # Starters describe events that will start the automation.
  # To add more than one starter, duplicate the "- type" section under "starters".
  # If you add multiple starter events, any one of them happening will start the automation
  starters:
    - type: time.schedule
      # Required. Time to schedule automation. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
      at: sunset
      # Optional. Days of the week to run automation on.
      weekdays:
        - MON
        - TUE
        - WED
        - THU
        - FRI

After the trigger the conditions are checked. If the conditions are not met, the automation will not start. In the example below, the first condition is a home.state.HomePresence event that will check if the home presence mode is set to HOME. The second condition is a device.state.OnOff event that will check if the television is on. If both conditions are met, the automation will start.

Example YAML for Sunset lights automation#
  # ---- CONDITIONS ---- #
  # Conditions are optional. Delete this section if it’s empty.
  # Conditions will prevent an automation from starting if the conditions aren’t met.
  # See g.co/home/script-editor-docs for documentation about how to use logical operators like “and”, “or”, and “not”.
  condition:
    type: and
    # "AND" together two or more conditionals
    conditions:
      - type: home.state.HomePresence
        state: homePresenceMode
        # [available operators: is, isNot]
        is: HOME
      - type: device.state.OnOff
        state: on
        # [available operators: is, isNot]
        is: true
        device: Living room TV - Living room

the final part of the script is the actions. This is where you define what you want to happen when the starter event takes place and all conditions are met. You can add as many actions as you want, and they will start in the order they appear in the script. You can also add a delay to each action, which will cause the action to start after the specified amount of time. In the example below, the first action will start immediately by turning on the lights in the order listed.

Example YAML for Sunset lights automation#
  # ---- ACTIONS ---- #
  # Actions will start when a starter event takes place and all conditions are met.
  # Actions will start in the order they appear in the script and with any delay specified.
  # To add more than one action, duplicate the "- type" section under "actions".
  actions:
    - type: device.command.OnOff # Turn the device on or off.
      on: true
      devices:
        - Lamp TV left - Living room
        - Lamp TV right - Living room
        - Table lamp - Living room
        - Floor lamp - Living room

Full example script#

If we combine all the parts of the script, we get the following example that can be directly imported into the Google Home Automation editor.

Example YAML for Sunset lights automation#
---
# ------------------------------------------------------------------------------------------ #
# Lines starting with “#” are comments and will be ignored by the automation.
# Indentation determines hierarchy within the script.
# Visit g.co/home/script-editor-docs for full documentation.
# ------------------------------------------------------------------------------------------ #

metadata:
  name: Sunset lights # Choose a short name that summarizes important starters and actions, like “Sunset lights”.
  description: Scripted automation # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”

automations:
  # “starters” and “actions” are required; “conditions” are optional.
  # Use Ctrl + Space to see autocomplete suggestions.

  # ---- STARTERS ---- #
  # Starters describe events that will start the automation.
  # To add more than one starter, duplicate the "- type" section under "starters".
  # If you add multiple starter events, any one of them happening will start the automation
  starters:
    - type: time.schedule
      # Required. Time to schedule automation. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
      at: sunset
      # Optional. Days of the week to run automation on.
      weekdays:
        - MON
        - TUE
        - WED
        - THU
        - FRI

  # ---- CONDITIONS ---- #
  # Conditions are optional. Delete this section if it’s empty.
  # Conditions will prevent an automation from starting if the conditions aren’t met.
  # See g.co/home/script-editor-docs for documentation about how to use logical operators like “and”, “or”, and “not”.
  condition:
    type: and
    # "AND" together two or more conditionals
    conditions:
      - type: home.state.HomePresence
        state: homePresenceMode
        # [available operators: is, isNot]
        is: HOME
      - type: device.state.OnOff
        state: on
        # [available operators: is, isNot]
        is: true
        device: Living room TV - Living room

  # ---- ACTIONS ---- #
  # Actions will start when a starter event takes place and all conditions are met.
  # Actions will start in the order they appear in the script and with any delay specified.
  # To add more than one action, duplicate the "- type" section under "actions".
  actions:
    - type: device.command.OnOff # Turn the device on or off.
      on: true
      devices:
        - Lamp TV left - Living room
        - Lamp TV right - Living room
        - Table lamp - Living room
        - Floor lamp - Living room

After pasting it in editor, you can click on the validate button to check if there are any errors in the script. If there are no errors, you can click on the save button to save the script. After saving the script, you can click on the run button to run the script. You also have the option to enable and disable the script by clicking on the toggle button. This way you can prepare scripts for future use like a Christmas script that will turn on the Christmas lights at a certain time or a script that will turn on the lights when you are on vacation.

First thoughts about Google Home Automation#

Google Home Automation is still in preview and it shows as not all triggers and actions are available yet, but improvements are made regulary. One of the biggest improvements is already made by having a validation option in the editor as it is very easy to make a mistake in the yaml file. The editor is also very easy to use and it is very easy to create a script, but this is also its biggest disadvantages as this may scare people off. Hopefully Google will add a GUI in the future to make it more accessible for everyone. For now Google Home Automation is a nice addition to the Google Home app and it is a good start for people who want to start with home automation and don’t want to use a third party app like Home Assistant or IFTTT.