cancel
Showing results for 
Search instead for 
Did you mean: 

Let's discuss: creating powerful automations with our new script editor!

kelanfromgoogle
Community Manager (Admin)
Community Manager (Admin)

Hey everyone!

This week, we released the script editor, a tool for creating advanced home automations, on Google Home for web and the Google Home app. Learn more about it in our community blog:
New to Public Preview: create powerful automations with our script editor.

 

You can unlock the full potential of home automation by building advanced, personalized automations. Here are some examples that can be done only in the script editor:

 

We'd love to hear about how you are using the script editor. Share your favorite use cases for the script editor, and your automation scripts in the comments below!

 

Here are some helpful guidelines for sharing your automations in the Community discussion forum: 

  • Use clear and concise titles in your post. For example, Automation Script: Water the lawn in the mornings.
  • Include why you created the automation. Describing what this solved for you may inspire others to try it out. For example, "My schedule can vary a lot during the week so it's helpful to add a few conditions to create the automation flexibility I need."
  • Share the script in text format. Copy and paste your automation script so that other users can learn from what you’ve created.

  • Do not include personal information. To ensure your safety, security, and privacy, make sure your custom automation doesn’t include any personal information you don’t want to share.
  • Use the category “Sharing an Automation.” Using the correct category helps other community members find your post.

 

166 REPLIES 166

Prafulla
Googler
Googler

Thanks @kelanfromgoogle 

 

Looking forward to seeing what everyone is creating. We are here to help if there are any questions.

I am trying to use a motion detection event as a starter, in lieu of motion activity state, and EventData is an optional state. Per the help file, the event data options are either "Priority" or "TimeStampSec." The list of options for Priority is a number, but the help files do not define what each value relates to. Is there documentation that provides greater details, such as what each priority value equates to? The code below was my attempt to get some information, but the system did not respond.

metadata:
  name: TEsting Stuff # 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; “condition” is 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: device.event.MotionDetection # This function belongs to devices which are able to record motion detection.
        eventData: priority
        is: 0
        device: Front Door MotionSensor - Front Porch

    actions:
      - type: assistant.command.Broadcast
        message: "Priority is 0"
        devices: Dining Room Speakers - Dining Room

  - starters:
      - type: device.event.MotionDetection # This function belongs to devices which are able to record motion detection.
        eventData: priority
        is: 1
        device: Front Door MotionSensor - Front Porch

    actions:
      - type: assistant.command.Broadcast
        message: "Priority is 1"
        devices: Dining Room Speakers - Dining Room

  - starters:
      - type: device.event.MotionDetection # This function belongs to devices which are able to record motion detection.
        eventData: priority
        is: 2
        device: Front Door MotionSensor - Front Porch

    actions:
      - type: assistant.command.Broadcast
        message: "Priority is 2"
        devices: Dining Room Speakers - Dining Room

  

  •  

I noticed that motion detection for Nest Thermostats and Cameras are now a starter. This is great! For the cameras, are we able to distinguish motion within a defined zone?

Does it works? it gives me an error in the state parameter.

Agree here. We need to have zones available to use with the cameras, etc.

On my front door camera with a 'driveway' zone enabled, the script fails validation as it thinks person detection is turned off but it's only turned off for outside of the zone.

I'd say most people have zones set up on their cameras. Without seeing zones in the script editor, it won't be much use unfortunately. 😓

Ok Google 

  •  

William1701
Community Member

I am working on creating a routine that turns my porch light on/off based on two motion sensors. ("or" condition for both sensors to turn the light on and an "and" condition for both sensors to turn the light off) The single light source affects two motion zones, so the ability to write a routine should help. I will find out if it works when it gets dark.

 

I am struggling with the save feature if I apply a "for" condition to both sensors with the "motionDetectionEventInProgress" state identified as "false." I can apply the "for" condition to one of the sensors and the routine will save, but not both. My preference is for both sensors to have to not sense motion for several minutes before the light turns off. Any thoughts?

 

automations:
starters:
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: false
for: 3min
device: Front Door MotionSensor - Front Porch
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: false
for: 3min
device: Front Porch MotionSensor - Front Porch

 

Thanks for sharing @William1701  - That's a very interesting use case but is not yet supported. Currently:

  • all starters are separated by "or" and automation runs whenever any of the starters is true.
  • all conditions get checked only when a starter has started the automation. Hence, "for" works for starters but not for conditions.

 

The closest workaround for your case could be to use sensor1 as starter using "for" and sensor2 as condition (motionDetectionEventInProgress = False)? You would need to do that both ways.

Prafulla

Separating the starters for the no-motion condition into two possible start conditions appears to work to create the "or" condition without the save fail. Thanks for your help. The script is now a bit more complex as I have added a condition that it should not run when I am using the light as part of my holiday decorations, and only for evening hours. New, much longer script below (indentions lost in paste):

 

metadata:
name: Front Porch Lights On/Off with Motion # Update automation name e.g. "Movie time"
description: Scripted Front Porch Steps Control Test # Update automation description

automations:
- starters:
# Use Ctrl + Space to get autocomplete suggestions
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: true
device: Front Door MotionSensor - Front Porch
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: true
device: Front Porch MotionSensor - Front Porch

condition:
type: and
conditions:
- type: time.between
after: sunset
before: sunrise
weekdays:
- MON
- TUE
- WED
- THU
- FRI
- SAT
- SUN
- type: or
conditions:
- type: device.state.Online
state: online
is: false
device: Icicles Left - Holiday
- type: and
conditions:
- type: device.state.Online
state: online
is: true
device: Icicles Left - Holiday
- type: device.state.OnOff
state: on
is: false
device: Icicles Left - Holiday

actions:
- type: device.command.BrightnessAbsolute # Adjust device absolute brightness.
brightness: 15
devices: Front Porch Steps - Front Porch
- type: device.command.ColorAbsolute
color:
name: warm white
devices: Front Porch Steps - Front Porch
- type: device.command.ColorAbsolute
color:
name: warm white
devices: Front Door Lamp Left - Front Porch
- type: device.command.ColorAbsolute
color:
name: warm white
devices: Front Door Lamp Right - Front Porch

- starters:
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: false
for: 2min
device: Front Porch MotionSensor - Front Porch

condition: # Use Ctrl + Space to get autocomplete suggestions
type: and
conditions:
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: false
device: Front Door MotionSensor - Front Porch
- type: or
conditions:
- type: device.state.Online
state: online
is: false
device: Icicles Left - Holiday
- type: and
conditions:
- type: device.state.Online
state: online
is: true
device: Icicles Left - Holiday
- type: device.state.OnOff
state: on
is: false
device: Icicles Left - Holiday
actions:
- type: device.command.OnOff # Turn the device on or off.
on: false
devices: Front Porch Steps - Front Porch

- starters:
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: false
for: 2min
device: Front Door MotionSensor - Front Porch

condition: # Use Ctrl + Space to get autocomplete suggestions
type: and
conditions:
- type: device.state.MotionDetection # This function belongs to devices that can detect motion.
state: motionDetectionEventInProgress
is: false
device: Front Porch MotionSensor - Front Porch
- type: or
conditions:
- type: device.state.Online
state: online
is: false
device: Icicles Left - Holiday
- type: and
conditions:
- type: device.state.Online
state: online
is: true
device: Icicles Left - Holiday
- type: device.state.OnOff
state: on
is: false
device: Icicles Left - Holiday
actions:
- type: device.command.OnOff # Turn the device on or off.
on: false
devices: Front Porch Steps - Front Porch
- type: device.command.OnOff # Turn the device on or off.
on: false
devices: Front Door Lamp Left - Front Porch
- type: device.command.OnOff # Turn the device on or off.
on: false
devices: Front Door Lamp Right - Front Porch

Wow that's one long script 🙂 Btw, you should be able to use the "insert code sample" feature of the editor that looks like "</>" and use "CSS" to format and share your script without losing the indentation.

Sending the script in the CSS format as suggested, for those who might be interested.

metadata:
  name: Front Porch Lights On/Off with Motion
  description: Scripted Front Porch Steps Control Test

automations:
  - starters:
      - type: device.state.MotionDetection 
        state: motionDetectionEventInProgress
        is: true
        device: Front Door MotionSensor - Front Porch
      - type: device.state.MotionDetection
        state: motionDetectionEventInProgress
        is: true
        device: Front Porch MotionSensor - Front Porch

    condition:
      type: and
      conditions:
        - type: time.between
          after: sunset
          before: sunrise
          weekdays:
            - MON
            - TUE
            - WED
            - THU
            - FRI
            - SAT
            - SUN
        - type: or
          conditions:
            - type: device.state.Online
              state: online
              is: false
              device: Icicles Left - Holiday
            - type: and
              conditions:
                - type: device.state.Online
                  state: online
                  is: true
                  device: Icicles Left - Holiday
                - type: device.state.OnOff
                  state: on
                  is: false
                  device: Icicles Left - Holiday

    actions:
      - type: device.command.BrightnessAbsolute
        brightness: 15
        devices: Front Porch Steps - Front Porch
      - type: device.command.ColorAbsolute
        color:
          name: warm white
        devices: Front Porch Steps - Front Porch
      - type: device.command.ColorAbsolute
        color:
          name: warm white
        devices: Front Door Lamp Left - Front Porch
      - type: device.command.ColorAbsolute
        color:
          name: warm white
        devices: Front Door Lamp Right - Front Porch

  - starters:
      - type: device.state.MotionDetection
        state: motionDetectionEventInProgress
        is: false
        for: 2min
        device: Front Porch MotionSensor - Front Porch

    condition:
      type: and
      conditions:
        - type: device.state.MotionDetection
          state: motionDetectionEventInProgress
          is: false
          device: Front Door MotionSensor - Front Porch
        - type: or
          conditions:
            - type: device.state.Online
              state: online
              is: false
              device: Icicles Left - Holiday
            - type: and
              conditions:
                - type: device.state.Online
                  state: online
                  is: true
                  device: Icicles Left - Holiday
                - type: device.state.OnOff
                  state: on
                  is: false
                  device: Icicles Left - Holiday
    actions:
      - type: device.command.OnOff
        on: false
        devices: Front Porch Steps - Front Porch

  - starters:
      - type: device.state.MotionDetection
        state: motionDetectionEventInProgress
        is: false
        for: 2min
        device: Front Door MotionSensor - Front Porch

    condition:
      type: and
      conditions:
        - type: device.state.MotionDetection
          state: motionDetectionEventInProgress
          is: false
          device: Front Porch MotionSensor - Front Porch
        - type: or
          conditions:
            - type: device.state.Online
              state: online
              is: false
              device: Icicles Left - Holiday
            - type: and
              conditions:
                - type: device.state.Online
                  state: online
                  is: true
                  device: Icicles Left - Holiday
                - type: device.state.OnOff
                  state: on
                  is: false
                  device: Icicles Left - Holiday
    actions:
      - type: device.command.OnOff
        on: false
        devices: Front Porch Steps - Front Porch
      - type: device.command.OnOff
        on: false
        devices: Front Door Lamp Left - Front Porch
      - type: device.command.OnOff
        on: false
        devices: Front Door Lamp Right - Front Porch

 

adriangalbincea
Community Member

I created a script that will play sound on a device in the house when I am away and the Sensor is open.

The issues I have are. It is very delayed and sometimes does not trigger and set volume on device does not seem to work. Media shuffle resume is temperamental too.

What I am trying to achieve is to start music on a few devices when the alarm is triggered.

Below is the script.

# ------------------------------------------------------------------------------------------ #
# Any line that starters with "#" sign is a comment and gets ignored.
# Indentation (i.e. Number of spaces before each line) is used to decide information hierarchy.
# To populate the template, please follow instructions listed via comments in this template.
# To learn more, please visit g.co/home/scripts for full documentation.
# ------------------------------------------------------------------------------------------ #

metadata:
name: Alarm Front Door # Update automation name e.g. "Movie time"
description: Scripted automation # Update automation description

automations:
# Update "starters", "actions" and optionally "condition" sections to create an automation
# Duplicate these three sections under "automations" to add more automations in the same script

# ---- STARTERS ---- #
# Starters describe events that should start the automation
# Duplicate "- type" section under "starters" to add more than one starters
# If you add multiple starters, any one of them happening will start the automation
# Automations will run if any of the starters meets the criteria

starters:
# Use Ctrl + Space to get autocomplete suggestions
- type: device.state.OnOff
state: on
# [available operators: is, isNot]
is: true
device: Smart Meter - Generic devices
# ---- CONDITIONS ---- #
# Conditions are optional checks that can limit an automation to run only in certain cases
# If your automations does not require conditions, please completely delete the CONDITIONS section
# To use advance conditions that use logical operators ("and", "or", "not") please visit our documentation

condition:
# Use Ctrl + Space to get autocomplete suggestions
type: home.state.HomePresence
state: homePresenceMode
# [available operators: is, isNot]
is: AWAY

# ---- ACTIONS ---- #
# Actions are performed when a automation starts and all conditions are met
# Actions run sequentially and respect any delay introduced between them
# Duplicate "- type" section under "actions" to add more than one action

actions:
# Use Ctrl + Space to get autocomplete suggestions
- type: device.command.SetVolume # Set the volume of a given device.
devices: Livingroom speaker - Livingroom
volumeLevel: 50
- type: assistant.command.Broadcast
message: The front door has been opened
devices: Livingroom speaker - Livingroom

@adriangalbincea - thanks for the feedback. Do you mind sharing which smart devices / speakers are you using? How often is it working? and what's the latency you are seeing?

Hi @Prafulla, the speaker is Nest mini. The other device used as a trigger is a smart switch(Smart Life).

I did a test today and after 80 seconds was triggered. Very slow...

That's really slow and unexpected. Taking a note for internal investigation. 

I also have an automation that doesn't work with a sensor. The automation is supposed to turn on the lights to my shed when I open the door via a contact sensor on the door. The automation doesn't work at all, not until you open the home app, then it works flawlessly. I noticed when opening the home app all your devices load, I'm guessing that it's because the Google home app doesn't recognize the state of my sensor until the Google home app is open. 

Toner
Community Member

Hi!

The scripting is great. But I tought there would be more starters than only our devices. 

- I'd suggest to have a Weather based starter (Sun, Rain, ...)

- Nest Camera Events Starters (Person detected, Zones, ...)

I'm eager to see those!!

Thanks

Great suggestions.

Beyond device starters there are Assistant voice starter:

starters:
- type: assistant.event.OkGoogle
 
eventData: query
 
is: Movie time # No need to add "Ok Google" to the query here.

Home Presence starter:

starters:
- type: home.state.HomePresence
 
state: homePresenceMode
 
is: HOME

condition:
  type: home.state.HomePresence
 
state: homePresenceMode
 
is: AWAY

Time schedule starter

https://developers.home.google.com/automations/schema/reference/standard/time_schedule_event

Thanks for the feedback @Toner - "Camera events"  are coming very soon as we shared in our announcement (https://www.googlenestcommunity.com/t5/Blog/Create-powerful-automations-with-our-new-script-editor-n...)

 

Weather event starters is another top use case that the team is actively exploring.  

Titof174
Community Member

The weather to know if is necessary or not to open blinds (if too sunny, no open because too hot in the house)

Actually, to control blinds/ curtains it would be more useful to use level of light (usually measured in LUX) from a sensor.

For instance all HUE motion sensor also measure LUX. These values are not available to see in the Google Home app nor the native HUE app itself. But the 3rd party app "Hue essentials" gives you access to level of light measured by the motion sensor.

 

At the moment i have a HUE motion sensor sitting in my window. Once it measures more than 30.000 LUX - which is direct sunlight - it will trigger a lamp to turn on, and when that lamp turns on my blinds/ shutters will close.

This is of course a workaround, and i would obviously be much more happy to be able to create this scenario and automation directly in the Google Home app.

One thing that i dont understand is, why not all sensor data is available in the Google Home app.
I have several Shelly products, and on my Google Nest hub i can access both temperature and humidity data. But in the Google Home app only humidity.
How hard can it be to display the data, when the sensor is providing it?

Same with the HUE motion sensor. They measure both movement, temperature and light level/ LUX. It should not be that hard to make the data available in the Google Home app.....


  

 

 

 

Hi @Toner - Thanks for sharing. We are systematically collecting all ideas here: https://www.googlenestcommunity.com/t5/Home-Automation/Script-Editor-Share-your-ideas-and-vote-on-ot...

May I request you to submit those ideas separately so that others can vote on them? Thanks.

lardo5150
Community Member

Looks like you can't set the volume on Nest Audio, or the JBL Portable Smart Google Speaker.

Nothing happens.  No errors, but the volume never changes.

I have several switchbot devices, and I need to "toggle" some of those.  there is no toggle action.

lardo5150_0-1686867109997.png

 

Prafulla
Googler
Googler

Thanks for the feedback @lardo5150 - We are investigating the volume issue.

 

Re: Switchbot - can you toggle them using Google Home app and not via the script editor? 

yes.  if I set it up to be a on/off button.

Here is an example of having a toggle option AND a repeat.

I am controlling the volume on a receiver that is not smart.

To change to bluetooth, I have to turn "on" and "off" that button to get it to the right input.

Then same thing for volume, I have to keep processing the on and off to get the volume to 30.  A repeat would be good here.

Thanks for the details @lardo5150 - I would love to capture your "repeat" idea and example in this post to allow other users to vote on it too. https://www.googlenestcommunity.com/t5/Home-Automation/Script-Editor-Share-your-ideas-and-vote-on-ot...

jkane001
Community Member

I was looking forward to trying something with my Aqara FP2, using OccupancySensingState as a start state. However, when I tried to do so, using something like the example on that page, i.e.: 

- type: device.state.OccupancySensing
   
device: Desk - Master Bedroom
   
state: occupancy
   
is: OCCUPIED

I found that the editor highlighted the type as not being a valid type, and the script would not save. In fact, if I ctrl-spacebar in "type," that OccupancySensing does not seem to exist. Is the documentation wrong, or is the editor?

Hi @jkane001 - Do you see "Aqara FP2" in your Google Home app but not in the script editor? We are investigating this further but autocomplete / ctrl+space shows options only when your home has devices that can support a given state e.g. OccupancySensingState.  

The Aqara device is in my home app (but shows as "Presence Sensor FP2" on the tile). Having multiple detection zones set up w/ that device, it also has 2 additional motion sensor tiles in Home, one called "Bed" and one called "Desk." In the home app, all three show a "motion detected" or "no motion" status as I am looking at it right now on my device.

I see. Motion sensors are treated differently from Matter occupancy sensors. See these two examples:

  1. Motion triggered lights with motion detection
  2. Motion triggered lights with Matter occupancy sensor

Can you try #1 and use your FP2 as a motion sensor?

Can Nest Protect, Nest Learning Thermostat (Gen 3), and/or Nest Cameras  be used a motion detection sensor?

Not yet but we are actively exploring this. Looks like other users are suggesting it too. Please feel free to to upvote related ideas in the ideas post.

IanSav
Community Member

@Prafulla rather than hiding valid items in the autocomplete why not offer the options but colour them in a different colour, like red, to indicate that the syntax is valid but the option is not currently valid in the current context.  This could allow scripts to be developed and prepared even when the current options may be unavailable at the time of development.

Eurik123
Community Member

Hi

Is it possible to make custom variables 

Hi @Eurik123 - We don't yet but would love to capture your request and use case as a new idea here, if you don't mind sharing. This will allow others to vote as well.  https://www.googlenestcommunity.com/t5/Home-Automation/Script-Editor-Share-your-ideas-and-vote-on-ot...

Diazed
Community Member

The section about variables is documented very briefly.
I would like to see a larger example using variables.

It would also be great to have the possiblity to create variables that are used inside multiple Script Automations.

Is it possible to start audio inside an action? For example my favorite podcast in the morning.
And if so, is it possible to start the podcast on multiple devices?

I only found the setInput action but i guess that means VideoInput for TVs right? 

I am deeply in love with the new possibilities this offers. I am very thankful for all the work that has been poured inside this new feature.  

Hi @Diazed - Variable support is in early stages but I would love to capture your ideas here so that other can vote on it too. https://www.googlenestcommunity.com/t5/Home-Automation/Script-Editor-Share-your-ideas-and-vote-on-ot...

 

Please add one comment per idea in the format suggested in the post. Thanks.

 

Re: your audio question, we do support OkGoogleCommand custom action that allows you to run any Assistant command as an action. See if that helps?