Google Mail
The Google Mail integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] allows you to connect your Google Mail to Home Assistant. The integration adds an action to allow you to set an email auto-response for when you go on vacation. A notify action is also added, allowing you to draft or send emails in plain text.
Prerequisites
You need to configure developer credentials to allow Home Assistant to access your Google Account. These credentials are the same as the ones for Nest and Google Sheets and YouTube. These are not the same as Device Auth credentials previously recommended for Google Calendar.
Scenario 1: You already have credentials
In this case, all you need to do is enable the API:
- Go to the Google Cloud console Gmail API .
- Confirm that the correct project is selected, then select Enable.
- Continue with the steps described in the Configuration section.
Scenario 2: You do not have credentials set up yet
In this case, you need to generate a client secret first:
To generate client ID and client secret
This section explains how to generate a client ID and client secret in the Google Cloud console.
- Go to the Google Cloud console.
- Select Create or select a project, then New project, enter a project name, and select Create.
- When the project opens, make sure it is selected in the console toolbar at the top. If it isn’t, select it.
- Go to Gmail API , then select Enable.
- Go to the Branding page in the Google Auth Platform Console.
- If Google Auth Platform is not configured, select Get started:
- Under App Information, enter an app name (for example, Home Assistant) and select your email address for User support email. Then select Next.
- Under Audience, select External, then select Next.
- Under Contact Information, enter your email address, then select Next.
- Review the Google API Services User Data Policy. If you agree, select the check box, then select Continue and Create.
- In the left sidebar, select Branding:
- Under App domain, enter
https://home-assistant.iofor Application home page, Application privacy policy link, and Application terms of service link. - Under Authorized domains, add
home-assistant.io.
- Under App domain, enter
- In the left sidebar, select Audience:
- Under Publishing status, select Publish app.
Otherwise, your credentials will expire every 7 days.
- If you leave the app in Testing, under Test users, select Add users, add your Google Account email address, then select Save.
- Under Publishing status, select Publish app.
- In the left sidebar, select Clients:
- Select Create client.
- For Application type, choose Web application and give the client a name (for example,
Home Assistant Client). - Under Authorized redirect URIs, add
https://my.home-assistant.io/redirect/oauth, then select Create.Note: This is not a placeholder. It is the URI that must be used.
- From the resulting dialog, take a note of the Client ID and Client Secret. You cannot retrieve it again after closing the dialog.
- Once you have noted these strings, select Ok to close.
- Congratulations! You are now the keeper of a client secret. Guard it in your treasure box. In most cases, your new credentials will be active within a few minutes. However, Google states that activation may take up to five hours in some circumstances.
Configuration
To add the Google Mail service to your Home Assistant instance, use this My button:
Manual configuration steps
If the above My button doesn’t work, you can also perform the following steps manually:
-
Browse to your Home Assistant instance.
-
In the bottom right corner, select the
Add Integration button. -
From the list, select Google Mail.
-
Follow the instructions on screen to complete the setup.
The integration setup will next give you instructions to enter the Application Credentials (OAuth Client ID and Client Secret) and authorize Home Assistant to connect to Google Mail.
OAuth and device authorization steps
-
Continue through the steps of selecting the account you want to authorize.
-
NOTE: You may get a message telling you that the app has not been verified and you will need to acknowledge that in order to proceed.
-
You can now see the details of what you are authorizing Home Assistant to access with two options at the bottom. Select Continue.
-
The page will now display Link account to Home Assistant?, note Your instance URL. If this is not correct, refer to My Home Assistant. If everything looks good, select Link Account.
-
You may close the window, and return back to Home Assistant where you should see a Success! message from Home Assistant.
Sending emails
The notify action added by this integration is named after the email address you chose on the consent screen. For example, an email address named “example@gmail.com” will display as notify.example_gmail_com.
The following attributes can be placed inside the data key of the action for extended functionality:
-
cc: List of recipients to be carbon-copied. -
bcc: List of recipients to be blind-carbon-copied. -
from: Defaults to the current authenticated user. Typically only applies to Google Workspace accounts where the user has delegate access to a shared mailbox. -
send: Defaults totrue. Set this tofalseto create a draft instead. Recipients are not required in this case. -
alias_from: Name that is shown to the recipients instead of your email address. To use this option, you must also setfrom.
This is the full action to send an email:
action: notify.example_gmail_com
data:
message: "test"
title: "test email"
target:
- "example2@gmail.com"
data:
cc:
- "example3@gmail.com"
bcc:
- "example4@gmail.com"
from: "example@gmail.com"
alias_from: "Example alias"
List of actions
The Google Mail integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following actions. Each link below opens a dedicated page with examples, parameters, and a step-by-step UI walkthrough.
-
Set vacation (
google_mail.set_vacation) Sets the vacation auto-responder for a Google Mail account.
For an overview of every action across all integrations, see the actions reference.
Video tutorial
This video tutorial explains how to set up Gmail in Home Assistant and how you can create a dashboard and automations to send email and toggle your out-of-office notice.
Troubleshooting
If you have an error with your credentials, you can delete them in the Application Credentials user interface.