Delay in automation will not work in specific order of actions

My goal when my automation triggers, in this order:

  1. Turn on my Denon receiver
  2. Wait 10 seconds for it to power on
  3. Set the volume
  4. Play a media file

This mostly works, except the delay runs first! I run the automation, it waits 10 seconds, my Denon receiver powers on and the media starts playing.

Do you have any idea how I can get this to work? I need the delay or the action to set the volume will not registry if the receiver is not on. No matter what I do the delay always runs first. I even broke this up into 3 scripts and ran that. No luck.

Here’s my automation

- id: '1590271192453'
  alias: testing denon
  description: Example of how to play a URL directly on the Denon AVR
  trigger:
  - device_id: fbfedf6ba1284100a3a26fe8f479e49e
    domain: binary_sensor
    entity_id: binary_sensor.front_door_sensor_4_0
    platform: device
    type: turned_on
  condition: []
  action:
  - data: {}
    entity_id: media_player.denon
    service: media_player.turn_on
  - delay: 00:00:10
  - data:
      volume_level: 0.25
    entity_id: media_player.denon
    service: media_player.volume_set
  - data:
      media_content_id: http://192.168.1.2:8080/media/sound/jr/JR%20DDG%20iOS%20Info.mp3
      media_content_type: url
    entity_id: media_player.denon
    service: media_player.play_media

The actions are executed in the order you list them. Not sure why you would be seeing the delay first.

Perhaps you just need a longer delay.

I’ve tried short delays and long delays. Nothing works. No matter what I do the delay is ran, then the power turns on the receiver. Short delay, then the receiver comes on after that short delay. Very long delay, the receiver comes on after that very long delay.

@tom_l is right, the actions run in order. If you want to really see what is happening, look in home-assistant.log. It will tell you exactly what is happening, and in what order.

EDIT: It almost sounds like your media player is not turning on correctly, and doesn’t really turn on until it gets the volume command. That seems weird, but it would explain what you’re seeing. Unfortunately I can’t help there; I have no experience with media players in HA.

1 Like

@pnbruckner that’s an interesting insight. I’ll do some testing around that. That very well could be what I’m seeing. I’ll report back once I know more.

That was it. It’s actually the media_player.play_media that turns on the device. If I do that first, delay, then change the volume, everything works great!

Thank you very much.

1 Like