RestAPI switching on/off all the devices :( :(

Hi All,

This would be my second post on HA forum and I really hope that Gurus here will be able to assist me on my this issue as well as that did to my first one.

I am Using HA with a Z wave socket (connected to Veralite) to provide power to my speakers. I am also using MQTT to control my sonoff device. Both these devices succcessfully show up under HA dashboard.

Now on Mobile I am using Imperihome to controll both my these devices. z wave shows by default, but for MQTT sonoff device the only way to have it on Imperihome is via HTTP req that via RestFULL API.

Here is the scenario …I DID MANAGE to control the device via below HTTP API command.

http://192.168.88.101:8123/api/services/switch/turn_on?{“entity_id”:“switch.bedroom_light”}api_password=mypassword

Since both the devices are switch type the entity ID is “switch”. For some reason, my Network and Rpi HA devices got rebooted. When things came back EVERYTHING worked as it should EXCEPT the above API HTTP command NOW switches BOTH the devices. Even though the Device ID for both are different

switch.bedroom_light
switch.bedroom_speakers_5

I DONT know what happened, but now the above API is not working as it should. Hair Pulling thing is…the same API HTTP command was WORKING perfectly before that reboot happened.

I have tried restarting …veralite, HA on Rpi, my sonoff. everything I HAVE NO IDEA what has gone wrong.

Can someone assist before I turn Bald …:frowning:

Is there no one who can assist me on this ,…??? Its really irritating, when both the devices start when I only want to switch on one ?? Please assist

I would double check the syntax for your HTTP POST command in the third party app.

Sounds like it is just sending the switch.turn_on service without an entity, which would turn all switches on

Perhaps the entity_id is invalid?

try using the POST command from another app - like maybe the postman chrome app

The syntax I use includes the password in the URL part of the call so:

url: http://192.168.88.101:8123/api/services/switch/turn_on?api_password=mypassword
JSON: {“entity_id”:“switch.bedroom_light”}

the alternative is including the password in the JSON headers - per the documentation

Hi , Thanks phileep,

I changed a few things and now I am facing a new issue…

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.

http://192.168.88.101:8123/api/services/switch/turn_on?api_password=mypassword

it works…, BUT when I pass JSON it says, like below…

http://192.168.88.101:8123/api/services/switch/turn_on?api_password=mypassword{“entity_id”:“switch.bedroom_light”}

it says

“Login attempt or request with invalid authentication from 192.168.88.116”, which is STRANGE, coz 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

Also phileep. coming to original issue, the entity id is correct, have quadraple checked … the command is working in Postman chrom extension, BUT not as a single URL, if I pass the url like below

http://192.168.88.101:8123/api/services/switch/turn_on?api_password=mypassword

and pass the JSON in the BODY tag as RAW data like below

{
“entity_id”:“switch.bedroom_light”
}

It works!!,… as in… it only switches on the correct switch and not all …

but IF I pass it as a complete URL, like below

http://192.168.88.101:8123/api/services/switch/turn_on?api_password=mypassword{“entity_id”:“switch.bedroom_light”}

It switches on all the switches…!!! Wierd

The problem is Imperihome does not have the abillity to insert BODY, it only gives me the option to put URL and choose GET or POST. Else it might have worked. Looks like I have to start looking for alternative of Imperihome (But as far as i Know there isnt)…:frowning:

Then I thought of the password things and there when I tried as explained in the above post, I am facing another new issue of authentication failure … :frowning:

i think home assistant is the alternative :wink:
what cant you do with home assistant that you can do with imperihome?

HA does not have an Android App … Imperihome has a very nice app with an intuitive dashboard that looks awsome. Plus is can incorporate different automation devices. HA you can only set it as a browser shortcut and it looks very ordinary. HA is good for other things but as a stand alone dashboard for TAB, Imperihome is much better (untill now I guess when I cannot make ti work for simple POST HTTP API)… :frowning:

for HA there is HADashboard.

this is how it looks on my tablet

i have take a quick look at that app but i think all devices you can run with that app can also be run with HA.

Looks good, but to be honest, dont mind not as good as Imperihome Dashboard. See below a sample example …

BUT if it aint working it aint working so I cannot crib about it much … can you suggest how to use HADashboard, the article on HA just gives an introduction, and no info as to how to get started with it …

there is a new HADashboard.
and with that you can create your own skins to let it look just like your app.
maybe not all options are there but its still being developed.

take a look at this thread:

1 Like

Hi Rene,

I would like to create my own DashBoard, since HA Dashboard is also running on a webserver and can be accessed via browser. I wouldl ike to try creating my own dashboard via Home Assistant Server Sent Event if you willaccess the link I provided I went through the installation as directed, but when I try to access the URL http://[your_hass_host]:8123/local/index.html it gives me 404: Not Found error. ANY IDEA?

nope, sorry i am absolutely not familair with that part. ( icould imagine that you also need to provide your HA password)
this is just a small part which enables you to create your own frontend part, but as far as i see it it hasnt even an option for switches.

i would advise you to use the HADashboard i pointed you to.
it is way more flexible and a lot better supported

I’m not sure Dash is going to be the proper solution for him as it is designed to run locally on the LAN where his app is mobile and works outside his LAN.

with the amount of people asking for the outside option, i am sure it is high on the list from Andrew.
but you are right i didnt think of that.

but the option he is trying to use now isnt much better in my eyes.

i guess i need to take some time to investigate how i can get the dashboard behind NGINX :wink:

While you’re rooting around in there, @turboc and I are still holding out hope that you’ll do an NGINX tutorial… :wink:

i already told you. just do an ordinairy NGINX install (intructions on the NGINX website)
its really nothing else then any other installation.
configuring after that is just a copy from my configuration.

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

https://maker.ifttt.com/trigger/EventName/with/key/myIFTTTKEY

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. … :slight_smile:

I am sticking with Imperihome afterall … :slight_smile:

Regards
Sammy

1 Like