I made some experiments with HASS and an endopoin based on ESP8266.
I created a REST switch and I set:
switch:
- platform: rest
resource: http://IP_ADDRESS/led
I have no problem sendind POST parameters to the ESP8266 which turn on LED correctly, but I cannon send the proper GET data to HASS and my switch turn off into the web UI.
Can someone provide an example of JSON/template I need to send back to HASS from my microcontroller?
You’re not using a standardized component so there’s no way anyone could tell you what you need to send to modify the light state or what the microcontroller may send back to that response or if there’s an endpoint to get the status. Do you have the code somewhere public?
I use this thread as a reference whenever I want to use the HA rest api. I’m sure there is some documentation somewhere, but the example is always enough for me
My issues is about ‘is_on_template’ parameter. I read documentation but it’s not so clear.
Actually on the GET I send as response this JSON:
{“is_active” : true/false}
so what is the right template for this?
Default is equivalent to ‘{{ value.json == body_on }}’. This means that by default, the state of the switch is on if and only if the response to the GET request matches body_on
I went and checked the parent component docs and there’s nothing that details the variable that’s used to store response data. Maybe that should be added.
imho yes, it is
It will be cool to have small examples (or external links to them) in some sections of documentation too, so it’s more easy to understan what you are doing.
@lambtho
That’s very cool!
Thank’s a lot to suggestion