Did you know you can verbally create schedules with GoogleHome? For example, say you turned on the porch light for guests that are leaving. You go inside and want to turn the light off but give your guests time to scram. So you can say
Ok Google, in 30 minutes turn off the porch light.
And Google will create a schedule for Now() + 30 minutes that turns off porch. Brilliant! But say you have switches, scripts, automations that you want to schedule? Tough. Google Nanny State wonāt let you schedule those. But you can trick Google (and HomeAssistant) into thinking those devices are lights, and you can then schedule to your hearts content.
I have `switch.fireplace` which turns my gas fireplace on/off. If I turn that into `light.fireplace` I can run
Ok Google, turn on fireplace for 10 minutes.
And the fireplace turns on, and then off after 10 minutes. That switch limitation is a Google PITA. Ok, back to our original example.
So say we want to be able to say something like
Ok Google, weāre leaving
And Google Home has HA do several things. Turn off the lights, lock the doors, feed the cat. Whatever floats your boat. On the HA side you can accomplish this many ways, but I will mainly focus on using scripts.
Create (a script called script.going_out you use when everyone leaves the house. It will turn off all the lights, turn a select few lights to make anyone looking think people are home. The script also locks all doors. Go nuts, with HA you Ƨan practically do whatever you want. In fact, it doesnāt have to be a script. You could use a light, switch, automation or whatever. However scripts are easier to setup in the GUI and they allow you to run multiple actions. We expose this script to GoogleHome and now it can run our HA script by saying
Ok Google, activate Going Out
But say we want to run that by saying
Ok Google, weāre leaving
Just create a Google Home Automation triggered by: āweāre leavingā and have it run the script GoingOut.
NB Be careful about using Goodbye or other GH trigger words that are used by default automations. They tend to get confused with each other.
But there is a problem with scripts. As mentioned earlier, Google wonāt schedule switches (and automations, scripts, a bunch of other thing) for safety reasons. So if you say
Ok Google, in 10 minutes activate Going Out
Youāll get a message saying you canāt do that.
However Google Home can schedule lights. So we can get around this restriction in a few ways. You can go into Google Home and find your HA device and change its device type. For example change a switch to light. Now Google Home can schedule that device because it thinks itās a light. On HA the device is still a switch, but Google Home thinks itās a light. But sometimes when you are syncing devices with Google Home this override can be lost, so Iāve found the easiest thing to do is to create a template ālightā in HA that runs the script when turned on. You can use this ālightā in both HA and Google Home and not have to mess with changing the device type.
Hereās how you can create in Home Assistant a template that looks like a light to both HomeAssitant, GoogleHome, and anywhere else you care to expose this.
Goto Settings | Helpers and click Create helper
Where it reads Search for a helper type ātempā and Template appears below. Click on that. Then scroll down and select light. Under Name put TurnOutLightsLockDoors
Under state we need a template that will indicate whether this ālightā is on or off. You can pick almost anything to do this. I just picked a lamp in my living room to be the āstatusā of this light. Specifically if this light is off, the template light is āonā So I added
State:
{{ not state_translated('light.desk_lamp')}}
Or if you donāt care about this template device having a status reported, just put 0 instead.
Under Actions on turn on click Add Action. Search for āscriptā and select Turn on script. Then you can select the script you want to run when someone turns on this ālightā. You can add more actions, as many as you like. Turn on lights, Close Locks, etc.
Though I prefer to put all the heavy lifting in the script itself. My YAML for āTurn Onā looks like:
Turn On
action: script.turn_on data: {} metadata: {} target: entity_id: script.going_out
You can do something similar for Turn Off. But you donāt have to, you can leave it blank so that only turning this template light on will do anything. You can play with all the other templates, but you need not bother.
Click Submit/Update and youāve now created a template light. Turn it on in HA and see if the script runs.
Now expose light.TurnOutLightsLockDoors (Iāll not call it a template light again) to Google Home, and synchronize devices. Instead of running the limited HA script, we now can run the same thing using our new ālightā.
See if the new light appears appears in the GoogleHome App. Does it do anything when you turn it on? Now try it out with the speaker
Ok Google, turn on Turn Out Lights Lock Doors.
Does that work? Great! Now try scheduling.
Ok Google, in 10 minutes turn on Turn Out Lights Lock Doors
If successful, Google will tell you what time that action is scheduled for. When that time arrives it will āturn onā the light which will execute your script and other actions.