Example scripted automations

While looking through these examples, be sure to look up any Automation script terms you come across in the left sidebar if the meaning is not clear.

Control a light with a switch

metadata:name:Switch-controlled lightdescription:When a switch is moved to the on position, turn on a light.automations:-starters:-type:device.state.OnOffdevice:Office Switch - Officestate:onis:trueactions:-type:device.command.OnOffdevices:-Christmas lights - Living Roomon:true

Schedule lights and blinds

metadata:name:Nighttime dim lights and close blindsdescription:At 10pm, dim the lights and close the blinds.automations:-starters:-type:time.scheduleat:22:00actions:# Adjusting brightness will automatically turn on the lights.# No need to add a separate OnOff command.-type:device.command.BrightnessAbsolutedevices:-Light - Living Roombrightness:50-type:device.command.OpenClosedevices:-blinds1 - Living RoomopenPercent:0

Control camera based on household presence

metadata:name:Person detection camerasdescription:When the first person comes home, turn off cameras.automations:-starters:-type:home.state.HomePresencestate:homePresenceModeis:HOMEactions:-type:device.command.OnOffdevices:-Camera - Living roomon:false

Vacuum while everyone is away

metadata:name:Empty home vacuumdescription:When the home is unoccupied, run the vacuum.automations:# Turn on robot vacuum when everyone is away-starters:-type:home.state.HomePresencestate:homePresenceModeis:AWAYactions:-type:device.command.StartStopdevices:-VACUUM - LIVING_ROOMstart:true# Turn off robot vacuum when someone is home-starters:-type:home.state.HomePresencestate:homePresenceModeis:HOMEactions:-type:device.command.StartStopdevices:-VACUUM - LIVING_ROOMstart:false

Dim lights and lower blinds when living room TV is on after dark

metadata:name:Nighttime lights and blindsdescription:After dark, when the TV is on, dim the light and lower the blinds.automations:-starters:-type:device.state.OnOffdevice:TV - Living Roomstate:onis:truecondition:type:time.betweenafter:SUNSETbefore:SUNRISEactions:# Adjusting brightness will automatically turn on the lights.# No need to add a separate OnOff command.-type:device.command.BrightnessAbsolutedevices:-Light - Living Roombrightness:5-type:device.command.OpenClosedevices:-Blind - Living RoomopenPercent:0

Cool weather heating

metadata:name:Cool weather heatingdescription:If it is cool, open blinds, turn on fans, and adjust thermostats.automations:-starters:-type:device.state.TemperatureSettingstate:thermostatTemperatureAmbientdevice:thermostat - Family RoomlessThan:18Cactions:-type:device.command.OpenClosedevices:-blinds - BedroomopenPercent:100-type:device.command.OnOffdevices:fan - Bedroomon:true-type:device.command.ThermostatTemperatureSetpointdevices:-thermostat - Family RoomthermostatTemperatureSetpoint:21C

Warm weather ventilation

metadata:name:Warm weather ventilationdescription:If it is warm, close blinds, turn on fans, and adjust thermostats.automations:-starters:-type:device.state.TemperatureSettingdevice:Nest Thermostatstate:thermostatTemperatureAmbientgreaterThan:25Cactions:-type:device.command.OpenClosedevices:-blind1 - Living Room-blind2 - BedroomopenPercent:0-type:device.command.OnOffdevices:-fan1 - Bedroomon:true-type:device.command.ThermostatTemperatureSetpointdevices:-thermostat - BedroomthermostatTemperatureSetpoint:22C

Scheduled lighting with multiple times

metadata:name:Scheduled lightingdescription:Turn on the lights at sunset, dim them at 10pm and turn them off at midnight.automations:# At sunset-starters:-type:time.scheduleat:SUNSETactions:# Adjusting brightness will automatically turn on the lights.# No need to add a separate OnOff command.-type:device.command.BrightnessAbsolutedevices:-Christmas lights - Living Roombrightness:100# At 10 PM-starters:-type:time.scheduleat:22:00actions:-type:device.command.BrightnessAbsolutedevices:-Christmas lights - Living Roombrightness:50# At midnight-starters:-type:time.scheduleat:00:00actions:-type:device.command.OnOffdevices:Christmas lights - Living Roomon:false

Synchronize two lights

metadata:name:Synchronize two lightsdescription:If one light is turned on, turn the other on, and if one light is turned off, turn the other off.automations:-starters:-type:device.state.OnOffdevice:Light A - Officestate:onis:truecondition:type:device.state.OnOffdevice:Light B - Living Roomstate:onis:falseactions:-type:device.command.OnOffdevices:-Light B - Living Roomon:true-starters:-type:device.state.OnOffdevice:Light A - Officestate:onis:falsecondition:type:device.state.OnOffdevice:Light B - Living Roomstate:onis:trueactions:-type:device.command.OnOffdevices:-Light B - Living Roomon:false-starters:-type:device.state.OnOffdevice:Light B - Living Roomstate:onis:truecondition:type:device.state.OnOffdevice:Light A - Officestate:onis:falseactions:-type:device.command.OnOffdevice:Light A - Officeon:true-starters:-type:device.state.OnOffdevice:Light B - Living Roomstate:onis:falsecondition:type:device.state.OnOffdevice:Light A - Officestate:onis:trueactions:-type:device.command.OnOffdevices:-Light A - Officeon:false

Flash lights when smoke alarm is active

metadata:name:Smoke detector lightsdescription:When smoke is detected, flash lights red and blue.automations:-starters:-type:device.state.SensorStatedevice:Smoke Detector - Kitchenstate:currentSensorStateData.SmokeLevel.currentSensorStateis:highactions:# Setting color will automatically turn on the lights.# No need to add a separate OnOff command.-type:device.command.ColorAbsolutedevices:-Light - Living Roomcolor:name:"red"-type:time.delayfor:5sec-type:device.command.OnOffdevices:Light - Living Roomon:false-type:time.delayfor:5sec-type:device.command.ColorAbsolutedevices:-Light - Living Roomcolor:name:"blue"-type:time.delayfor:5sec-type:device.command.OnOffdevices:-Light - Living Roomon:false-type:time.delayfor:5sec-type:device.command.ColorAbsolutedevices:-Light - Living Roomcolor:name:"red"

Turn on air purifier when indoor air quality is poor

metadata:name:Low air quality air purifierdescription:When indoor air quality is poor turn on air purifier at high speed.automations:-starters:-type:device.state.SensorStatedevice:Air Sensor - Living Roomstate:currentSensorStateData.AirQuality.currentSensorStateis:pooractions:-type:device.command.OnOffdevices:-Air Purifier - Living Roomon:true-type:device.command.SetFanSpeeddevices:-Air Purifier - Living RoomfanSpeed:"speed_high"

Nighttime unlock alert

metadata:name:Nighttime unlocking lightsdescription:At night, when a lock is unlocked, turn on the light at full brightness.automations:-starters:-type:device.state.LockUnlockdevice:Front Door - Living Roomstate:isLockedis:falsecondition:type:time.betweenafter:SUNSETbefore:SUNRISEactions:# Adjusting brightness will automatically turn on the lights.# No need to add a separate OnOff command.-type:device.command.BrightnessAbsolutedevices:-Light - Bedroombrightness:100

Flash lights when carbon monoxide detected

metadata:name:Carbon monoxide detection lightsdescription:When carbon monoxide is detected, flash the lights.automations:-starters:-type:device.state.SensorStatedevice:coDetector - Living Roomstate:currentSensorStateData.CarbonMonoxideLevel.currentSensorStateis:carbon monoxide detectedactions:# Only works for lights that support Pulse effect-type:device.command.LightEffectPulsedevices:-Light - Bedroom-Light - Living Roomduration:5min

Motion triggered lights

metadata:name:Motion detection lightsdescription:When motion is detected, turn on the lights, then turn them off after five minutes of stillness.automations:-starters:-type:device.state.MotionDetectiondevice:sensor - Living Roomstate:motionDetectionEventInProgressis:trueactions:-type:device.command.OnOffdevices:-light - Living Roomon:true-starters:-type:device.state.MotionDetectiondevice:sensor - Living Roomstate:motionDetectionEventInProgressis:falsefor:5minactions:-type:device.command.OnOffdevices:-light - Living Roomon:false

Motion triggered lights with occupancy sensor

metadata:name:Occupancy sensor lightsdescription:When an occupant is detected, turn on the lights, then turn them off after five minutes.automations:-starters:-type:device.state.OccupancySensingdevice:sensor - Living Roomstate:occupancyis:OCCUPIEDactions:-type:device.command.OnOffdevices:-light - Living Roomon:true-starters:-type:device.state.OccupancySensingdevice:sensor - Living Roomstate:occupancyis:UNOCCUPIEDfor:5minactions:-type:device.command.OnOffdevices:-light - Living Roomon:false

Turn on cameras when leaving home

metadata:name:Occupancy sensor camerasdescription:Once the home is unoccupied, turn on cameras.automations:-starters:-type:home.state.HomePresencestate:homePresenceModeis:AWAYactions:-type:device.command.OnOffdevices:-Camera - Living Roomon:true

Doorbell light alert

metadata:name:Doorbell light alertdescription:When someone rings the doorbell, blink the lights in occupied room.automations:-starters:-type:device.event.DoorbellPressdevice:Front Door doorbell - Front Doorcondition:type:device.state.OccupancySensingdevice:sensor - Living Roomstate:occupancyis:OCCUPIEDactions:-type:device.command.LightEffectPulsedevices:-light - Living Roomduration:5min

Movie night scene

metadata:name:Movie night blinds, lights, and appliancesdescription:When Assistant hears the utterance "movie night", lower the blinds, turn off the lights, and pause certain noisy appliances.automations:-starters:-type:assistant.event.OkGoogleeventData:queryis:"MovieNight"actions:-type:device.command.OnOffdevices:-light - Living Roomon:false-type:device.command.OpenClosedevices:-blinds - Living RoomopenPercent:0-type:device.command.PauseUnpausedevices:-washer - Hallpause:true

Home and away lighting

metadata:name:Occupancy sensor lightsdescription:After dark, when someone arrives home, turn on lights, and turn off all lights when the home is unoccupied.automations:# Turn on certain lights after someone gets home after dark-starters:-type:home.state.HomePresencestate:homePresenceModeis:HOMEcondition:type:time.betweenafter:SUNSETbefore:SUNRISEactions:-type:device.command.OnOffdevices:-light1 - Living Room-light2 - Front dooron:true# Turn off all lights when everyone is away during the day-starters:-type:home.state.HomePresencestate:homePresenceModeis:AWAYcondition:type:time.betweenafter:SUNRISEbefore:SUNSETactions:-type:device.command.OnOffdevices:-light1 - Living Room-light2 - Front door-light3 - Bedroomon:false

Send a notification when a package is delivered

metadata:name:Package Delivereddescription:When a package is delivered, send a notification.automations:-starters:-type:device.event.PackageDelivereddevice:Camera - Frontdooractions:-type:home.command.Notificationtitle:Package Deliveredbody:A package is deliveredmembers:-cloudysanfrancisco@gmail.com

When I walk through my corridor first time (motion sensor) in the morning open all my blinds and suppress the trigger for 20 hours

metadata:name:Open blindsdescription:Open blinds in the morning after motion is detected.automations:-starters:-type:device.event.MotionDetectiondevice:Camera - HallwaysuppressFor:20 hourscondition:type:time.betweenafter:5:00before:12:00actions:-type:device.command.OpenCloseopenPercent:100devices:-Blinds1 - Living Room-Blinds2 - Family Room

Send a notification when movement is detected at home on a weekday

metadata:name:Motion at homedescription:Send a notification when movement is detected at home on a weekdayautomations:-starters:-type:device.event.MotionDetectiondevice:Camera - Frontdoor-type:device.event.MotionDetectiondevice:Thermostat - Downstairs-type:device.event.MotionDetectiondevice:SmokeDetector - Upstairscondition:type:time.betweenafter:09:00before:18:00weekdays:-MON-TUE-WED-THU-FRIactions:-type:home.command.Notificationtitle:Motion at homemembers:-cloudysanfrancisco@gmail.com-jeffersonloveshiking@gmail.com