From 3dec0a3a585e511e2194e891aeabf3812b121ca6 Mon Sep 17 00:00:00 2001 From: Mahasri Kalavala Date: Fri, 9 Feb 2018 16:56:34 -0500 Subject: [PATCH] added service call example (#4606) * added service call example * Minor changes --- source/_components/python_script.markdown | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/source/_components/python_script.markdown b/source/_components/python_script.markdown index a470ec3960c..5e03edc16c0 100644 --- a/source/_components/python_script.markdown +++ b/source/_components/python_script.markdown @@ -44,4 +44,21 @@ hass.bus.fire(name, { "wow": "from a Python script!" }) } ``` -For examples, visit the [Scripts section](https://community.home-assistant.io/c/projects/scripts) in our forum. +## {% linkable_title Calling Services %} + +The following example shows how to call a service from `python_script`. This script takes two parameters: `entity_id` (required), `rgb_color` (optional) and calls `light.turn_on` service by setting the brightness value to `255`. + +```python +entity_id = data.get('entity_id') +rgb_color = data.get('rgb_color', [255, 255, 255]) +if entity_id is not None: + service_data = {'entity_id': entity_id, 'rgb_color': rgb_color, 'brightness': 255 } + hass.services.call('light', 'turn_on', service_data, False) +``` +The above `python_script` can be called using the following JSON as an input. + +```json +{"entity_id": "light.bedroom", "rgb_color": [255, 0, 0] } +``` + +For more examples, visit the [Scripts section](https://community.home-assistant.io/c/projects/scripts) in our forum.