HTTP Put Request explanation

Hello,
i am new to the HTTP API thing.

I want to send some commands to my Shellys. But i have absolutely no idea how the HTTP requests work. Even Actions | openHAB did not explained it to me as i hoped.

If i want to change the brightness and transition on one of my shellies, i can type the following into a browser: http://192.168.178.98/light/0?turn=on&brightnesss=100&transition=0

i got three parameters:
turn = on (turns the light on)
brightness = 100 (sets the brightness to 100%)
transition = 0 (transition time from 0% to 100% in 0ms)

Now i need to add them into an Http Reques with a rule. And now i am encountering all problems. I dont know how. Can someone explain it a bit to me?

rule "Testrule"
when
    something triggers
then
    sendHttpPutRequest("http://192.168.178.98/light/0?", "body", "brightness=10")
end

I know that my current rule is wrong, but i dont know how to modify the request until its working.

HTTP offers mainly three options to interact (there’s more, but for now three are ok):

  • GET
  • POST
  • PUT

So, what you usually see is “GET” → like the URL you just posted: http://192.168.178.98/light/0?turn=on&brightnesss=100&transition=0

So, my advice => go with “GET”, you won’t need PUT for that, as it requires some more details:

rule "Testrule"
when
    something triggers
then
    sendHttpGetRequest("http://192.168.178.98/light/0?turn=on&brightnesss=10&transition=0")
end

If your trigger (e.g. item) also has an value for brightness, you can do

    sendHttpGetRequest("http://192.168.178.98/light/0?turn=on&brightnesss="+ITEMNAME.state+"&transition=0")

PS: I don’t have any Shellys, but there’s a binding for it, perhaps that’s a bit easier:

Thank you very much. For my understanding a GET Request is there to get some informations and store them e.g. in a variable.
A PUT request is to update some informations. Why is it better to use get request here?

For what i am trying to do the shelly binding isnt working. It is sort of limited.

read the Wikipedia entry on HTTP for a basic understanding:

As I said, I don’t have any Shellys and don’t know about their Web-API. But if there’s a GET-based API, then just use it. If there’s a POST-based API, you’ll have to use that. You can’t change the way an API works on the Client-side. ever.
The Shellys obviously use an GET-based API, so there’s that.-

You’re right, as GET should be used for retrieving information, but obviously Shelly did it otherwise.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.