From de561e329e8284c63097e91e44d8b41524f15853 Mon Sep 17 00:00:00 2001 From: Gil Peeters Date: Sun, 8 Sep 2019 20:53:55 +1000 Subject: [PATCH 1/4] Added 'availability_template' to all Template Swicth platform --- source/_integrations/switch.template.markdown | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/_integrations/switch.template.markdown b/source/_integrations/switch.template.markdown index d98e57f85ebf..b5cfe099be8e 100644 --- a/source/_integrations/switch.template.markdown +++ b/source/_integrations/switch.template.markdown @@ -20,6 +20,7 @@ This can simplify the GUI and make it easier to write automations. You can mark To enable Template Switches in your installation, add the following to your `configuration.yaml` file: {% raw %} + ```yaml # Example configuration.yaml entry switch: @@ -35,7 +36,12 @@ switch: service: switch.turn_off data: entity_id: switch.skylight_close + availability_template: >- + {%- if not is_state('dependant_device.state', 'unavailable') %} + true + {% endif %} ``` + {% endraw %} {% configuration %} @@ -56,6 +62,11 @@ switch: description: Defines a template to set the state of the switch. required: true type: template + availability_template: + description: "Defines a template to get the `available` state of the component. If the template returns `true` the device is `available`. If the template returns any other value, the device will be `unavailable`. If `availability_template` is not configured, the component will always be `available`" + required: false + type: template + default: the device is always `available` turn_on: description: Defines an action to run when the switch is turned on. required: true @@ -87,6 +98,7 @@ In this section you find some real-life examples of how to use this switch. This example shows a switch that copies another switch. {% raw %} + ```yaml switch: - platform: template @@ -102,6 +114,7 @@ switch: data: entity_id: switch.source ``` + {% endraw %} ### Toggle Switch @@ -109,6 +122,7 @@ switch: This example shows a switch that takes its state from a sensor and toggles a switch. {% raw %} + ```yaml switch: - platform: template @@ -125,6 +139,7 @@ switch: data: entity_id: switch.blind_toggle ``` + {% endraw %} ### Sensor and Two Switches @@ -133,6 +148,7 @@ This example shows a switch that takes its state from a sensor, and uses two momentary switches to control a device. {% raw %} + ```yaml switch: - platform: template @@ -149,6 +165,7 @@ switch: data: entity_id: switch.skylight_close ``` + {% endraw %} ### Change The Icon @@ -156,6 +173,7 @@ switch: This example shows how to change the icon based on the day/night cycle. {% raw %} + ```yaml switch: - platform: template @@ -177,6 +195,7 @@ switch: mdi:garage {% endif %} ``` + {% endraw %} ### Change The Entity Picture @@ -184,6 +203,7 @@ switch: This example shows how to change the entity picture based on the day/night cycle. {% raw %} + ```yaml switch: - platform: template @@ -205,4 +225,5 @@ switch: /local/garage-closed.png {% endif %} ``` + {% endraw %} From 6a8c1dad2ad0aa83df32a37017c0ff4e3d4dd13e Mon Sep 17 00:00:00 2001 From: Gil Peeters Date: Sun, 8 Sep 2019 23:47:59 +1000 Subject: [PATCH 2/4] Fixed Syntax and default --- source/_integrations/switch.template.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/_integrations/switch.template.markdown b/source/_integrations/switch.template.markdown index b5cfe099be8e..64d8e7087800 100644 --- a/source/_integrations/switch.template.markdown +++ b/source/_integrations/switch.template.markdown @@ -63,10 +63,10 @@ switch: required: true type: template availability_template: - description: "Defines a template to get the `available` state of the component. If the template returns `true` the device is `available`. If the template returns any other value, the device will be `unavailable`. If `availability_template` is not configured, the component will always be `available`" + description: Defines a template to get the `available` state of the component. If the template returns `true` the device is `available`. If the template returns any other value, the device will be `unavailable`. If `availability_template` is not configured, the component will always be `available` required: false type: template - default: the device is always `available` + default: true turn_on: description: Defines an action to run when the switch is turned on. required: true From 94ecd5bfb37c925e937559cb0b573b1bf191f4ed Mon Sep 17 00:00:00 2001 From: Gil Peeters Date: Wed, 11 Sep 2019 07:30:42 +1000 Subject: [PATCH 3/4] Removed optional parameter from example config --- source/_integrations/switch.template.markdown | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/_integrations/switch.template.markdown b/source/_integrations/switch.template.markdown index 64d8e7087800..9d1bba7db10e 100644 --- a/source/_integrations/switch.template.markdown +++ b/source/_integrations/switch.template.markdown @@ -36,10 +36,6 @@ switch: service: switch.turn_off data: entity_id: switch.skylight_close - availability_template: >- - {%- if not is_state('dependant_device.state', 'unavailable') %} - true - {% endif %} ``` {% endraw %} From 9f72aa6981556f8fdf4d5e61ac9214c7b39bc5e2 Mon Sep 17 00:00:00 2001 From: Gil Peeters Date: Wed, 11 Sep 2019 07:30:54 +1000 Subject: [PATCH 4/4] Apply suggestions from code review Co-Authored-By: Franck Nijhof --- source/_integrations/switch.template.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/_integrations/switch.template.markdown b/source/_integrations/switch.template.markdown index 9d1bba7db10e..050b3f2b16a3 100644 --- a/source/_integrations/switch.template.markdown +++ b/source/_integrations/switch.template.markdown @@ -59,7 +59,7 @@ switch: required: true type: template availability_template: - description: Defines a template to get the `available` state of the component. If the template returns `true` the device is `available`. If the template returns any other value, the device will be `unavailable`. If `availability_template` is not configured, the component will always be `available` + description: Defines a template to get the `available` state of the component. If the template returns `true`, the device is `available`. If the template returns any other value, the device will be `unavailable`. If `availability_template` is not configured, the component will always be `available`. required: false type: template default: true