API URL examples?

1,628 views
Skip to first unread message

Tobias Tobin

unread,
Feb 26, 2015, 3:25:39 PM2/26/15
to home-assi...@googlegroups.com
I am new to using REST API.  I was wondering if someone might give me a couple of examples of how I would use a url to do something like dim a light?  Say the light is light.game_room_torch.

I have been reading but I am not really understanding.  I've tried making changes in the UI and look at the terminal output but I still don't get it.  I thought maybe a couple of examples might help?

Theodor Lindquist

unread,
Feb 26, 2015, 3:57:05 PM2/26/15
to home-assi...@googlegroups.com
Hi,

You probably have to use some form of REST client in order to send data. Since all commands that are sent to home-automation (as far as I can tell) has to be sent by POST. Everything you can request from a browser only gives you information.


the first command is GET /api. You can call it by entering a URL like:


The api_password is of course the key you have configured in your config file.

The next step would be figuring out what services you can run. You can do this by using the GET /api/services command:


This will give you a "list" of the things you can input to <domain> and <service>.

So, like I said, if you want to make home-assistant do something using the REST API you probably have to use a REST client. An example is the Postman extension for Google Chrome. With this you can use the POST commands. The one you want is probably POST /api/services/<domain>/<service>. Use it like so:

The url for turning on a switch would be:

The url for turning off a switch would be:

The data you could send with this is (in the postman chrome extension send this as "raw" data)
{"entity_id": "switch.living_room"}

if you have a switch called "living room".

Good luck!

Tobias Tobin

unread,
Feb 26, 2015, 4:10:04 PM2/26/15
to home-assi...@googlegroups.com
Thank you.  I had already played around with the info in the documentation but I didn't understand how you specified identities and such when doing a POST (or how you indicated it was a POST for that matter).  I see now that it is not as I thought, and you have pointed me in the right direction.  I appreciate your help!

tobias.

Paulus Schoutsen

unread,
Feb 27, 2015, 12:44:59 AM2/27/15
to home-assi...@googlegroups.com
For what it's worth, you can try the documentation I clicked together in Apiary.io:
http://docs.homeassistant.apiary.io/#

I just realized how awful designed the API is. Oops.

Paulus

--
You received this message because you are subscribed to the Google Groups "Home Assistant Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to home-assistant-...@googlegroups.com.
To post to this group, send email to home-assi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/home-assistant-dev/7dc9e898-0a8f-476b-8d11-669c9c5a7544%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
It's nice to be important but it's more important to be nice.
Message has been deleted
Message has been deleted

Tobias Tobin

unread,
Feb 27, 2015, 1:20:50 PM2/27/15
to home-assi...@googlegroups.com
Thank you for the link.  Another source of documentation wills surely help.  I like the way it is formatted too. 
 
I took Theodor's advice and was able to get some interactions going using Postman in Chrome.  I dimmed lights, things like that.  Thank you again Theodor for pointing me in the right direction!


Thank you Paulus for pointing me to the additional API documentation!

I am still really set on voice activation.  My research has turned up that while you can use a Kinect with Linux, the speech recognition is not good.  In addition, I have already worked with speech recognition programming in C# in .Net with good success.

Right now the only way I see I can combine the two is I need to either create my own app to run on my systems doing the speech recognition and speech responses, and then use the REST API to send the commands to Home Assistant.

Sounds like a lot of work :)  I still have this feeling that we are just at the beginnings of the HA revolution.  We are at the pioneering stage.  Who knows what things will be like in a few years.  Regardless, I think we enjoy this kind of stuff, and the challenges.  And people like you create something that gives people like me something to explore.

I was really surprised about something.  I blogged yesterday morning about the Wink hub and Home Assistant, etc.  I was doing a google search later that day, and my blog post was on the first page of results.  I had now idea things got indexed that quick.  I think if more people knew about HA they would be here.

CastleOS released the details on their hub yesterday.  It looks to be a custom PC + hub.  Not inexpensive, but considering what it is, not bad.  They have the only software I know of that can use a Kinect for voice and it works very nicely but their software is still pretty young, and there is not a lot of documentation, and no Wink support.  I guess what I am getting at is I am using a demo of their software for my Kinects but since it will expire soon, and it costs $200, I think I am just going to write my own speech app and like I said, speech -> recognition -> api command -> Home Assistant.

ttyl,
tobias.
Reply all
Reply to author
Forward
0 new messages