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.

4 Likes

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:

Thanks for the help. Also added -k in curl to allow for insecure and

Hi all,
do not kow if you were able to sucessfully make it work.
I’ve a similar problems with the Axis cameras… I’d like to activate / deactivate the ‘motionguard’ app… I tried tons of variaion but nothing.
Below my working http (in the browser) and the possible rest command (that doesn’t work)… any suggestion would be highly apprecited!

Fabio

http://192.168.1.201/axis-cgi/applications/control.cgi?action=stop&package=motionguard
rest_command:
  axis_camera_activate_motion:
    url: "http://192.168.1.201/axis-cgi/applications/control.cgi"
    username: root
    password: admin
    payload: "action=stop&package=motionguard"
    verify_ssl: false
    method: post

You can add this to your configuration.yaml to see what errors you are getting.

logger:   ####  Need to view full HA core logs and can be filtered 
  default: info
  logs:
    homeassistant.components.rest_command: debug

I’m trying to do something similar to send SMS from Teltonika router.
If this is used in browser it works.
http://192.168.55.1/cgi-bin/sms_send?username=admin&password=password&number=00441234567890&text=testmessage

How to run it as service to call it with automation?

Hi there, did you ever get more functionality out of your speaker? I have a set of axis C3003-E horn speakers and I’m trying to figure out the best way to get access to some of the audio streams, either microphone or speaker.

The Axis integration doesn’t appear to have support for them.