Unable to correctly launch curl command to save image form an URL to the local disc

EDIT

The answer to this is that you cannot use variables when you call cURL from an automation.

You must define your shell command in your config fil, including the variables and then call if from within the automation.


I placed this in my configuration file

shell_command:
   cameraonesnapshot: curl -o /share/snapshots/cameraonesnapshot.jpg 'Url that you want to call'

If your URL includes an inline password then the entire url should be enclosed in single quotes '...'

I placed this in my automation as a service call

action:
  - service: shell_command.cameraonesnapshot




I’m trying to create an automation that retrieves a still image from a CCTV camera and saves it to a named file when the automation is triggered.

The CCTV camera has a snapshot URL

(http://192.168.0.80/webcapture.jpg?command=snap&channel=0&user=...&password=...)

Calling this URL will automatically return an image named “webcapture.jpg”.

I want to save this image to local storage.

Based on the help documentation I’ve created this code segment that I’ve saved to the automations.yaml file using Studio code server.

- id: 1701508224410
  alias: Save image from URL
  trigger: (insert trigger here)
  action:
  - service: shell_command
  command: curl -o /share/images/image.jpg {{ http://192.168.0.80/webcapture.jpg?command=snap&channel=0&user=...&password=...  }}
  mode: single```

The automation does not appear alongside the rest of the automations, and on a soft reboot the following error message appears in the log vile

Logger: homeassistant.components.automation
Source: components/automation/config.py:108
Integration: Automation (documentation, issues)
First occurred: 17:27:37 (5 occurrences)
Last logged: 17:31:26

Automation with alias 'Save image from URL' could not be validated and has been disabled: Service shell_command does not match format <domain>.<name> for dictionary value @ data['action'][0]['service']. Got 'shell_command' extra keys not allowed @ data['command']. Got 'curl -o /share/images/image.jpg {{ http://192.168.0.80/webcapture.jpg?command=snap&channel=0&user=...&password=... }}'
Automation with alias 'Save image from URL' could not be validated and has been disabled: Service shell_command does not match format <domain>.<name> for dictionary value @ data['action'][0]['service']. Got 'shell_command' expected str for dictionary value @ data['id']. Got 1701508224410 extra keys not allowed @ data['command']. Got 'curl -o /share/images/image.jpg {{ http://192.168.0.80/webcapture.jpg?command=snap&channel=0&user=...&password=... }}'

I think that I understand the basics of what the error message means, but I don’t know how to put the code in the correct format to achieve what I want.

Could someone please lend me a hand.

The URL is correct and the permissions to the destination directory are correct. I’m using them in other automations.

This is not a feature request. Please edit and re-categorize your post.

I would suggest configuration topic with automation tag.

1 Like

Moved.

It wasn’t supposed to be.

Wrong section, my bad

Why is this in braces? {{ http://192.168.0.80/webcapture.jpg?command=snap&channel=0&user=...&password= ...

They were in example code that I was given.

  - id: save_image_from_url
    alias: Save image from URL
    trigger:
      - platform: webhook
        entity_id: webhook_save_image
    action:
      - service: shell_command
        command: curl -o /share/images/image.jpg {{ trigger.payload.image_url }}

The sample code uses a template, which is why it is in {{…}}

You don’t seem to be using a template.

My understanding was that I was replacing a variable with a fixed value.

How should I be doing it?

Leave out the braces.

Service shell_command does not match format <domain>.<name> for dictionary value @ data['action'][0]['service']. Got 'shell_command' expected str for dictionary value @ data['id']. Got 1701508224410 extra keys not allowed @ data['command']. Got 'curl -o /share/images/image.jpg http://192.168.0.80/webcapture.jpg?command=snap&channel=0&user=...&password=...'

Same problem, I even changed the name on the Alias to make sure that this was a unique message and not a repeat.

It’s not the {} doing it.

Should I have a template that I’m missing?

Please post the yaml in full

That’s all that there is, aside from the trigger, which is just a motion cell activation from a CCTV camera.

I’m going to guess that I should have more?

Below is the example code that I tried to modify, I wanted to put in a fixed URL instead of the webhook and thought that I could simply replace the code in the backets with the URL. Which I obviously can’t.

automation:
  - id: save_image_from_url
    alias: Save image from URL
    trigger:
      - platform: webhook
        entity_id: webhook_save_image
    action:
      - service: shell_command
        command: curl -o /share/images/image.jpg {{ trigger.payload.image_url }}

# Webhook to trigger the automation
webhook:
  - id: webhook_save_image
    name: Save image webhook
    mode: single
    service: save_image_webhook
    data:
      image_url: "{{ trigger.payload.image_url }}"
{
  "image_url": "http://example.com/image.jpg"
}
curl -X POST -H "Content-Type: application/json" http://YOUR_HOME_ASSISTANT_IP:8123/api/webhooks/webhook_save_image -d '{ "image_url": "http://example.com/image.jpg" }'

I asked for your yaml.

I’m afraid that you’re going to need to be a little more specific. Please don’t presume that I understand what you mean when you post clipped comments. I’m not yet familiar with how things are described in HA.

Are you asking for a dump of my entire configuration.yaml file, or my automations.yaml?

The yaml of that automation, or really just the action part.

I suspect you need to do some quoting, ie put " " around the url.

I’ve tried single and double quotes, without brackets, and with single and double brackets.

My takeaway is that this probably has to be a template, and not a variable, by design.

I’m not clear how this differs from the code that I posted except that I deleted some personal information like my username and the name of the trigger device.

it looks like I may not have the shell_command feature fully implemented. is there something I need to do to load it as an integration?

It is a core integration.