Error running cURL command

I had disabled a script for some time and when re-enabling and testing it, it raises an error. It used to work early April, some HA version upgrades ago.

The purpose of the script is to post a sensor value to an external web service using a POST API.

The error is:

2018-06-02 08:20:05 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/usr/bin/curl {{ args|default('-sS') }} -X {{ method|default('get')|upper }} {%- for k in headers %} -H "{{ k }}: {{ headers[k] }}"{% endfor %} {{- (' -d \'' ~ payload|tojson ~ '\'') if payload }} {{ url }} > {{ stream|default('/dev/null') }}`, return code: 3
NoneType: None

This is the relevant config:

script:
  ## API documentation at https://www.mindergas.nl/member/api
  post_mindergas:
    alias: Post Gas Consumption
    sequence:
      - service: shell_command.curl
        data_template:
          url: https://www.mindergas.nl/api/gas_meter_readings
          method: post
          headers:
            Content-Type: application/json
            AUTH-TOKEN: !secret mindergas_token 
          payload:
            date: "{{ (as_timestamp(now()) - (24*3600)) | timestamp_custom('%Y-%m-%d', True) }}"
            reading: "{{ states.sensor.gas_consumption.state }}"
      - service: logbook.log
        data:
          name: Gasverbruik
          message: is verstuurd naar mindergas.nl
          entity_id: sensor.gas_consumption
          domain: sensor

shell_command:
  curl: >-
    /usr/bin/curl {{ args|default('-sS') }} -X {{ method|default('get')|upper }} {%- for k in headers %} -H "{{ k }}: {{ headers[k] }}"{% endfor %} {{- (' -d \'' ~ payload|tojson ~ '\'') if payload }} {{ url }} > {{ stream|default('/dev/null') }}

Can someone explain what the error means, why it’s raised and hopefully how to fix?

For the record, I’m using Hassio and curl is working in SSH:

➜  ~ which curl
/usr/bin/curl
1 Like

Same hre :frowning:

Did you ever made it work? I am now posting to mindergas.nl via a Python script and want to get rid of it as inside Docker it is not an ideal solution.

I have it working. Have a look at my repo tomsee how. I you stil have questiosn, please ask over here.

I had a look at your repository, but couldn’t find the automation. It is probably in the scripts.yaml file which is not available in your repository…

Little bump… @metbril am really eager to make this work :wink:

1 Like

This is where you can find the automation:

All it actually does is call a rest_command:

Many thanks! Got it up and running in a minute :slight_smile:

1 Like