mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-21 08:16:53 +00:00
Adds 'Python Scripts' documentation on using responses from services. (#29151)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
d14aed6632
commit
b851c3e6dc
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user