Start MediaPlayer and change Source with delay/loop

I’m trying to write a automation to start my playstation and start Netflix when the playstation is started (state: idle). But I can’t figure out how to wait to check if the playstation is stared. I need some kind of loop or delay.

Has anyone tried something similar yet?

See the second example on the documentation here:

That is a fixed delay, right? It would probably work.
But it would be more elegant quicker and more reliable to be able to check when the playstation started after sending the command to start it.
I’m gonna try to write a loop that checks that and if I find a solution I’ll post it here.

I think you’ll have to drop to appdaemon to get a delay loop.
You could potentially do this with another automation that triggers on the state change of the playstation. You would probably need to add an input_boolean to indicate that the state change was triggered by your first automation. It may be more trouble than it is worth when you can set the fixed timer and achieve the desired results.

Maybe you are right…

Is there a way to store data somehow?

My Idea is:

  • Script starts Playstation and sets variable to “netflix”-
  • Automation gets triggered when playstation is started and checks if variable is set and starts app accordingly and resets variable.

Use a wait_template rather than a fixed delay.

Edit -

2 Likes

That looks great, thank you!

1 Like

My Solution:

# (start Paystation and) start Netflix
set_playstation_netflix:
  sequence:
    - service: media_player.turn_on
      data_template:
        entity_id: media_player.playstation
    - wait_template: "{{ states.media_player.playstation.state == 'idle' }}"
    - service: media_player.select_source
      data_template:
        entity_id: media_player.playstation
        source: Netflix
2 Likes