Adds 'Python Scripts' documentation on using responses from services. (#29151)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Marekjdj 2023-10-07 13:19:32 +02:00 committed by GitHub
parent d14aed6632
commit b851c3e6dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,6 +128,14 @@ The above `python_script` can be called using the following YAML as an input.
rgb_color: [255, 0, 0]
```
Services can also respond with data. Retrieving this data in your Python script can be done by setting the `blocking` and `return_response` arguments of the `hass.services.call` function to `True`. This is shown in the example below, in this case, retrieving the weather forecast and putting it into a variable:
```python
# get_forecast.py
service_data = {"type": "daily", "entity_id": "weather.YOUR_HOME"}
current_forecast = hass.services.call("weather", "get_forecast", service_data, blocking=True, return_response=True)
```
## Documenting your Python scripts
You can add names and descriptions for your Python scripts that will be shown in the frontend. To do so, simply create a `services.yaml` file in your `<config>/python_scripts` folder. Using the above Python script as an example, the `services.yaml` file would look like: