HTTP Shortcuts for Android - what is wrong?

Hi ih8gates,

I must say - that is just amazing. You solved it! I’ve been messing with it for two days and you just spot the problem right away. Thanks a lot!

Awesome. A good tip: test everything in the services dev tool (bottons at bottom of sidebar) first - especially when you’re looking to use the REST API. It’ll save you lots of headaches.

Yeah, that’s really a good tip. I will definitely do it in the future :slight_smile:
Thanks again and have a nice weekend!

can you tell me the structure of the http cpommand?

I am trying but I always get error 404 or 401 …

newb :slight_smile:

Hi, sure thing! HTTP command, is it the URL you want to see? In that case:
http://your_domain:8123/api/services/light/turn_on?api_password=your_passwd

I hope you get it right!

Here’s a way to figure out the URL for any API call:

  • Open the services dev tab (icon at bottom of sidebar that looks like a remote control)
  • Hit F12 in your browser (or whatever turns on developer tools for your browser). Switch to the network tab of your browser’s developer tools.
  • Pick the service you want a URL for and enter the appropriate service data
    (it’ll be in JSON format. A typical value is {“entity_id”:“switch.switchname”}
  • Press the “call service” button and watch for an entry to appear in your network tool below. In Chrome, if I click on the entry, it’ll display the full URL

In practice, you’ll need to remember a few things:

  • You’ll need to append (assuming you’ve set one up) the API password to that URL, so it’ll look like what’s in @Jojojo’s example: http://your_server/api/services/light/turn_on?api_password=your_passwd
  • You need to format this as a POST (URLs that you put in your address bar are GETs). Postman is a good tool for testing POSTs
  • The service data (that JSON code) gets passed as the body or data for your call. If you’re using IFTT with a service that doesn’t require data (like calling a scene directly rather than using scene.turn_on), you may need to pass empty JSON like: {}
3 Likes

Is working!

For the Hue light which is the list of the commands? turn_on turn_off … and? How to put single light bulb or group?

I press call service, but where is the URL?

You need to switch to the network tab. You’re viewing “elements” (see the blue underline).

Thanks, found it.

With this system I need to understand JSON commands, a bit too much work.

Any other way to do it more easily? Like an app or something where you run the command and it gives you the URL?

I want just to use existing commands (for example a scene for Philips Hue) run it, copy the URL, paste the URL in Http shortcut, and have a simple button on my smartphone home doing the command

If you’re going to use the API for anything, understanding a bit of JSON is required. It maps to the same data you’d send to a service in HASS. The service page even gives you the possible arguments.

Just think of JSON as a list with attribute/value pairs. A semicolon splits the attribute/value pair, a comma splits multiple groups of attributes/values.
{
“attribute1”:“value1”,
“attribute2”:“value2”,
}

Hi, I’m glad to hear that you’ve got it working! It’s pretty neat to just click an icon on your homescreen rather than open home assistant just to turn a light on or off.

Sorry, but I don’t know the commands to control Philips Hue. But I’m sure you will find it on home assistants website!

Ok, why is this not working?
Domain light
Service turn_on
JSON below

{“attributes”: {“brightness”: 144, “color_temp”: 443, “friendly_name”: “TV Standing Lamp”, “rgb_color”: [249, 180, 82], “supported_features”: 127, “xy_color”: [0.5017, 0.4152]}, “entity_id”: “light.tv_standing_lamp”, “last_changed”: “2016-11-19T17:40:09.851663+00:00”, “last_updated”: “2016-11-19T17:40:09.851663+00:00”, “state”: “on”}

Not entirely sure what you’re trying to do. I’m guessing, you want:

http://your_domain:8123/api/services/light/turn_on?api_password=your_password

and

{“entity_id”: “light.tv_standing_lamp”,“brightness”: “144”, “color_temp”: “443”}

or similar. I don’t think you can call color_temp and rgb_color and xy_color at the same time.

Yes thanks, this part I figured it out that the command was not correct.

But where to look for the final URL to be copied and pasted in HTTP Shortcuts??

Like I said - look at the network tab in your browser’s dev tools. Click on the entry in the network log and it’ll give the whole URL. You’ll have to append the ?api_password=xxx part.

And? That’s correct. Add the API password…
http://192.168.1.12:8123/api/services/light/turn_on?api_password=whatever_it_is

and make sure you’re using post and passing the correct JSON:
{“entity_id”: “light.tv_standing_lamp”,“brightness”: “144”, “color_temp”: “443”}

or whatever.

thanks, working

Sorry if this is a stupid question, but is it a security risk putting the API password in plain text in the web address of the request?

It’s not great being plain text but folks are likely only doing that on a private network.

Using SSL would be better.