IFTTTs, webhook, automations

Hello! I´m new to this but I´ve been doing an awesome project(so I thonk). I´m using H-A on an raspberry pi to control my Xiaomi roborock v2.

I´ve managed to set upp everything with duckdns, portforward and so on and also managed with IFTTTs and webohook make a command to “zone clean” a specific area(living room).

In the body of the “make a web request” i have the following code:

{ “action”: “call_service”, “service”: “vacuum.send_command”, “entity_id”: “vacuum.bellman” }

And in the configuration.yaml file I have this code:

automation:
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    service: vacuum.send_command
    data: {"entity_id": "vacuum.bellman", "command": "app_zoned_clean", "params": [[22800,25100,27700,28600,1]]}

When I say “clean the living room” the ifttt activate the zone clena of my living room. The think I now want to do is to make 4 simular setups for kitchen, bedroom, hallway and bathroom.

What should I add in the body of webhook and the code in configuration so I can call specifik automations?

Or is it better to make a script 4 every room and then make 4 ifttts that call the different scripts?

Could someone hlp with the roght code for the body in the ifttts and right scriptcode in scripts.yaml ?

So I did scripts instead like this:

clean_kitchen:
alias: “Vacuum the kitchen”
sequence:
- service: vacuum.send_command
data: {“entity_id”: “vacuum.bellman”, “command”: “app_zoned_clean”, “params”: [[22800,25100,24000,26500,1]]}

clean_livingroom:
alias: “Vacuum the living room”
sequence:
- service: vacuum.send_command
data: {“entity_id”: “vacuum.bellman”, “command”: “app_zoned_clean”, “params”: [[22800,25100,27700,28600,1]]}

clean_bedroom:
alias: “Vacuum the bedroom”
sequence:
- service: vacuum.send_command
data: {“entity_id”: “vacuum.bellman”, “command”: “app_zoned_clean”, “params”: [[22800,25100,27700,28600,1]]}

clean_hallway:
alias: “Vacuum the hallway”
sequence:
- service: vacuum.send_command
data: {“entity_id”: “vacuum.bellman”, “command”: “app_zoned_clean”, “params”: [[22800,25100,27700,28600,1]]}

clean_bathroom:
alias: “Vacuum the bathroom”
sequence:
- service: vacuum.send_command
data: {“entity_id”: “vacuum.bellman”, “command”: “app_zoned_clean”, “params”: [[22800,25100,27700,28600,1]]}

I know the coordinates are the same right now. Just want to make it work, then I can map out new coordinates. If i run the scripts from overview in H-A they work. And the kitchen makes a diffrent zone than the rest.

The thing now is though that ifttt commands doesnt trigger the script. Maybe it´s this part thats missing:

trigger:
platform: event
event_type: ifttt_webhook_received
event_data:

Or you have any tip on what to add to make the script work? Also what to add in the body of the ifttt webhook

1 Like

Maybe I´m thinking backwards… Maybe there should only be one code in automation, like this:

automation:
-alias: ‘Execute IFTTTT commands to vacuum’
trigger:
platform: event
event_type: ifttt_webhook_received
event_data:
action: call_service
action:
service_template: ‘{{ trigger.event.data.service }}’
data_template:
entity_id: ‘{{ trigger.event.data.entity_id }}’

Then the body of the iftttt includes the “trigger.event.data.service” and “trigger.event.data.entity_id” like:

{ “action”: “call_service”, “service”: “vacuum.send_command”, “entity_id”: “vacuum.bellman”, “command”: “app_zoned_clean”, “params”: [[22800,25100,27700,28600,1]] }

Am I on the right path with this now?Or should the body trigger one of the above scripts instead? Like this:

{ “action”: “call_service”, “service”: “script.turn_on”, “entity_id”: “script.clean_kitchen” }

I´n my head the IFTTT sends a command to H-A. The automation recieves the command inside H-A and executes the command recieved från IFTTT?

have a look at Use variables in Google Assistant input command for Chromecasting via HA - might be helpful

Thanks for reply! I´ve read a lot in the forum and it seems like i should ad this automation:

automation:
trigger:
platform: event
event_type: ifttt_webhook_received
event_data:
action: call_service
action:
service_template: ‘{{ trigger.event.data.service }}’
data_template:
entity_id: ‘{{ trigger.event.data.entity_id }}’

And den in the ifttt webhook body use this:

{ “action”: “call_service”, “service”: “script.turn_on”, “entity_id”: “script.clean_kitchen” }

And it should activate that script.

The problem I have is that wen I add that automation to the configuration.yaml the hassio wont start after reboot. I´ll try add it to automations.yaml in the afternoon instead and see if it´ll bot and if it´ll work after that. Also maybe its because I have automation: in the code.

I´ll try the following code in automations.yaml :

¨ - alias: ‘Execute IFTTT request’
trigger:
platform: event
event_type: ifttt_webhook_received
event_data:
action: call_service
action:
service_template: ‘{{ trigger.event.data.service }}’
data_template:
entity_id: ‘{{ trigger.event.data.entity_id }}’

And after that see if I can activate a script with:

{ “action”: “call_service”, “service”: “script.turn_on”, “entity_id”: “script.nameofscript” }

you only need automation: in configuration:yaml

Either as a header for a block or if you want to offload the config to another file:

automation: !include automations.yaml

If you just want to use IFTTT to call a script, do this:

use IFTTT webhook with your chose trigger (Google Assistant Simple Phase in mycase) and call the following URL

https://yourpublicaccessaddress.com/api/services/script/<SCRIPTNAME>?api_password=<password>

(without the <> )

This is using the old password API, which is on the way out.

Thanks for reply!

Yes, I actually got it to work last night!

I skipped the “new way” and added a api_pasword: password under http: in configuration.yaml

Then in ifttt url i used:
https://uniqid.duckdns.org:8132/api/services/script/vacuum_bedroom?api_password=**password**

Method: POST
Body:

To claryfy, left body empty.

I know it´s on the way out, så long term i need to sort why the automation suggested not onlye doesn work but “brick” hassio. This one:

-alias: ‘Execute IFTTT commands’
trigger:
platform: event
event_type: ifttt_webhook_received
event_data:
action: call_service
action:
service_template: ‘{{ trigger.event.data.service }}’
data_template:
entity_id: ‘{{ trigger.event.data.entity_id }}’

With this in the body:
{ “action”: “call_service”, “service”: “script.turn_on”, “entity_id”: “script.clean_bedroom” }
And the webhook url given from hassio. Should it be:

-alias: "Execute IFTTT commands"
trigger:
platform: event
event_type: ifttt_webhook_received
event_data:
action: call_service
action:
service_template: "{{ trigger.event.data.service }}"
data_template:
entity_id: "{{ trigger.event.data.entity_id }}"

The difference beeing the ´ and “”.

1 Like

first issue - in your actual code do you have additional spacing that isn’t shown above? If not, nothing will work. To be blunt - indents are super important in yaml - screw them up, and nothing works as your expect. It is incredibly sensitive to spacing.

second, I would remove the service component of the webhook and put it direct in the automation - at least to start with, and thus reduce the number of things to check

Finally - there is a difference between the various quotes. You want ’ not the directional `and the opposite of it (I can’t get it on my keyboard)

I dont think so. I copy the text directly from:

And then i replace “automation:” with "- alias: “Execute IFTTT commands” since “automation:” is not needed in the automations.yaml

To “finish” this post. I´ve fixed it.

In the automations.yaml use this code:

- alias: Recieve information from IFTTT
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'

You dont need the “automation:” if it´s in the automations.yaml file.

In the ifttt webhook URL you should use the line you get when integration ifttt in hassio. Looks like:
https://MY-DOMAIN.duckdns.org:8123/api/webhook/YOUR_UNIQ_CODE

The thing i missed is than in configuration.yaml you need to put a code to. Like this:

ifttt:
key: YOUR_API_KEY

I missed what this code was buy YOUR_API_KEY is found by viewing the Settings of the Webhooks applet. It’s the last part of the URL (e.g., IFTTT Maker Webhooks) you will find under My Applets > Webhooks > Settings .

Then you use this code in the body of the webhook:

{ “action”: “call_service”, “service”: “script.turn_on”, “entity_id”: “script.NAME_OF_SCRIPT_TO_RUN” }

3 Likes

Hej Rickard,

I have tried to do the same as you, but Webhooks always says “Unable to make web request: Error: ETIMEDOUT”. My setup:

configuration.yaml:

ifttt:
  key: My_Key

automations.yaml:

- alias: IFTTT Automation
  trigger:
    - platform: event
      event_type: ifttt_webhook_received
      event_data:
        action: 'call_service'
  action:
    - service_template: '{{ trigger.event.data.service }}'
      data_template:
        entity_id: '{{ trigger.event.data.entity_id }}'

Webhooks:
URL: https://My_DNS.duckdns.org:8123/api/webhook/xxxxx
Method: POST
Content Type: application/json
Body: { “action”: “call_service”, “service”: “script.turn_on”, “entity_id”:“script.My_Script” }

What am I doing wrong? :upside_down_face:

Hello … same issue for me.

have you found the solution ??

Sorry for late response… No, I gave up :sob: But hopefully I will take a look at again some time. If you find some solution, please share it with me :blush:

Hello,

You must just call service, like this :
Body: { “action”: “call_service”, “service”: “script.My_Script” }

This is my first post and my second day with Home Assistant.

Finally got it to work. Executed the vacuum.locate service successfully from IFTTT using google assistant.

If you have set up port forwarding correctly, You need to take off the port number from API URL you give in IFTTT.

Here is the Body of my request. You need not have a script.

URL : https://My_DNS.duckdns.org/api/webhook/xxxxx
Method: POST
Content Type: application/json
Body: { “action”:“call_service”, “service”:“vacuum.locate”, “entity_id”:“vacuum.my_vacuum_name” }

I’m trying to set this up (using HA Cloud), what do I put at the end of the URL where you have the ‘xxxx’. Above in post 11 it seems I need a ‘unique code’. Where do I get that from? Is this the same as my ifttt api key?

the opposite - this is the HA Key to use in IFTTT.

To set it up, go to the integrations page in the configuration screen and find IFTTT. Click on configure. Follow the instructions on the screen to configure IFTTT.

Thank you! I kind of skimmed over that and got caught up when I saw the config.yaml entry for ifttt… The integration was nice and easy to do. Luckily I copy /pasted the info that comes up when setting up the integration because it seems you never get to see it again…

Hi,
“Vacuum.locate” works but for some reason the “vacuum.send_command” service does not work. Could you test if this one works on your ha?