HTTP Binding commandTransformation

Hi, i’m a beginner with OH v3 but have some experience with OH v1. Now try to slowly migrate to v3, and had a stop with simple question - how i can send command with http binding?
I have video recorder that run record with command “http://localhost:874/avreg-cgi/operator/rec.cgi?camera=4&do=start”, i made a thing with http binding and specify base_url as "http://localhost:874/avreg-cgi/operator/rec.cgi?", made a channel (string) and specify Command URL Extension as “camera=4&do=”, and … uuups, my brain is stopping :hot_face: What i need to configure that adding “start/stop” ending to the final url?
I understand that i need to configure switch (may be string) item and rule with sending command to this item, but how to transform ON command to “start” ending of the url - i cant figure out. Help pls

Also, i’m configure state channel with State URL Extension as “camera=4&do=status” and it’s work fine.

Use a MAP Transformation that maps on/off to start and stop.

Thnks for your reply. I am using MAP file in my v1 system. But in v3 I try to use UI for configuring (may be it wrong way). How to use MAP with UI for my task?
v1 config no need any transformation, may be v3 UI has the same easy way?
Switch Cam4 { http=">[ON:POST:http://user:pass@localhost:874/avreg-cgi/operator/rec.cgi?camera=4&do=start] >[OFF:POST:http://user:pass@localhost:874/avreg-cgi/operator/rec.cgi?camera=4&do=stop]" }

The .map file can‘t be configured in‘s the same format as before.

v1 syntax is not supported.

yes, this is the question - how to set up the sending of http requests through the UI?

What exactly is your problem? Adding the command to the URL? It’s in the docs:

yes, i can’t undestand how to configure parameter “commandTransformation” for transformation command On (OpenHab) to Start (value that need to be added to baseURL + commandExtension), and i can’t find any example.

Like the examples here.

apparently I’m stupid, I can’t understand this example where is the transformation file that converts ON/OFF to start/stop.

I did not test this, but in theory, this should be the equivalent:
Thing as text configuration:

Thing http:url:recorder "Recorder" [ 
    ] {
        Type switch : cam4 "Cam 4" [commandExtension="rec.cgi?camera=4&do=%2$s", onValue"start", offValue="stop", mode="WRITEONLY"]

Item as text configuration:

Switch Cam4 "Cam 4" {channel="http:url:recorder:cam4"}
1 Like

thanks a lot, I will try both and return with the results

did not work, most likely there is not enough experience to implement

it turned out and works successfully, thank you very much

for information, why it did not work for me right away - it was necessary to add to the “%2$s” to the commandExtension,
“rec.cgi?camera=4&do=” - wrong string
“rec.cgi?camera=4&do=%2$s” - correct string

Well, %2$s is substituted with the status of the Item (after replaced with onValue or offValue). When setting up an extension, you have to define the position of the substitution. It could also be on the beginning of the extension or somewhere in the middle…

1 Like