Error running cURL command


#1

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

#2

Same hre :frowning:


#3

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.


#4

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


#5

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…


#6

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


#7

This is where you can find the automation:

All it actually does is call a rest_command:


#8

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