mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-16 22:06:50 +00:00
add a simple python sample
This commit is contained in:
parent
b7ad2c7188
commit
604fee3fdc
@ -18,12 +18,28 @@ In the package [`homeassistant.remote`](https://github.com/balloob/home-assistan
|
|||||||
|
|
||||||
The API accepts and returns only JSON encoded objects. All API calls have to be accompanied by the header `X-HA-Access: YOUR_PASSWORD` (YOUR_PASSWORD as specified in your `configuration.yaml`).
|
The API accepts and returns only JSON encoded objects. All API calls have to be accompanied by the header `X-HA-Access: YOUR_PASSWORD` (YOUR_PASSWORD as specified in your `configuration.yaml`).
|
||||||
|
|
||||||
|
There are several ways to consume the Home Assistant API. One is with `curl`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X GET \
|
curl -X GET \
|
||||||
-H "x-ha-access: YOUR_PASSWORD" \
|
-H "x-ha-access: YOUR_PASSWORD" \
|
||||||
http://localhost:8123/api
|
http://localhost:8123/api
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Another option is to use Python and the [Requests](http://docs.python-requests.org/en/latest/) module.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from requests import get
|
||||||
|
|
||||||
|
url = 'http://localhost:8123/api/'
|
||||||
|
headers = {'x-ha-access': 'YOUR_PASSWORD',
|
||||||
|
'content-type': 'application/json'}
|
||||||
|
|
||||||
|
response = get(url, headers=headers)
|
||||||
|
|
||||||
|
print(response.text)
|
||||||
|
```
|
||||||
|
|
||||||
<p class='note'>
|
<p class='note'>
|
||||||
You can append <code>?api_password=YOUR_PASSWORD</code> to any url to log in automatically.
|
You can append <code>?api_password=YOUR_PASSWORD</code> to any url to log in automatically.
|
||||||
</p>
|
</p>
|
||||||
@ -251,3 +267,4 @@ It will return a message if event forwarding was cancelled successful.
|
|||||||
<p class='note'>
|
<p class='note'>
|
||||||
If your client does not support <code>DELETE</code> HTTP requests you can add an optional attribute <code>_METHOD</code> and set its value to <code>DELETE</code>.
|
If your client does not support <code>DELETE</code> HTTP requests you can add an optional attribute <code>_METHOD</code> and set its value to <code>DELETE</code>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user