Now I want to switch off individual specific switch under HA and for that I am passing below command but it is not working, It still switches on or off ALL my switches
switch.bedrrom_light is the entity of my Bedroom light. Above command, no only switches the light but also all other switches like my speakers and my table lamp, even though they all have different seperate entity IDs
I know something is wrong with the syntax, can anyone assist how to pass RestAPI for apecific devices/entity id from URL
OK what would be the correct syntax for POST method. basically I need to control my switches independently via Rest API HTTP. Can you assist how I can do that.
I am using Postman google extension to test BTW.
Below is the POST syntax as per HA
POST /api/services/domain/service
I dont see where my URL is getting wrong
LET ME ADD … In Postman google extension if I enter the command like below
192.168.88.101:8123/api/services/switch/turn_on
and then under Body as RAW data I add
{
“entity_id”:“switch.bedroom_light”
}
This works as it should … meaning it “ONLY” switches off the bedroom light. BUT BUT
if I want to pass the entire command as one single URL, like below
Using the POST method (which is what the API requires() you can’t send all the data via just the URL, that’s not how HTTP works. You need to hit the URL with a Post request which takes the additional data and supplies it in the body of the request, not as part of the URL.
The CURL examples in the API docs show how you can do this from the command line. If you are doing this from Python or some other language, the appropriate libraries will have parameters that allow you to specify a POST request and supply the parameters.
I am using imperihome to execute an HTTP request from where I want to controll my switches via HTTP request. Also using Google Postman to test, where it works if I put the arguments in body under RAW. as I have shown in my edited post above.
But this is not what I want I want to use the entire command in one URL like below
I understand what you are trying to do, but read my post above - you can’t do this with just a URL, you need to tell Imperihome to use a POST request and supply the parameters (I have no idea if Imperihome can actually do that)
OK then what the solution .If the URL => …http://192.168.88.101:8123/api/services/switch/turn_on works in imperihome and switches on all my switches, there must be a way to “only” switch on specific switch via same URL ???
imperihome can take a URL and I can also choose “get” or “post” which obviously I chose POST and then past the URL there.
I made some progress … if you can call it a progress. I thought maybe I do not have HTTP password set in YAML file, it might be the reason, so I set the api_password in my YAML file, I supplied the below url to it.
Do you not have a password on your HA instance? Because if you do, you need to specify it in the POST request. None of the examples you gave show this, which is why I asked. I would think a password would be required to access the REST API in HA, just out of security concerns.
rpitera, I have set the password in my HA instance as I mentioned in the above post …and I am passing the same, it works, BUT when I pass JSON it says “Login attempt or request with invalid authentication from 192.168.88.116”, which is STRANGE, as if the authentication was the issue it would have failed when I passed the url WITHOUT JSON parameters.
Thanks for the assistance anyway,wish I can solve this. Its the only last link pending in my complete ROOM automating
I managed to solve it. Big thanks to ih8gates member who point me towards IFTTT.
I created an event in IFTTT and in the “then” part connected it to the web request,
IFTTT was already added to YAML file with the KEY. Then was just a matter of passing the below URL
and that switched on the Lights and only lights and not the speakers. I provided the same URL in Imperihome and IT WORKED!!!
The only tiny complaint is that its bit slow, I mean its takes 1-2 seconds after the button is pressed, Plus I cannot use local IP from IFTTT, I had to use DDNS and fw the HA IP, which I personally did not want to, but if that’s the only way to solve this so be it … I am happy. …