Trigger script from IFTTT

Hi,
I am new to this forum and to Home Assistant.
I have Home assistant up and running on a Mac server and it is working as it should. I have also added support for Verisure in order to get control over my smart plugs. Works fine.
I have external access with the help of port forwarding and that also works fine.
Now I am trying to trigger a script from my android phone with the help of google assistant and IFTTT.
I am able to get IFTTT to run with my voice command but I cannot manage to get it to trigger the script on my Home Assistant instance.
I have external access with the help of port forwarding and that works fine.

I have created a script in Home Asssitant that i called “lampsoff”. When I trigger this from within Home assistant it is working as supposed and turns the light off.
But to get this to work with IFTTT… please help me before I loose all my hair :wink:

I have read several threads without luck.

So what, exactly do I need to type in the configuration of the IFTTT script?

URL:
http://MYIP:8123/SOMETHING?api_password=MYPASSWORD

Method:
POST

Content:
application/json

Body:
{ “entity_id”: “script.lampsoff” } Tried a lot of different things here… :slight_smile:

Thank you in advance for the help!!

Best regards

Per-Henrik

So i have made som changes in IFTTT and the IFTTT (see picture) recipe runs without any errors now. However the script in Home Assistant still does not run. Any idea?

Hi Try

URL:
http://MYIP:8123/api/services/script/lampsoff?api_password=MYPASSWORD

Method:
POST

Content:
text/plain

Body:

Hope it works for you.

Thanks Cameron!
However I get this error message back from IFTTT:
“Unable to make web request: Error: ETIMEDOUT”

So still no luck.

Has any body have any luck figuring this one out yet?

Yes. What exactly do you want the IFTTT Web Request to do in HA? Fire an event? Run a service? Change a state?

Never mind !! Got it to work.

https://URL/api/services/script/scriptname?api_password=PASSWORD

Replace scriptname with your respective script name

Post with content type text/plain

Yes, that will work if you’re not passing any data. But if you need to pass data, you should set Content Type to application/json, and then enter the data (formatted as JSON) in the Body.

1 Like

I wanted IFTTT to ran a script from my Home assistant.

Can anyone help me?

scripts.yaml
‘test’:
alias: test
sequence:
- data: {}
service: rest_command.youtube

configuration.yaml

rest_command:
  netflix:
    url: http://192.168.1.8:8001/api/v2/applications/11101200001
    method: POST
    
  youtube:
    url: http://192.168.1.8:8001/api/v2/applications/111299001912
    method: POST

IFTTT webhooks
https://X.duckdns.org/api/services/script/test?api_password=X

I have tried with :8123,
json with entity_id: test,
text/plain with empty body
port 443 forward to 8123 in my RPi

The script works if i call it from HA…

Thanks in advance

The URL depends on how you’ve exposed HA to the web. What do you use when you want to open the front end in a browser from outside your LAN? The first part (e.g., https://X.duckdns.org:8123/) is the same for both opening the frontend in a browser, and using the REST API from IFTTT webhooks.

Other than that, when you’re calling a service, you need to make sure the IFTTT webhook uses the POST command (not GET. See here.) Otherwise, the rest of the URL looks correct.

BTW, if you’re not passing any variables to the script, Content Type shouldn’t matter (although it doesn’t hurt to set it to application/json), and the Body can be left empty.

I have 443 forwarded to 8123 so I don’t have to use :8123 (I tried thought).

And I am using post and not get. I have tried anything that I can think but I cannot make it work.

So what works when you’re opening the UI in a browser from outside your LAN? Whatever you use for that should be the same as the first part of the URL you use in IFTTT (with api/…&api_password=X appended on the end.) That’s what I use in IFTTT and it works for me.

Have you tried using curl? Even if you’re on your LAN, that URL should get routed outside and then back in through the router. Might be worth a try, especially if you use curl’s -v option.

From outside the lan I use https://x.duckdns.org

Then is /api/services/ and at the end it will be ?api_password=MYPSW

But what should I put in between so I can call the script I mentioned above?

From what you’ve said https://x.duckdns.org/api/services/script/test?api_password=MYPSW should work. Of course, that’s what you originally said you tried. Hmm. I would try using curl with -v. That should give you more details about why it doesn’t work. I.e.:

curl -v -X POST https://x.duckdns.org/api/services/script/test?api_password=MYPSW

OK I’m retarded, I work all day long the last months so I’m tired :stuck_out_tongue:, I thought that by clicking check in ifttt applwr it triggers it, I tried now with the voice command and it worked.
Thanks for your time. Now it’s time to learn how to write scripts and even better how to. Use appdeamon

1 Like