diff --git a/source/_integrations/python_script.markdown b/source/_integrations/python_script.markdown index 8b7de9877f9..351d5c40f21 100644 --- a/source/_integrations/python_script.markdown +++ b/source/_integrations/python_script.markdown @@ -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 `/python_scripts` folder. Using the above Python script as an example, the `services.yaml` file would look like: