How to send REST command?

Hello,

I would like to create an automation for solar charging.
To do this, I need to send the ampere value to my wallbox (go-eCharger) via HTTP post.
The call for this is for example http://192.168.x.x/mqtt?payload=amx=10.

I have created a template that provides me with the required value, depending on the production of the photovoltaics (sensor.watt_in_ampere).

What does not work, however, is sending the HTTP post. I have entered the following in configuration.yaml:

rest_command:
    goecharger_set_amx:
        url: http://192.168.x.x/mqtt?payload
        method: POST
        payload: '{"amx": "{{ sensor.watt_in_ampere }}"}'
        content_type: 'application/json; charset=utf-8'

Is this correct? If so, how can I call the command?

EDIT:
This HTTP call works with an variable parameter:

rest_command:
    goecharger_set_amx:
        url: http://192.168.178.120/mqtt?payload=amx={{ amx_value }}
        method: GET
        verify_ssl: false

But I just can’t get the value of the sensor, it always sends 0.

service: rest_command.goecharger_set_amx
data:
  amx_value: sensor.watt_in_ampere

What am I doing wrong?

Many thanks in advance.

Did you check for errors in your log?

payload: '{"amx": "{{ states(\'sensor.watt_in_ampere\') }}"}'

Or, without a need to escape quotes.

payload: >
  {"amx": "{{ states('sensor.watt_in_ampere') }}"}

Thank you, you push me to the right direction. Now it’s working. :slightly_smiling_face:

rest_command:
    goecharger_set_amx:
        url: http://192.168.x.x/mqtt?payload=amx={{ states.sensor.watt_in_ampere.state }}
        method: POST
1 Like

Great!

You can remove “solved” from the title and mark the appropriate post as the solution instead. This works with built-in feature of the forum.

Also, use the states() function like I have. You can read more about why in the templating docs.