How can i get the current state of a device

Hey Guys, so I would like to know if it’s possible to get a customized response after requesting a link on Node-Red. A example:

After opening this link: http://192.168.3.123:1880/endpoint/living-lights/on, i’m able to turn on my lights. My idea now is to create a link like: http://192.168.3.123:1880/endpoint/living-lights/current-status, where i can get a response like:

The only thing that i need to know is how to get to this last picture where it shows { Current Lights State: ON}. I edited the Page Source to show that, so you guys can understand what i’m trying to get.

It’ possible to get that response, or anything similar, on Home Assistant? I would love to make it possible using Node-RED, but i’m open to any other solutions.

Look into the http request node, which should do it.
You might even be able to set the return field to a parsed JSON to just get “on” in the msg.payload.

What about the Home Assistant API?

1 Like

Hey everyone, updating this topic. So to get the custom response is actually very simple, just use a “template function”, you can write up anything there basically. That together with the “current state”, is just what i was looking for.

Hi, could you please provide some details how to do this with Node-Red ? Are you using http request node or http in & http response nodes ?

Http In – Used to set the link that i’m accessing to make an action possible: :1880/light-1/on
Http Respose – Used to end the Request, otherwise it will be waiting forever to a respose, so just give it one, even if it’s not true.
Call Service – Do the action that i want when i access the link specified by Http In

Note that you can do different functions on Http In, if you’re planning to do it by your browser use GET.