From eb9ba845d848d704a50d581f32a8da022634efa8 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 19 Dec 2015 23:13:49 -0800 Subject: [PATCH] Upgrade components with template docs --- source/_components/automation.markdown | 27 +++++++++++++++++++++++++ source/_components/light.mqtt.markdown | 6 ++++++ source/_components/sensor.rest.markdown | 6 +++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/source/_components/automation.markdown b/source/_components/automation.markdown index d90887ee8af..42ecbb4ea45 100644 --- a/source/_components/automation.markdown +++ b/source/_components/automation.markdown @@ -147,6 +147,17 @@ automation: offset: '-00:45:00' ``` +#### {% linkable_title Template trigger %} + +Template triggers work by evaluating a [template] on each state change. The trigger will fire if the state change caused the template to render 'true'. + +```yaml +automation: + trigger: + platform: template + value_template: '{% raw %}{% if is_state('device_tracker.paulus', 'home') %}true{% endif %}{% endraw %}' +``` + #### {% linkable_title Time trigger %} Time can be triggered in many ways. The most common is to specify `after` and trigger at a specific point in time each day. Alternatively, you can also match if the hour, minute or second of the current time has a specific value. For example, by only setting minutes in the config to 5 it will trigger every hour when it is 5 minutes past whole. You cannot use `after` together with hour, minute or second. @@ -215,6 +226,8 @@ automation: # At least one of the following required above: 17 below: 25 + # Optional + value_template: '{% raw %}{{ state.attributes.battery }}{% endraw %}' ``` #### {% linkable_title State condition %} @@ -229,6 +242,18 @@ automation: state: not_home ``` +#### {% linkable_title Template condition %} + +The template condition will test if [given template][template] renders a value equal to true. + + +```yaml +automation: + condition: + platform: template + value_template: '{% raw %}{{ state.attributes.battery }}{% endraw %}' +``` + #### {% linkable_title Time condition %} The time condition can test if it is after a specified time, before a specified time or if it is a certain day of the week @@ -302,3 +327,5 @@ INFO [homeassistant.components.automation] Initialized rule Rain is over The Logbook component will show a line entry when an automation is triggered. You can look at the previous entry to determine which trigger in the rule triggered the event. ![Logbook example](/images/components/automation/logbook.png) + +[template]: /getting-started/templating/ \ No newline at end of file diff --git a/source/_components/light.mqtt.markdown b/source/_components/light.mqtt.markdown index 2efd163e0b4..07c24d8eaa7 100644 --- a/source/_components/light.mqtt.markdown +++ b/source/_components/light.mqtt.markdown @@ -33,6 +33,9 @@ light: brightness_command_topic: "office/rgb1/brightness/set" rgb_state_topic: "office/rgb1/rgb/status" rgb_command_topic: "office/rgb1/rgb/set" + state_value_format: "{% raw %}{{ value_json.state }}{% endraw %}" + brightness_value_format: "{% raw %}{{ value_json.brightness }}{% endraw %}" + rgb_value_format: "{% raw %}{{ value_json.rgb | join(',') }}{% endraw %}" qos: 0 payload_on: "ON" payload_off: "OFF" @@ -63,6 +66,9 @@ Configuration variables: - **brightness_command_topic** (*Optional*): The MQTT topic to publish commands to change the light's brightness. - **rgb_state_topic** (*Optional*): The MQTT topic subscribed to receive RGB state updates. - **rgb_command_topic** (*Optional*): The MQTT topic to publish commands to change the light's RGB state. +- **state_value_format** (*Optional*): Defines a [template](/getting-started/templating/) to extract the state value. +- **brightness_value_format** (*Optional*): Defines a [template](/getting-started/templating/) to extract the brightness value. +- **rgb_value_format** (*Optional*): Defines a [template](/getting-started/templating/) to extract the RGB value. - **qos** (*Optional*): The maximum QoS level of the state topic. Default is 0 and will also be used to publishing messages. - **payload_on** (*Optional*): The payload that represents enabled state. Default is "ON". - **payload_off** (*Optional*): The payload that represents disabled state. Default is "OFF". diff --git a/source/_components/sensor.rest.markdown b/source/_components/sensor.rest.markdown index a7ffa015c44..59bfb47f70a 100644 --- a/source/_components/sensor.rest.markdown +++ b/source/_components/sensor.rest.markdown @@ -20,9 +20,9 @@ To enable this sensor, add the following lines to your `configuration.yaml` file sensor: platform: rest resource: http://IP_ADDRESS/ENDPOINT + value_template: '{% raw %}{{ value_json.thermostat }}{% endraw %}' method: GET name: REST GET sensor - value_template: '{% raw %}{{ value_json.x }}{% endraw %}' unit_of_measurement: "°C" ``` @@ -34,7 +34,7 @@ sensor: platform: rest resource: http://IP_ADDRESS/ENDPOINT method: POST - value_template: '{% raw %}{{ template }}{% endraw %}' + value_template: '{% raw %}{{ value_json.thermostat }}{% endraw %}' payload: '{ "device" : "heater" }' name: REST POST sensor unit_of_measurement: "°C" @@ -44,7 +44,7 @@ Configuration variables: - **resource** (*Required*): The resource or endpoint that contains the value. - **method** (*Optional*): The method of the request. Default is GET. -- **value_template** (*Required*): Defines a [template](/getting-started/templating/) to extract the value. +- **value_template** (*Optional*): Defines a [template](/getting-started/templating/) to extract the value. - **payload** (*Optional*): The payload to send with a POST request. Usualy formed as a dictionary. - **name** (*Optional*): Name of the REST sensor. - **unit_of_measurement** (*Optional*): Defines the unit of measurement of the sensor, if any.