From ccf6b4f43807e72b45bc87a79644234500f0cee1 Mon Sep 17 00:00:00 2001 From: Ashley Cawley Date: Mon, 24 Jan 2022 12:55:36 +0000 Subject: [PATCH] Added Python Example (#1143) --- docs/api/rest.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/api/rest.md b/docs/api/rest.md index bf7beb0c..e7b108bc 100644 --- a/docs/api/rest.md +++ b/docs/api/rest.md @@ -565,6 +565,21 @@ curl -X POST -H "Authorization: Bearer ABCDEFGH" \ http://localhost:8123/api/services/switch/turn_on ``` +Sample `python` command using the [Requests](https://requests.readthedocs.io/en/master/) module: + +Turn the light on: + +```shell +from requests import post + +url = "http://localhost:8123/api/services/light/turn_on" +headers = {"Authorization": "Bearer ABCDEFGH"} +data = {"entity_id": "light.study_light"} + +response = post(url, headers=headers, json=data) +print(response.text) +``` + Send a MQTT message: ```shell