Newbie configuration question (multiple service calls from one curl command)

I have the following three curl commands working:

curl -s -X POST -H "Content-Type: application/json"  -d '{"entity_id":"media_player.receiver"}' firewall:8123/api/services/media_player/turn_on
curl -s -X POST -H "Content-Type: application/json"  -d '{"entity_id":"media_player.receiver", "source" :"game1"}' firewall:8123/api/services/media_player/select_source
curl -s -X POST -H "Content-Type: application/json"  -d '{"entity_id":"media_player.receiver", "volume_level" :"0.7"}' firewall:8123/api/services/media_player/volume_set

I would like to be able to cause all three service calls to be run at once via a single curl shell command line call.

I suspect there is a way to set up an action or trigger (or whatever the correct word is) in my configuration.yaml file, then use it in a curl command to get all three services executed at once.

Can anyone provide me:

. a snippet to add to my configuration to do this
. the curl shell command to activate it

I have searched, but haven’t found the answer…

Thanks!

I would make a script in Home Assistant that performs the sequence you want.

Then use a curl command to call the script, for example:

curl -X POST -H "Content-Type: application/json" -d '{"entity_id": "script.do_media_things"}' http://firewall:8123/api/services/script/turn_on

Excellent! Looks like just what I need! Thanks!!!

P.S. I need to sleep 5 seconds between “turn_on” and “select source” (or the receiver does not get the select_source). How can I do that in the script? I that what “delay:” is for? If so, where does it go, directly under the “- service:” tag? Does it need a dash in front of it?

I have this…

script:
  start_mythtv:
    sequence:
    - service: media_player.turn_on  # also turns on receiver w/CEC
      data:
        entity_id: media_player.shield
    - delay: '00:00:05'
    - service: media_player.select_source
      data:
        entity_id: media_player.receiver
        source: 'game1'

It seems to work!

Thanks again…

Great!

Scripts are very handy, you’ll probably end up with up dozens of them :slight_smile: