Run a Google Routine
-
Ia am trying to run a Google Routine the same way that we can run Alexa Routines, but when I am creating the Routine I can't use de TriggerCMD command as an activator, I can see it in my device list, but it doesn't show on the valid devices to use as an Activator.
I want to do the same you did with de Lamp example (https://www.youtube.com/watch?v=nrqj-OwDpGE), but with Google Routines, how can this be done please??
-
@Marcos-Raldes,
unfortunately Google Assistant does not offer the ability to activate a routine when something like a doorbell button is pressed. Alexa does, and that's why you're able to run an Alexa routine when one of your TRIGGERcmd commands is triggered.<- Correction, I was wrong about this. You can create routines but you have to use the script editor. See post below.That said, you could run a routine from a python script on your computer if you wanted. I asked the AI Script Assistant to generate a script to do that. This is what it gave me:
AI Prompt: python script on Windows to run a google assistant routine
To run a Google Assistant routine on Windows using Python, you can use the google-auth and google-assistant-sdk libraries. Here’s an example script:
import os import json import google.auth.credentials from google.assistant.library import Assistant from google.assistant.library.event import EventType from google.assistant.library.file_helpers import existing_file # Set the path to your credentials file credentials_file = 'path/to/credentials.json' # Load the credentials from the file with open(credentials_file, 'r') as f: credentials = google.auth.credentials.Credentials.from_authorized_user_info(json.load(f)) # Define the routine you want to run routine = 'Good morning' # Create an Assistant instance with Assistant(credentials) as assistant: # Start the conversation assistant.start_conversation() # Send a text query to trigger the routine response = assistant.send_text_query(routine) # Print the response print(response)
Make sure to replace path/to/credentials.json with the actual path to your credentials file. You can create a credentials file by following the instructions in the Google Assistant SDK documentation.
To run the script, open a command prompt or PowerShell window and navigate to the directory where the script is saved. Then, run the command python script_name.py, replacing script_name.py with the actual name of your script file.
-
@Russ Thank you very much for your quick response!!
Google Assistant actually offers that ability, I have many routines triggered when a light or a Smartplug turns on, that's why I am trying to do this. There must be something that is missing from the Object that the TriggerCMD Command creates for the GA to recognice, maybe you can inquire about it, I am sure many other users will find it very usefull.
In the meantime I will have to learn the basics of Phyton as a workarround.
Thaks again!! Hope that you find the solution to this
-
@Marcos-Raldes, sorry you're right - I see that now. I'm still not sure why the TRIGGERcmd devices don't show up in Home app as a routine (aka Automation) starter option, but you can create routines that work with TRIGGERcmd using Google's script editor, then after it's created you can edit it in the Home app.
I made this video to demonstrate it: https://youtu.be/aP3FAuh291s
Here's my test routine that works for me:
The editor makes it easy to select your devices. You just start typing the name and it brings up a list of your devices that contain those letters.
Your TRIGGERcmd commands will only show up as Google devices if they have the voice field filled in. The computer also needs the voice field filled in, unless it's your default computer (set in your profile).
You'll also need to add your command's Google device to a home and a room before it will work. Long-press the device, then tap the gear in the upper-right, then tap Home (Add to a home).
Notice you specify whether the routine should run when the TRIGGERcmd device is flipped on or off. That's different from Alexa where triggering a command is like a doorbell press that runs the routine.
The state defaults to on unless you send off as the parameter, so you can run Google routines without having to send a parameter when you trigger your commands.
You can also create a routine (aka Automation) that triggers a command. You can use TRIGGERcmd device as a starter or an action but either way, you have to use the script editor to create the routine, not the Google Home app on your phone.
EDIT 10/24/24:
Here's the code for the notepad on -> lamp on example:metadata: name: notepad on -> lamp on # Choose a short name that summarizes important starters and actions, like “Sunset lights”. description: Turn on lamp switch when notepad TRIGGERcmd command is triggered with parameter on automations: starters: - type: device.state.OnOff # The basic on and off functionality for any device that has binary on and off, including plugs and switches as well as many future devices. state: on # Whether a device with an on/off switch is on or off. <code>true</code> if the device is on, <code>false</code> if the device is off. [available operators: is, isNot] is: true device: notepad - Office condition: type: device.state.OnOff # The basic on and off functionality for any device that has binary on and off, including plugs and switches as well as many future devices. state: on # Whether a device with an on/off switch is on or off. <code>true</code> if the device is on, <code>false</code> if the device is off. [available operators: is, isNot] is: false device: lamp - Office actions: - type: device.command.OnOff # Turn the device on or off. # Whether to turn the device on or off. on: true devices: lamp - Office
-
-
@Russ Sorry, I just signed up so I could add more computers. But I have no knowledge of how to create the script to make this work.
Could you make yours available so we can copy and change it on our devices? I tried a few ways, but none of them worked for me to get the app on my PC to do this. Even though I adjusted everything as explained in the video. I think it might have been something in the code. -
@Bruno-Oliveira-0, I just added the code for the notepad on -> lamp on example from the video. I hope that helps.
-
name: ligar abajur auto description: When ligar abajur automations: starters: - type: device.state.OnOff state: on is: true device: ligar abajur - PC condition: type: device.state.OnOff state: on is: false device: Abajur do Escritório - Escritório actions: - type: device.command.OnOff devices: Abajur do Escritório - Escritório on: true
I use this, I really don't know what could be happening
-
@Bruno-Oliveira-0, please confirm these things:
- The ligar abajur TRIGGERcmd device is in the PC room in Google Home.
- The Abajur do Escritório device is in the Escritório room in Google Home.
- You can turn on the Abajur do Escritório device from your Google Home app.
- You can run the ligar abajur command by saying, "Hey Google, turn on ligar abajur" or by toggling it on from virtual device in the Google Home app.
- You want your Automation to turn on the Abajur do Escritório device (the action) when you run the ligar abajur command via TRIGGERcmd with parameter on (the starter), if Abajur do Escritório is currently off (the condition).
Also, how are you running the ligar abajur command via TRIGGERcmd with parameter on? Are you using the TRIGGERcmd website?
I suggest you test using the orange Parameters button where you can enter your on parameter:
Also, please send me a screenshot of your Automation code. I'm curious if it shows a red underline like this or not. If it does, your device is probably not in a room.
Also, please confirm the automation is activated.
I just tested this myself. At first my TRIGGERcmd command's device wasn't showing up in the list because it wasn't in a room. It has to be in a room before it will work. If you change certain things about the command, you'll have to re-add it to the room because the virtual device will get deleted and re-created.
-
@Russ
Yes, I use thisAnd, if I say "Ok Google, run ligar abajur" message pop-up show in my PC ok. But don't light my lamp..
Abajur do Escritório is the lamp and work fine in google homeAnd this is my PC - Google Home
Code screenshot
-
@Bruno-Oliveira-0 said in Run a Google Routine:
"Ok Google, run ligar abajur
Thank you for the screenshots.
I think I see the problem. When you say this, you're not running your command with the on parameter.
"Ok Google, run ligar abajur"You should do 2 things:
- Change Permitir Parametros to true so it will accept the on and off parameters.
- Say, "Ok Google, turn on ligar abajur" so Google will send on as the parameter.
Actually, you should change the Trigger and Voice fields to just "abajur" because "ligar" means turn on, but then you'll also need to update your Automation code to use "abajur - PC" as your device under starters instead of "ligar abajur - PC". Then say, "Ok Google, ligar abajur" to run your abajur command with the on parameter which is what your Automation's starter will be looking for.
-
@Russ Ty.. works for me.. Now, I will try turn off this.. lol