Help with inserting delay into automation

holy crap this should be easy, but i can’t figure it out for some reason.

Scenario:
Trying to add a 5 second delay when an MQTT trigger is received. The below configuration is from my automation file, and HA ignores the delay line. What am I doing wrong here?

- action:
  - data:
      payload: 0
      topic: tub/pump/relay/0/set
    service: mqtt.publish
  - delay: 00:00:05
  alias: Shower ON pump delay
  condition: []
  id: '1523909935563'
  trigger:
  - payload: 1
    platform: mqtt
    topic: shower/touch/relay/0

At a minimum I would put 00:00:05 in quotes. But, I don’t see any action after the delay. So how do you know it’s not waiting the 5 seconds?

1 Like

I’ve tried it with single ‘quotes’ same result. The documentation lists it as both, in different places.
I know it’s not working because tub/pump/relay/0/set 0 never fires.

are you implying that the order of the action is incorrect? as in the delay line should be above the - data?

No. The order is the order you want the two actions to happen in. What I’m saying is you have two actions: 1) MQTT publish, and 2) delay 5 seconds. But there’s nothing after the delay, so why do you have a delay?

If the MQTT publish is not happening, then you should solve that first. I don’t use MQTT, but given what you have I don’t see any obvious problems.

1 Like

What is the condition: [] for? That could be your problem. That should evaluate as false and keep the actions from running.

I was working on the assumption that the delay was a condition of the trigger, in one action. That the action was read as a block, and the delay would be executed as part of it. But what i’m hearing you say is i need to break out the delay as a distinct action, executed prior to the mqtt trigger (which works fine)

the condition is something that got inserted in there from my attempts at using the automation editor thing. seems to be automatic when you save from there.

No, sorry, I’m not saying that at all. This is how it works, as I understand it. When the trigger (a trigger, if you have more than one), happens, then if the condition evaluates to true, then the action (or actions, if you have more than one) will run. The way I read what you have is, you have one trigger, one condition, and two actions, the first of which is the MQTT publish, followed by a 5 second delay.

1 Like

Yeah, i didn’t realize a delay could be a stand alone thing. I read it as a property of an action.

this config seems to work great now. I’m getting a delay before the mqtt fires off.

- action:
  - delay: '00:00:05'
  - data:
      payload: 0
      topic: tub/pump/relay/0/set
    service: mqtt.publish
  alias: Shower ON pump delay
  id: '1523909935563'
  trigger:
  - payload: 1
    platform: mqtt
    topic: shower/touch/relay/0

This whole thing is part of an outdoor shower. The tankless water heater needs to maintain water flow or else it turns off. The water heater also heats a hot tub, so when i turn the shower on, the hot tub pump needs to turn off, but i have to maintain water pressure until the valves for fresh shower water open. turning off the pump is a simple switch that kills the heater, only to be turned back on seconds later as the fresh water triggers it… ugh, yeah that confusing, sorry. NM it all works now and i’ve also learned something. thanks much.

No problem, it’s definitely hard explaining things sometimes in a forum like this where it’s often way too much to fill in all the context. :slight_smile:

What you have looks good now. I think your main problem was the condition. Not sure why the automation editor would have included that. (I don’t use it.) [] is an empty list which evaluates to False, and like I said before, that would have prevented the actions from running.

Glad you have it working!