Adding a condition in the Action section

Hi Everyone,

I configured a webhook to pass my Skylink Door Sensor trigger to Hassio and turn on a light when the door is open and turn off the light 5 mins AFTER the door is closed. I cannot figure out how to add the delay.

The ifttt webhook body for door open is:

{ "action": "call_service", "service": "light.turn_on", "entity_id": "light.side_entrance_light" }

The ifttt webhook body for door is closed:

{ "action": "call_service", "service": "light.turn_off", "entity_id": "light.side_entrance_light" }


To automation configuration for in Hassio is as follows:

=======================

- id: '1574110420946'
  alias: Webhook Receiver
  description: ''
  trigger:
  - event_data:
      action: call_service
    event_type: ifttt_webhook_received
    platform: event
  condition: []
  action:
  - data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'
    service_template: '{{ trigger.event.data.service }}'

=======================

The only place I can think of making this work is if there is a way in the action I can look for the light.turn_off and add the delay.

Can someone please help? I am not a developer :frowning: Thank you for all your help

Yes this is possible but you need to use the </> to format your code, we can’t read it as is

apologies. is it readable now? thanks,

I don’t understand your trigger but I’ll take your word for it

- id: '1574110420946'
  alias: Webhook Receiver
  description: ''
  trigger:
  - event_data:
      action: call_service
    event_type: ifttt_webhook_received
    platform: event
  action:
  - delay: '00:05:00'
  - service: light.turn_off
    entity_id: light.side_entrance_light

Re-Reading your post I assume the trigger quoted is the door now closed, so you shouldn’t need the light.turn_on part as presumably it’s already on

Edit: summary of thread; ifttt will provide a trigger, but it’s meaningless unless you read the payload (I didn’t above) see mo’s solution at the end for circumventing this.

That is correct. Basically when I enter the house through the side entrance I want the light to turn on. and then when I close the door behind me, I want the light to turn off after 5 mins. Those are the two triggers for me from IFTTT. I have to use IFTTT because there is no integration for skylink in Hassio.

Okay, I’ve deleted the unnecessary turn on bit.
Give it a whirl and feedback if it works or not

No wait…I don’t think that will work. The way I understand it is in the webhook 1 (when the door opens, turn on light) it is sending the service variable "service": "light.turn_on" and in the webhook 2 (when the door closes, turn off light) it is sending the service variable "service": "light.turn_off".

In my existing code I read this variable to take the approporiate action. service_template: '{{ trigger.event.data.service }}'

But in your code, any trigger on the event_type: ifttt_webhook_received would turn off the light after 5 mins, right?

I basically want, if the sensor is active (door is opened), the light goes on. and if the sesor goes back to normal (door closed), the light goes off after 5 mins of closing the door.

What really needs to happen is that when I read this service variable sent from IFTTT, I have to take action based on that. if it is the “off” service i have to add 5 mins delay.

That’s what you have,
I assumed you had already successfully set up the light turn on bit

You need two automations, one to turn the light on and the other to start the timer and turn it off

I agree with you on the two automation. But how do I do that setup? What would I send from the webhooks? what do I put in the body of the ON webhook and OFF webhook to differentiate them? I followed the instructions from here: https://www.home-assistant.io/integrations/ifttt/

and those instructions allow to send all the data required to trigger the automation.

from what I am understanding you are saying is that maybe just send trigger words from webhook 1 and 2 and catch those in the automation 1 and 2 somehow.

Can you please point me in the right direction on how I can do this?

No, I don’t use ifttt but from what I’ve read you can publish to ifttt which will then talk to some of your iot devices “open the garage door”
Similarly they can tell ifttt that the garage door is closed
So the garage door opening triggers the light going on and the closing triggers the delay and off.
I must have missed something here let me read the who thread again

Okay, I’ve skimmed the IFTTT docs.
Your original code was as per the docs and completely useless to you needs.
The reason being that these are direct service calls set to use a generic handler operate on multiple devices and as such it has to operate as and when it’s received.
Far better would be triggers into different automations (well they’d all get it but we can filter) and then act specifically ie delay then off.
The calls seem flexible enough
Someone with actual experience of this may come by in the next 5 mins and solve this, I on the other hand have to go to bed AND think about this. It looks like it will have to parse the payload, test against expected and trigger the appropriate script. Hmmmmm !

Just seen another thread : IFTTTs, webhook, automations. I’ll read it in the morning

Thank you very much! Love that you will be thinking about this in your sleep! :smiley: I will also do some reading. Learning about templates etc…Maybe this will kick start my training into scripting…

Ok I figured this out…not sure if this is the best way of doing this but it is working…

for the turning off the light that requires a delay I created the following script.

'1574134228113':
  alias: Turn Side Entrance Light Off
  sequence:
  - delay: '00:05:00'
  - service: light.turn_off
    data:
     entity_id: light.side_entrance_light

Then in the webhook for sensor becoming normal (when I close the door), I put the following in the body:

{ "action": "call_service", "service": "script.turn_on", "entity_id": "script.1574134228113" }

The light turning on webhook remains as is.

{ "action": "call_service", "service": "light.turn_on", "entity_id": "light.side_entrance_light" }

so basically, since the turn on trigger does not require any delay, i am passing the service call directly. and for the turn off to day the delay I am using to call a script instead.

If there are better ways to do this, please reply with it. This stuff is exciting!

That’s as good as what I was going to suggest.
I was going to suggest creating an input boolean turning it on from ifttt when the door opens and using the input boolean turn on as a trigger for the light (bear with me I’ve not finished, as I know you can do this directly)
BUT
getting the garage door closing to turn off the input boolean which can trigger your delay.

Your way is better as it just creates a script, my way would need an input_boolean AND an automation (less is MORE :smile:)

AND you solved it yourself, how good is that!

Please mark your thread as self-solved (actually true in this case), it will help others

sounds good!!! I am also reading more and it seems like there is a way to create binary sensors using ifttt. If that is the case then a better approach would be to create binary sensor for the door and use that for automation of state change. that will also give me a sensor status of the door in HA.