Sending HTTP command in automation action

Hey all,

I’m trying to create an automation with an action that runs an HTTP request and cannot figure it out. If I enter http://user:[email protected]/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1 into a web browser, the network speaker plays the audio file. I tried adding the following command line switch to my configuration.yaml file:

switch:
  - platform: command_line
    switches:
      axis:
        friendly_name: 'Axis Speaker'
        command_on: 'curl -k "http://user:[email protected]/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1"'
        command_off: 'curl -k "http://user:[email protected]/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1"'

Then, I tried to test the “CALL SERVICE” Service switch.turn_on with entity_id: switch.axis but nothing happens. Am I totally off on how this is supposed to work? I’m brand new to this, so please excuse the dumb question.

Use a shell command rather than a switch as you do not have an on / off state.

You can call this command from an automation or a Lovelace button as a service.

Thanks for the reply. I tried

shell_command:
  play_clip1: curl 'http://user:[email protected]/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1'

Still no luck. I’ve attached my system info if that helps. I’ve read a few threads mentioning maybe a full path needs to be included in the curl command?

Try this

shell_command:
  play_clip1: 'curl -X POST "http://user:[email protected]/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1"'

Or a rest command:

rest_command:
  play_clip:
    url: "http://192.168.1.155/axis-cgi/virtualinput/activate.cgi"
    userame: user
    password: pass
    payload: "schemaversion=1&port=1"
    verify_ssl: false
    method: post

Thank you very much for your help! I think the issue was related to a password encryption setting on the Axis speaker. I had also changed the shell_command to GET instead of POST, but will have to do some more testing tomorrow to see if it that contributed to it as well. In any case, the following works:

shell_command:
  play_clip2: 'curl -X GET "http://user:[email protected]/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1"'

Thanks again.

1 Like

Try this https://www.home-assistant.io/integrations/rest_command/

If that’s the case then this should work too, if you change the method: