How to Integrate Google Assistant and Home Assistant API using only IFTTT

#How to Integrate Google Assistant and Home Assistant API using only IFTTT

Preamble

Hey all.
Been working on my Home Assistant set up for a couple of months now and would like to contribute a little something back.

Here is how you can use Google Assistant on Android with Home Assistant HTTP API calls.

##Requirements

  • Dynamic DNS entry for your Public IP address

    • e.g. DuckDNS or similar
  • IFTTT (If This Then That) account

  • Android phone with Google Assistant

  • Port forwarding for your HTTP/HTTPS Home Assistant web interface for API calls

Steps

  1. Integrate IFTTT into Maker Webhooks
    a. Log into IFTTT
    b. Click Search
    c. Look up Maker Webhooks and select it
    d. Click Connect
    e. Connect with Maker Webhooks and follow any prompts
  2. Integrate IFTTT into Google Assistant
    b. Click Search
    c. Look up Google Assistant and select it
    d. Click Connect
    e. It should prompt you to associate with a Google Account (obviously, associate with the same one your Google Assistant is hooked in with).
    If not, click on Settings and click Edit Connection to choose an account, and then Allow.
  3. Make the recipe!
    a. Click My Applets on the top of the screen
    b. Click New Applet
    c. Click This and search for Google Assistant
    d. Click Say a simple phrase (you can experiment with the other kinds later!)
    e. Add a simple phase to say, e.g.

    f. Click Create trigger
    g. Click the blue word that
    h. Search for Maker Webhooks and select it
    i. Click on Make a web request
    j. Fill in the details as follows:
  • URL: https://your-hass.duckdns.org/api/services/light/toggle?api_password=
    • Note I use HTTPS. but you might be using HTTP, change the URL to be http:// instead of https:// as required.
    • You may use a Public IP address instead of a domain name if you do not have one.
    • You might need to add the port number allowable on your router, for example if you are forwarding 9876 to your internal port of 8123, then your URL would be : https://your-hass.duckdns.org:9876 accordingly.
    • Naturally, complete the URL with your API password if one is set (and it should be!)
  • Method: POST
  • Content Type: application/json
  • Body: {"entity_id":"light.kitchen_light"}
    • Replace the body with whatever is relevant for you. Best place to go is the Services section of Developer Tools on your front end to find out the right query.
  • Should look something like this:

    k. Click on Finish
  1. Now go on and trigger your script by calling Google Assistant and saying your phrase!
  • I had to restart my phone before Google Assistant started forward requests to IFTTT
  • If it fails, have a look at My Applets > Activity for a hint as to why

Good Luck!

13 Likes

Thanks for such a deep tutorial. However, Iā€™ve been investigating and it seems using IFTTT is not ideal for lights, as an example, because of a short delay. Have you noticed any lag?

This is exactly how Iā€™ve been integrating my Google Home with Home Assistant. :slight_smile: FWIW, this works with pretty much every service that HA exposes, including custom scripts. You just need to send a body along with the request which includes any arguments that are required (or that you have defined), for example:

http://my-home-assistant-instance:8123/api/services/script/play_movie?api_password=my_password 

{"entity_id": "script.play_movie", "movieTitle": "Big Buck Bunny"}
1 Like

I guess acceptable delay is a little subjective, but after I get positive feedback from Google assistant that IFTTT intercepted, it takes a second or two to activate my light. Is yours much longer than that?

The delay seems to be reasonable from the IFTTT side, google assistant varies it seems. Seems that I canā€™t IFTTT to send the packets. syslog and access.logs show not attempt try trying the IFTTT webhook manually.

If I try to do the request local, it works. I tried with a http request from https://www.hurl.it/ and that works fine too.
IFTTT documentation is lax, and found a couple results that the ssl certificate is not validated by IFTTT.

running nginx with letsencrypt ssl with certificate based auth and failback basic auth expect for /api

Rookeh, could you share your play_movie script? Iā€™m trying to do something similar from IFTTT ā€¦ calling a script with another variable, but I am not sure how the syntax works in the script. Thanks.

Thanks for the quick response. Actually, I still havenā€™t decided whether to buy a Google Home or not. This delay seems too much for me and Iā€™m testing Google Now + Tasker in the meantime.

@Smith, sure, Iā€™ll post my script config when I get home tonight.

Edit: This is the config for my play_movie script:

play_movie:
  alias: Play Movie
  sequence:
  - service: shell_command.play_movie
    data_template:
      movieTitle: '{{movieTitle}}'

This in turn calls a shell command which passes the movie title as an argument to a python script that contains all of the logic to find and play the movie. That command is defined in the config as follows:

play_movie: python3 /home/homeassistant/.homeassistant/scripts/playMovie.py {{movieTitle}}

(As I look back at this it occurs to me that I could probably simplify this logic by just calling the shell command directly without needing the script - this was probably the first thing I attempted to set up in HA though so youā€™ll have to excuse the inefficiency!)

Anyway, HTH. :slight_smile:

Thanks, this helps.
@fanuch, I also experience some delay in Google Assistant / IFTTT / HA calls, but they work well.

This is another way of doing it :slight_smile: :

Hi
How can I get the recognized word about Google assistant Forwarding via a webhook??
I ask for help.

http://[email protected]:[email protected]:11111/api/globalVariables/test

Body = { ā€œvalueā€: ā€œRecognized wordā€, ā€œinvokeScenesā€: true }

Can someone please give me a tip.

Take a look at the link that I posted above, if you still have troubles Iā€™ll explain in detail :slight_smile:

using IFTTT, would it be possible to retrieve information from a sensor?

for example, finding out home temperature from a zigbee/zwave sensor?

Thanks

Not using this method.
IFTTT responds with an ā€˜okayā€™ message, and does not forward the response from Home Assistant.

Best to post that as a question in the forum.

1 Like

Thanks for the greatTutorial,

when i have dyndns can is use it to?

is this correct?
http://mydyndns/api/services/light/toggle?api_password=12345678

is this stock? i dint have to change ths?
api/services/light/

can you explain me that? iam very helpless with that, for me its like from another worldā€¦

Replace the body with whatever is relevant for you. Best place to go is the Services section of Developer Tools on your front end to find out the right query.

i have these five lamps which i wanne switch on and off

https://hastebin.com/kodijulavi.go

Thank you very much
Chris

is this correct?

Yes. Make sure that mydyndns is an actual address. (i.e. has .com or whatever you use)

is this stock? i dint have to change ths?
api/services/light/

If you go to services you will be able to see that it says light.xxxx if you are targeting a light. If you are targeting a switch it will be a different call.

Replace the body with whatever is relevant for you. Best place to go is the Services section of Developer Tools on your front end to find out the right query.

These are instructions you can follow. If you can toggle your light/switch from this page, you will be able to find the correct augments to pass.

Perfect Thank you i got everything to workā€¦

Thanks a lot

1 Like

what about google home?

Works too. Just need to make sure you are setting this up on the phone that Google Home is connected to,

hello tks for your tutorial, iĀ“m very noobie on this, i was already able to setup my broadlink with home assistant, and iĀ“m trying to make a webrequest trough ifttt to turn on my tv, but I donĀ“t know how to fill correctly this applet. After service on the url what should I write, switch? also on my services thereĀ“s nothing how should I know wich service should I call? My entity I notice itĀ“s on the dashboard state, and after entoty_id what should I wirte. If anyone can help me IĀ“d be very apreciate.