Quick question about POST requests to ESPhome device

My overall goal is to have my sonoff rf bridge flashed with tasmota send REST API commands directly to my home-built ESPhome devices, without going through an MQTT broker. However, that means I first have to understand how to send a POST request to the esp device. If I send:
http://192.168.1.14/light/bedroom_lamp_light/
It returns
{"id":"light-bedroom_lamp_light","state":"OFF"}
which is great. But if I send,
http://192.168.1.14/light/bedroom_lamp_light/toggle
(or turn_off’) it does not change the state of the light. My understanding from the documentation is that should toggle the state. Can anyone tell me what I am missing?
(If anyone has accomplished something similar to my overarching goal, I will take help there, too!)

Does turn_on work. (with or without setting bright,ness?)

No, it does not turn on. BTW, it is really just a relay that I have set up so:


# Light Bulb Relay
output:
  - platform: gpio
    pin: D7
    id: lamprelay2

# Light entity
light:
  - platform: binary
    id: lamp_light2
    name: $entity_name
    output: lamprelay2

What does the log say?

The console doesn’t register anything.

How are you sending the rest commands?

I want to ultimately send them via tasmota rules, but right now just through a browser.

Just from the address bar? That is a GET not a POST I think.

Yeah, I think that you are right. I was hoping for a simple check that all my syntax was right.
It is probably OK, since the GET works. I just need to figure out how to send this via tasmota.
Thanks!

There is a simple way. I installed httpie (linux) and then ran

$ http POST 192.168.1.14/light/bedroom_lamp_light/toggle
HTTP/1.1 200 OK
Accept-Ranges: none
Connection: close
Content-Length: 0

and it works fine.

1 Like