Controlling API of Wallbox via OH3

Hello

i own a HARDY BARTH wallbox with an eCB1 smart meter to control the wallbox.
I do have a documentation for the API but i have never done something like this before.

I am happy to learn for myself but i do not know where to start.

The eCB1 API has also a REST api like OH and you can control it with simple calls like:

http://ecb1.local/api/v1/chargecontrols/1/start

this would start charging on point 1.

My question now:
how do i call something like this via openHAB?

Do i need the exec binding or is there something special for such a use case?

Thank you!

You could use for instance the HTTP binding.
I do something similar with my Samsung AC.

1 Like

Ok i took a look at it but i am missing some examples :frowning:

only the things-config is in the documentation.

I want to send a string (charge-modes eco, quick or manual). The itembox in the ui of the wallbox is called “mode” → this is where i can choose eco etc. via dropdown menu.

basically i am missing the information on where to put the “mode” i guess.

Here’s what i came up with:

Things:

Thing http:url:Ladesaeule "Ladesäule" [
	baseURL="http://192.168.1.11/api/v1/",
    commandMethod="POST",
    stateMethod="GET",
	refresh=15] {
		Channels:
			Type string : Modus "Ladesäule Modus" [commandExtension="chargecontrols/1/mode",mode="WRITEONLY"]  
}

Items:

Group Ladesaeule

String Ladesaeule_Modus "Ladesäule Modus" (Ladesaeule) {channel="http:url:Ladesaeule:Modus"}

Thank you for your help!

Have another look at the docs

The magic part is %2$s , which is a placeholder for whatever the Item supplies as “argument”, after any transformation. In this case, you probably want to command your Item with "eco" and place that at the end of the url
commandExtension="chargecontrols/1/mode/%2$s"
or
commandExtension="chargecontrols/1/mode?%2$s"
or whatever your url syntax is

1 Like

Thank you again, rossko.
unfortunately it is not working i tried it both ways.

It seems i need to pass the string to a subitem here mode manual …
the CURL response from the API UI of the wallbox is:

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'mode=manual' 'http://192.168.1.11/api/v1/chargecontrols/1/mode'

it’s hard to explain for me so i attached some screenshots

Oh yes, it’s a POST, so the data has to go in the body, not the url.
An example of what you are trying to do really does help.
Same placeholder principle -
stateContent="mode=%2$s"

1 Like

Just to add on this, as it might help, though I use the UI to configure:

The “thing” needs your base URL as you have shown in your previous post - http://192.168.1.11/api/v1/
Your “channel” then can have a state transformation (if required) and/or a command URL extension, in your case this is chargecontrols/1/mode.
You can then define inside the item the different, in your case, “modes”.

Example from my AC item to set AC mode:

I do not use the %2$s in the command as well. Example:

Your error message looks like that the POST you did was wrong (400 Bad Request).
It shows in your log URL, maybe I am wrong though, that your URL ends with mode?quick.
I assume “quick” is your mode, but the “?” should not be there and it should more look like this: chargecontrols/1/mode/quick (not sure again).

A simple way of testing this would be to use either a rule (so you do not need to redefine the items etc. all the time) or Postman.

EDIT: I forgot to explain my map file - it includes the content shown in this post, which are all the commands. This might be needed for you as well as your “quick” mode might need to be part of the body message as your screenshot shows its part of “formData” and not the “path”

1 Like

Hello

unfortunately i can still not get it to work. I tried multiple mappings and expanded my things-config …

if i call this from my terminal i can switch values:

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'mode=manual' 'http://192.168.1.11/api/v1/chargecontrols/1/mode'

here’s my config now (i hope you can help):

Thing http:url:Ladesaeule "Ladesäule" [
	baseURL="http://192.168.1.11/api/v1/",
    commandMethod="POST",
    stateMethod="GET",
	contentType="application/x-www-form-urlencoded",
	refresh=15] {
		Channels:
			Type string : Ladesaeule_Modus "Ladesäule Modus" [commandTransformation="MAP:HTTP.map",commandExtension="chargecontrols/1/mode",mode="WRITEONLY"]
}

items

Group Ladesaeule
String Ladesaeule_Modus "Ladesäule Modus" (Ladesaeule) {channel="http:url:Ladesaeule:Ladesaeule_Modus"}

map

quick=[{"mode":"quick"}]
eco=[{"mode":"eco"}]
manual=[{"mode":"manual"}]

this is frustrating …

Did you try it via a (ECMA) rule?
Below is a rule for my Samsung AC:

var token = "token";
var headers = [];
headers["Authorization"] = "Bearer " + token;
var url = "https://api.smartthings.com/v1/devices/ID/commands"
var jsondata = '[{"component": "main", "capability": "switch", "command": "off"}]';
  
var result = HTTP.sendHttpPostRequest(url, "application/json", jsondata, headers, timeout);

For your CURL this would look something like:

var headers = [];
headers["Content-Type"] = "application/x-www-form-urlencoded";
var url = "http://192.168.1.11/api/v1/chargecontrols/1/mode"
var jsondata = '[{"quick"}]';

var result = HTTP.sendHttpPostRequest(url, "application/json", jsondata, headers, timeout);

I am not so sure what to do with the -d ‘mode=manual’ though.

EDIT: another option of above could be:

var headers = [];
headers["Content-Type"] = "application/x-www-form-urlencoded";
var url = "http://192.168.1.11/api/v1/chargecontrols/1/"
var jsondata = '[{"mode":"quick"}]';

var result = HTTP.sendHttpPostRequest(url, "application/json", jsondata, headers, timeout);

EDIT2: above might still not work as in your -d I guess that’s the command to be send.

1 Like

This looks promising. Have you installed MAP add-on? What does it actually send?

Note that many bindings do not always pick up small edits from xxx.things files, and need a restartonce you’veedited in your best effort.

yep, i installed the map addon - got an error first and installed it after that and it does not complain now.

It did not work but i know found the solution with some help of my friend.

The api just does not accept json so my .things file i posted earlier with the contentType is correct but the mapping was still in json format.

new mapping looks like:

quick=mode=quick
eco=mode=eco
manual=mode=manual
2 Likes

Thought so that it is JSON related as your initial command does not actually show a JSON format.

Glad that it works now!

1 Like

Impressed that works - I thought the second = might blow MAP up!

1 Like

i had a weird feeling as well.
but only after i copied it in here :wink: