Configure IFTTT automation with numeric ingredient

Hello everyone

what I’m trying to do is to configure Google Home with IFTTT such that if I say “Turn on my oven for X minutes”, IFTTT generate a POST request with the number ingredient and HA gets it and turn on the oven for the specified amount of time.

I was trying to follow this thread here: Sending events from IFTTT to Home Assistant - webhooks broken? but since I’m pretty new at all of this, I really have no idea how to pass the “dynamic” information (the timer) to the switch on service in Home assistant.

I’m pretty sure this is fairly easy for experienced users, but right now to me this is kind of obscure :slight_smile:

Thanks a lot and sorry if something is wrong in my post

Is there any reason you’re not using the Google Assistant integration directly instead of using IFTTT as an intermediary? I don’t have a Google Home, and I’ve never tried to use the Google Assistant integration, but I would think that would work much better for you.

But if you really do want to use IFTTT, then I could probably help you with that. I’ve used it before, and it is a bit confusing.

Hello pnbruckner,
yes there’s a reason. First off I’d like to avoid paying the monthly fee with Nabucasa goet the cloud integration and I’d like to stay away from the “on-prem” integration since it’s not reliable at all and I don’t want to play with it every month or so to get it running. I’ve already configured it but it was a mess and it stopped working all of a sudden. IFTTT with Google assistant integration is way easier to manage and more reliable, but I’d need to understand how I should pass this info to the HA automation.

Ok, fair enough, although I didn’t know that the integration between HA and Google Assistant relied on the Home Assistant Cloud integration. That was not what I expected, but I’ve never used either.

Anyway, basically set up the IFTTT applet to use the Webhooks service to make a web request in the “That” part of the applet. The URL comes from when you set up the IFTTT integration in HA. Set the Method to POST and the Content Type to application/json. Then you can put whatever you want in the Body (but you do need to format it as JSON.) E.g.:

{"action": "turn_on_oven", "minutes": 10}

Now create an automation in HA, something like:

- trigger:
  - platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: turn_on_oven
  action:
  - service: script.turn_on_oven
    data_template:
      minutes: "{{ trigger.event.data.minutes }}"

This is just one way of doing it, but hopefully it gives you an idea of how to get it to work.

Note that the IFTTT HA documentation mostly describes how to send data the other way – i.e., to IFTTT – and doesn’t explain very well how to get, and respond to, events from IFTTT. And the example that is provided is very generic and doesn’t necessarily work well in all circumstances. (I can’t tell you how many times I’ve had to explain this. :frowning:)

Thanks a lot for your reply!! I’ll try this. One thing which is still unclear to me (sorry I’m very new to all this, I told you!) is within the action in the automation. You put service “script.turn_on_oven”, which looks somewhat “custom”, I was more thinking to a way to directly call the service in the automation, like this for example:

service: switch.turn_on
data: {}
entity_id: switch.sonoff_10003ee7e4

but based on what you wrote here I guess I have to build a script and call it like you put in the example, isn’t it?

No, you don’t need to write and use a script. Since you didn’t provide any details about how you turn on the oven in your system, I just used that as kind of a “place holder.” You could write and use a script, but if it’s really as simple as turning on a switch, then I guess there’s no need. On the other hand, where do you use the “minutes” value, which was kind of the whole point of this topic, right???

Right! That’s where I get stuck. Basically the idea is to call the service switch.turn.on, add a delay which corresponds to the minutes value I get from IFTTT and then call the switch.turn.off. Not sure if there’s a better way to accomplish this, but that’s what I had in my mind.

How about:

- trigger:
  - platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: turn_on_oven
  mode: restart
  action:
  - service: switch.turn_on
    entity_id: switch.sonoff_10003ee7e4
  - delay:
      minutes: "{{ trigger.event.data.minutes }}"
  - service: switch.turn_off
    entity_id: switch.sonoff_10003ee7e4

This looks like exactly what I was looking for. I’ll give it a try as soon as I can and let you know. Thank you very much for the help, really.

1 Like

Hello again !

I just finished configuring the automation and it works pretty well!!! That’s awesome! I know it’s such an easy thing, but for me it’s a success ! :slight_smile:

So first off I wanted to thank you again, that was very much appreciated ! Secondly, if I could ask another question, I’d need to know if within the IFTTT JSON I have to use only “accepted values” or I could use something “custom” property. Let me give you an example. When I configured the IFTTT Json, I put an “extra” property like this:

{“action”: “turn_on_oven”, “minutes”: numberfield, “started”: startedat}

This way I was expecting to receive an extra property “started” which I could for example consume in a notification. What I was trying to achieve is to turn off the oven after a certain time and get a notification in the HA app that tells me the time the oven will be turned off basically. I can for sure do this directly in the HA automation, but just for my knowledge, I’d like to know if I can pass information within the JSON without causing errors, when I tried to pass the body request above, the automation was not triggered and I could see an error being logged:

By the way, for everybody’s reference, here’s the code I’m using in the automation. This does what I asked initially, plus send 1 notification to 2 devices which contains the time the oven will be turned off:

- id: '1596096890464'
  alias: Timer forno
  description: ''
  trigger:
  - event_data:
      action: turn_on_oven
    event_type: ifttt_webhook_received
    platform: event
  condition: []
  action:
  - entity_id: switch.sonoff_10003ee7e4
    service: switch.turn_on
  - data_template:
      message: Il forno si spegnerà alle {{ (as_timestamp(now()) + ((trigger.event.data.minutes)*60)) | timestamp_custom('%H:%M') }}
      title: Forno Acceso
    service: notify.mobile_app_mi_9t
  - data_template:
      message: Il forno si spegnerà alle {{ (as_timestamp(now()) + ((trigger.event.data.minutes)*60)) | timestamp_custom('%H:%M') }}
      title: Forno Acceso
    service: notify.mobile_app_mi_a2_lite
  - delay:
      minutes: "{{ trigger.event.data.minutes }}"
  - data: {}
    entity_id: switch.sonoff_10003ee7e4
    service: switch.turn_off
  mode: restart

You can have nothing, or whatever you want. It all depends on what you’re trying to do in your system. Everything provided to you so far, including the example in the docs, and the example I gave you, are just that, examples. But whatever you decide to put in the requests coming from IFTTT, you have to write an automation, or automations, that handle them properly.

Well, read what the error says. The problem is the data you sent was not valid JSON. I.e., the date was not enclosed in double-quote characters. I think you need to use:

{"action": "turn_on_oven", "minutes": {{NumberIngredient}}, "started": "{{DateIngredient}}"}

This is what I would recommend. Always include an “action.” Make up values for different types of messages/requests you want to send to HA, where each corresponds to a HA automation that receives and processes it. That way each type of action can have whatever set of other data that makes sense for it. So you might have:

{"action": "turn_on_oven_in", "minutes": {{NumberIngredient}}}

and

{"action": "turn_off_oven_in", "minutes": {{NumberIngredient}}}

and

{"action": "turn_off_oven_now"}

etc.

Got it. Sorry I’m missing here knowledge of the Json formatting and web request, so that’s why I ask these silly questions :slight_smile:

Anyway, thanks to you I managed to get my automation working very well and the way I wanted !

Many many thanks !