Curl inside shell_command not working

Hi folks
I’m new here and need some help.
I want to control my Wallbox (Hardy Barth) by Homeassistant through curl / API commands.
Quite a few things are working, but I got stuck with sending numeric value from an input number helper as setting to my Wallbox.
In my configuration.yaml I inserted:
´shell_command:
wallbox_ampere_eco: /scripts/manual_mode_ampere_an_wb´
(indentation somehow not shown here)

In this file “manual_mode_ampere_an_wb” I placed the curl command to be sent to the Wallbox:

´curl -X POST -H ‘Content-Type: application/x-www-form-urlencoded’ -H ‘Accept: application/json’ -d ‘manualmodeamp= 14’ http://192.168.1.4/api/v1/chargecontrols/01/mode/manual/ampere´

The “14” in the data part I want to replace later by a value_template and the shell_command service will be used in an automation.
The service is showing up as “wallbox_ampere_eco” under developement tools / services and can be executed.
In the log I get error 127 and there is no change in the setting of the wallbox.
The curl command is working fine in the terminal.

You have a space between the = and 14

Yes, the is a space

curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'manualmodeamp= 14' http://192.168.1.4/api/v1/chargecontrols/01/mode/manual/ampere

Here the code again in better formatting

and

shell_command:
  wallbox_ampere_eco: /scripts/manual_mode_ampere_an_wb

Have you tried removing that space? And give the file a .sh extension? And make sure it has eXecute permission?

According to the documentation it should look like this

my_script: bash /config/shell/script.sh
shell_command:
  wallbox_ampere_eco: bash /scripts/manual_mode_ampere_an_wb.sh

Though if the sh file is in your config directory it should be /config/scripts

Thanks for all these hints.
Yes I mad the script executeable by chmod +x.
The other proposals I will try out and come back.

Very nice so far, first step done. Following code is running.
In configuration.yaml:

shell_command:
  wallbox_ampere_manual: bash /config/scripts/manual_mode_ampere_an_wb.sh

And in /config/scripts/manual_mode_ampere_an_wb.sh file

curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'manualmodeamp=14' http://192.168.1.4/api/v1/chargecontrols/01/mode/manual/ampere

I can verify by a GET command to my wallbox, that the value “14” is reaching there.
I inserted this shell_command servive in the automation triggered by the input number helper and it works.
Now I’d like to send any value by input number helper from my HA dashboard to the wallbox.
I tried following in the configuration.yaml, which ended up in error 127 again.

shell_command:
  wallbox_ampere_manual: bash '/config/scripts/manual_mode_ampere_an_wb.sh ampere={{states('input_number.manual_mode_ampere')}}'

In the .sh file I would need something like this?

curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'manualmodeamp={{ampere}}' http://192.168.1.4/api/v1/chargecontrols/01/mode/manual/ampere

FINALYYYYY, GOT IT RUNNING.

CONFIGURATION.YAML:
shell_command:
  wallbox_ampere_manual: bash /config/scripts/manual_mode_ampere_an_wb.sh "{{states('input_number.manual_mode_ampere')}}"

SCRIPT:
curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'manualmodeamp='"$1" http://192.168.1.4/api/v1/chargecontrols/01/mode/manual/ampere

THAT WAS TOUGH

Just in case someone else wants to control a Wallbox Hardy Barth, such as cPµ1 with coltroller eCB1 by Home assistant API commands.
Here are the configuration.yaml entries to control all the other buttons of the wallbox WEB interface:

# Wallbox Kommunikation
switch:
  - platform: command_line
    switches:
      autostartstop_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'autostartstop=true' 'http://192.168.1.4/api/v1/chargecontrols/01/mode/eco/startstop'"
        command_off: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'autostartstop=false' 'http://192.168.1.4/api/v1/chargecontrols/01/mode/eco/startstop'"
        command_state: "/usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.1.4/api/v1/chargecontrols/01/mode/eco/startstop'"
        value_template: "{{ value_json.autostartstop == true }}"
        friendly_name: Wallbox Autostart Switch
        unique_id: 'wallbox_autostart'
        
      laden_startstop_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/json'  -H 'Accept: application/json' -d '' 'http://192.168.1.4/api/v1/chargecontrols/01/start'"
        command_off: "/usr/bin/curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '' 'http://192.168.1.4/api/v1/chargecontrols/01/stop'"
        friendly_name: Wallbox StartStop Switch
        unique_id: 'wallbox_startstop'    

      eco_ladung_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=eco' 'http://192.168.1.4/api/v1/chargecontrols/01/mode'"
        command_off: ""
        command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.1.4/api/v1/chargecontrols/01/mode'"
        value_template: "{{ value_json.mode == 'eco' }}"
        friendly_name: Wallbox Eco-Ladung
        unique_id: 'wallbox_eco_ladung'

      quick_ladung_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=quick' 'http://192.168.1.4/api/v1/chargecontrols/01/mode'"
        command_off: ""
        command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.1.4/api/v1/chargecontrols/01/mode'"
        value_template: "{{ value_json.mode == 'quick' }}"
        friendly_name: Wallbox Quick-Ladung
        unique_id: 'wallbox_quick_ladung'

      manual_ladung_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=manual' 'http://192.168.1.4/api/v1/chargecontrols/01/mode'"
        command_off: ""
        command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.1.4/api/v1/chargecontrols/01/mode'"
        value_template: "{{ value_json.mode == 'manual' }}"
        friendly_name: Wallbox Manual-Ladung
        unique_id: 'wallbox_manual_ladung'        

Here the link to the wallbox API docu:
http://apidoc.ecb1.de/doc/api/v1/swagger.json
If you have a wallbox with eCB1 installed you can access it though
http://“local_ip_address”/api/v1/doc#

Hello, thanks for the previous posts on the subject of Hardy Barth with eCB1.

How can I get the values ​​from the eCB1 in Home Assistant?
According to Hardy Barth, the smart meter of the WB (eCB1) can be read out via API:
(I could also call up the house connection measurement via the eCB1 - but I already have the values ​​from the RCT-WR.)
The socket meter is available at http://ecb1.local/api/v1/meters/1 ( curl -X GET --header ‘Accept: application/json’ ‘http://ecb1.local/api/v1/ meters/1’ ).

{“meter”: {“function”: “socket”, “type”: “eCB1 intern”, “ipaddress”: “127.0.0.1”, “vendor”: “eCHARGE”, “serial”: >>serial number<< , “id”: 1, “data”: {“1-0:22.4.0”: 0.0, “1-0:73.4.0”: 0.0, “1-0:51.4.0”: 0.0, “1 -0:62.4.0”: 0.0, “1-0:41.4.0”: 0.0, “1-0:72.4.0”: 225.082, “1-0:42.4.0”: 0.0, “1-0 :42.8.0”: 0.0, “1-0:2.4.0”: 0.0, “1-0:62.8.0”: 0.0, “1-0:53.4.0”: 0.0, “1-0:41.8 .0”: 0.0, “1-0:1.8.0”: 8.6427, “1-0:61.8.0”: 0.0, “1-0:2.8.0”: 0.0, “lgwb”: -5.8, “ 1-0:21.8.0”: 8.6427, “1-0:52.4.0”: 225.736, “1-0:31.4.0”: 0.027999999999999994, “1-0:61.4.0”: 0.0, “1- 0:71.4.0”: 0.0, “1-0:21.4.0”: 5.8, “1-0:33.4.0”: 0.882, “1-0:13.4.0”: 0.882, “1-0: 22.8.0”: 0.0, “1-0:1.4.0”: 5.8, “1-0:32.4.0”: 225.046}, “name”: “Carport”}, “protocol-version”: “1.4” }

The answers are in JSON format and the coding of the measured values ​​corresponds to the OBIS codes.

The following values ​​would be enough for me as sensors to then visualize them:
lgwb Balance Active power+/- <= current power
1-0:1.4.0 Active power+ <= current power
1-0:1.8.0 Active energy+ <= Counter work/energy
1-0:2.4.0 Active power- <= current power
1-0:2.8.0 Active energy- <= work/energy counter

Surely this can be realized.

solved:

rest:
  - resource: "http://ecb1.local/api/v1/meters/1"
    sensor:
      - name: "aktuelle Leistung +/-"
        value_template: "{{ value_json['meter']['data']['lgwb'] }}"
        unit_of_measurement: "W"
      - name: "aktuelle Leistung +"
        value_template: "{{ value_json['meter']['data']['1-0:1.4.0'] }}"
        unit_of_measurement: "W"

Hallo Gerd_Berlin, herzlichen Dank für das Bereitstellen des Codes zur Steuerung einer Wallbox von Hardy Barth!

Könntest du mir als vollkommener Anfänger im Umgang mit Home Assistant etwas genauer erklären, wie ich die Schaltflächen der Web-Schnittstelle der Wallbox nutzen kann, nachdem ich die Einträge in der configuration.yaml eingefügt habe?

Vielen Dank!!!

I agree with the previous speaker’s question. I have changed the config accordingly and was hoping to find new entities or switches for the wallbox in HomeAssistant. Unfortunately, nothing. Can anyone here help?

Many thanks and best regards

Hello @Gerd_Berlin ,

I added the code to the coniguration.yaml. Is there anything else to add to the files?
How did you create the switches in the dashboard?

Thanks in advance.

This is one sensor configuration from my Configuration.yaml

command_line:

Wallbox Lademodus auslesen

  • sensor:
    name: Wallbox Lademodus

    scnan_interval: 10

    command: “/usr/bin/curl -X GET --header ‘Accept: application/json’ ‘http://192.168.1.4/api/v1/chargecontrols/01/mode’”
    value_template: “{{ value_json.mode }}”
    unique_id: “wallbox_lademodus”

Then in the Developing Tools the sensors and switches show up like this:

And the in the Dashboard I placed sensors and switches accordingly like this:

In the upper part I placed other switches to start / stop charging depending on other conditions
I hope that helps. If not you might ask more detailed

Hello @Gerd_Berlin ,
Thank you for your quick response.
I have the following code in the configuration.yaml that works to read the data.


