REST switch not working but CURL working

Hello All,
This is my first post here. I am now learning my way around the system. The reason I am posting is because I am having some problem getting a REST switch to work.

If I test out the switch in the command line

curl --header "Content-Type: text/plain" --request PUT --data "0" http://127.0.0.1:8080/rest/items/Dim2/state/

It works perfectly. If I replace “data” with 100 the light turns on fully. The switch is accessible via the url above.

However when I try to add the switch to my configuration I get the following error

ERROR:homeassistant.components.switch.rest:Can't turn off http://127.0.0.1:8080/rest/items/Dim2/state/. Is resource/endpoint offline?

Here is my config

switch:
  platform: rest
  resource: http://127.0.0.1:8080/rest/items/Dim2/state/
  name: "Bedroom Switch"
  body_on: "100"
  body_off: "0"

Any help would be great!!

Thanks

Have anyone used the RESTful API? Any help or ideas on this would be greatly appreciated.

I have the same issue…

Can anybody help ?

Are you using OpenHab as a back end?

No I am using HA as standalone …

I cant get my switch to hit my web endpoint … did you get it running ?

I did get it to work but the issue was the back end.

You may need to experiment with POST and PUT. Also the HTTP return code for the curl call sometimes is 201 instead of 200 from your device so it isn’t recognized as being successful in HA since HA is looking for 200.

can you help me with the sample response from the backend ? I totaly new to all this…

can you explain to me how this is supposed to work ? and what kind of response (json,xml) is HA expecting ?

thanks a tonne!!

I would appreciate any help with this …

right now my endpoint is returning this as GET

{"status":200,"data":"ON"}

is this not correct ?

my Config is this

switch: platform: rest resource: <redacted> name: "Sprinkler" body_on: "ON" body_off: "OFF"

what should I do to

a) Make the button sustain its state
b) Post values to take an action ?

thx for anybody’s help

I will attempt to help you but I need some information.

What type of switch is it?
Model?
Is it a dimmer?
How is it that it is exposed via REST?
What platform is it on?

its an inground sprinkler i made at home

i need to do an api call to

To Turn on my sprinkler - Zone 1 for 10 Minutes I hit this
http://<redacted>.com/sprinkler/zone1/10/on

To turn off i hit this link

http://<redacted>.com/sprinkler/zone1/off

its just an api call endpoint

I just need to know how do i hit those links with HA and Switches

Post an output using curl with the -v option from the command line