rest:
  - resource: "http://ecb1.local/api/v1/meters/1"
    sensor:
      - name: "ecb1 Saldo Active power+/- aktuelle Leistung"
        value_template: "{{ value_json['meter']['data']['lgwb'] | round(0) }}"
        unit_of_measurement: "W"
      - name: "ecb1 Active power+ aktuelle Leistung"
        value_template: "{{ value_json['meter']['data']['1-0:1.4.0'] | round(0) }}"
        unit_of_measurement: "W"
      - name: "ecb1 Active energy+ Zähler Arbeit/Energie"
        value_template: "{{ value_json['meter']['data']['1-0:1.8.0'] | round(1) }}"
        unit_of_measurement: "kWh"
      - name: "ecb1 Active power- aktuelle Leistung"
        value_template: "{{ value_json['meter']['data']['1-0:2.4.0'] | round(0) }}"
        unit_of_measurement: "W"
      - name: "ecb1 Active energy- Zähler Arbeit/Energie"
        value_template: "{{ value_json['meter']['data']['1-0:2.8.0'] | round(1) }}"
        unit_of_measurement: "kWh"        
      - name: "ecb1 Power factor gesamt"
        value_template: "{{ value_json['meter']['data']['1-0:13.4.0'] | round(0) }}"
        unit_of_measurement: "W" 
      - name: "ecb1 Active power+ (L1)"
        value_template: "{{ value_json['meter']['data']['1-0:21.4.0'] | round(0) }}"
        unit_of_measurement: "W"        
      - name: "ecb1 Active energy+ (L1)"
        value_template: "{{ value_json['meter']['data']['1-0:21.8.0'] | round(1) }}"
        unit_of_measurement: "kWh"
      - name: "ecb1 Active power- (L1)"
        value_template: "{{ value_json['meter']['data']['1-0:22.4.0'] | round(0) }}"
        unit_of_measurement: "W"        
      - name: "ecb1 Active energy- (L1)"
        value_template: "{{ value_json['meter']['data']['1-0:22.8.0'] | round(0) }}"
        unit_of_measurement: "W"         
      - name: "ecb1 Current (L1)"
        value_template: "{{ value_json['meter']['data']['1-0:31.4.0'] | round(1) }}"
        unit_of_measurement: "A"    
      - name: "ecb1 Voltage (L1)"
        value_template: "{{ value_json['meter']['data']['1-0:32.4.0'] | round(1) }}"
        unit_of_measurement: "V"   
      - name: "ecb1 Power factor (L1)"
        value_template: "{{ value_json['meter']['data']['1-0:33.4.0'] | round(1) }}"
        unit_of_measurement: ""         
      - name: "ecb1 Active power+ (L2)"
        value_template: "{{ value_json['meter']['data']['1-0:41.4.0'] | round(0) }}"
        unit_of_measurement: "W"        
      - name: "ecb1 Active energy+ (L2)"
        value_template: "{{ value_json['meter']['data']['1-0:41.8.0'] | round(1) }}"
        unit_of_measurement: "kWh"
      - name: "ecb1 Active power- (L2)"
        value_template: "{{ value_json['meter']['data']['1-0:42.4.0'] | round(0) }}"
        unit_of_measurement: "W"        
      - name: "ecb1 Active energy- (L2)"
        value_template: "{{ value_json['meter']['data']['1-0:42.8.0'] | round(0) }}"
        unit_of_measurement: "W"         
      - name: "ecb1 Current (L2)"
        value_template: "{{ value_json['meter']['data']['1-0:51.4.0'] | round(1) }}"
        unit_of_measurement: "A"    
      - name: "ecb1 Voltage (L2)"
        value_template: "{{ value_json['meter']['data']['1-0:52.4.0'] | round(1) }}"
        unit_of_measurement: "V"   
      - name: "ecb1 Power factor (L2)"
        value_template: "{{ value_json['meter']['data']['1-0:53.4.0'] }}"
        unit_of_measurement: ""                 
      - name: "ecb1 Active power+ (L3)"
        value_template: "{{ value_json['meter']['data']['1-0:61.4.0'] | round(1) }}"
        unit_of_measurement: "W"        
      - name: "ecb1 Active energy+ (L3)"
        value_template: "{{ value_json['meter']['data']['1-0:61.8.0'] | round(1) }}"
        unit_of_measurement: "kWh"
      - name: "ecb1 Active power- (L3)"
        value_template: "{{ value_json['meter']['data']['1-0:62.4.0'] | round(0) }}"
        unit_of_measurement: "W"        
      - name: "ecb1 Active energy- (L3)"
        value_template: "{{ value_json['meter']['data']['1-0:62.8.0'] | round(0) }}"
        unit_of_measurement: "W"         
      - name: "ecb1 Current (L3)"
        value_template: "{{ value_json['meter']['data']['1-0:71.4.0'] | round(1) }}"
        unit_of_measurement: "A"    
      - name: "ecb1 Voltage (L3)"
        value_template: "{{ value_json['meter']['data']['1-0:72.4.0'] | round(1) }}"
        unit_of_measurement: "V"   
      - name: "ecb1 Power factor (L3)"
        value_template: "{{ value_json['meter']['data']['1-0:73.4.0'] }}"
        unit_of_measurement: ""  

To control the box, I incorporated your code from above on this page into the configuration.yaml. Now I see that you probably also have a charging mode sensor.
Would you provide me with all your code?

# Wallbox Kommunikation
switch:
  - platform: command_line
    switches:
      autostartstop_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'autostartstop=true' 'http://192.168.178.48/api/v1/chargecontrols/01/mode/eco/startstop'"
        command_off: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'autostartstop=false' 'http://192.168.178.48/api/v1/chargecontrols/01/mode/eco/startstop'"
        command_state: "/usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.178.48/api/v1/chargecontrols/01/mode/eco/startstop'"
        value_template: "{{ value_json.autostartstop == true }}"
        friendly_name: Wallbox Autostart Switch
        unique_id: 'wallbox_autostart'
        
      laden_startstop_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/json'  -H 'Accept: application/json' -d '' 'http://192.168.178.48/api/v1/chargecontrols/01/start'"
        command_off: "/usr/bin/curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '' 'http://192.168.178.48/api/v1/chargecontrols/01/stop'"
        friendly_name: Wallbox StartStop Switch
        unique_id: 'wallbox_startstop'    

      eco_ladung_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=eco' 'http://192.168.178.48/api/v1/chargecontrols/01/mode'"
        command_off: ""
        command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.178.48/api/v1/chargecontrols/01/mode'"
        value_template: "{{ value_json.mode == 'eco' }}"
        friendly_name: Wallbox Eco-Ladung
        unique_id: 'wallbox_eco_ladung'

      quick_ladung_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=quick' 'http://192.168.178.48/api/v1/chargecontrols/01/mode'"
        command_off: ""
        command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.178.48/api/v1/chargecontrols/01/mode'"
        value_template: "{{ value_json.mode == 'quick' }}"
        friendly_name: Wallbox Quick-Ladung
        unique_id: 'wallbox_quick_ladung'

      manual_ladung_schalter:
        command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=manual' 'http://192.168.178.48/api/v1/chargecontrols/01/mode'"
        command_off: ""
        command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://192.168.178.48/api/v1/chargecontrols/01/mode'"
        value_template: "{{ value_json.mode == 'manual' }}"
        friendly_name: Wallbox Manual-Ladung
        unique_id: 'wallbox_manual_ladung'
        

Somehow I don’t see a sensor for control in the developer tools.
Is an entry necessary anywhere else besides the configuration.yaml?

I would be happy if you could help me.

Thank you very much for the explanation. Can you shortly explain an unexperiecend user like me how these switches can be created , and how get it done correctly.
Thank you

Maybe it helps someone…
The command_line in Home Assistant has been changed (see https://www.home-assistant.io/integrations/command_line/), I updated the source code of @Gerd_Berlin.

command_line:
  - switch:
      name: wallbox_autostartstop_switch
      command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'autostartstop=true' 'http://ecb1.local/api/v1/chargecontrols/01/mode/eco/startstop'"
      command_off: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'autostartstop=false' 'http://ecb1.local/api/v1/chargecontrols/01/mode/eco/startstop'"
      command_state: "/usr/bin/curl -X GET -H 'Accept: application/json' 'http://ecb1.local/api/v1/chargecontrols/01/mode/eco/startstop'"
      value_template: "{{ value_json.autostartstop == true }}"
      unique_id: 'wallbox_autostart'
  - switch:
      name: wallbox_charge_startstop_switch
      command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/json'  -H 'Accept: application/json' -d '' 'http://ecb1.local/api/v1/chargecontrols/01/start'"
      command_off: "/usr/bin/curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '' 'http://ecb1.local/api/v1/chargecontrols/01/stop'"
      unique_id: 'wallbox_startstop'
  - switch:
      name: wallbox_eco_charge_switch
      command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=eco' 'http://ecb1.local/api/v1/chargecontrols/01/mode'"
      command_off: ""
      command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://ecb1.local/api/v1/chargecontrols/01/mode'"
      value_template: "{{ value_json.mode == 'eco' }}"
      unique_id: 'wallbox_eco_charge'
  - switch:
      name: wallbox_quick_charge_switch
      command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=quick' 'http://ecb1.local/api/v1/chargecontrols/01/mode'"
      command_off: ""
      command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://ecb1.local/api/v1/chargecontrols/01/mode'"
      value_template: "{{ value_json.mode == 'quick' }}"
      unique_id: 'wallbox_quick_charge'
  - switch:
      name: wallbox_manual_charge_switch
      command_on: "/usr/bin/curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -d 'mode=manual' 'http://ecb1.local/api/v1/chargecontrols/01/mode'"
      command_off: ""
      command_state: "sleep 1; /usr/bin/curl -X GET -H 'Accept: application/json' 'http://ecb1.local/api/v1/chargecontrols/01/mode'"
      value_template: "{{ value_json.mode == 'manual' }}"
      unique_id: 'wallbox_manual_charge'