From a5e3f4eea482e551eae6773b151f6a2c37be2a35 Mon Sep 17 00:00:00 2001 From: Nikolay Vasilchuk Date: Thu, 11 Oct 2018 14:25:57 +0300 Subject: [PATCH] Template Lock (#6642) * Template Lock * :pencil2: Tweak * Update release --- source/_components/lock.template.markdown | 142 ++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 source/_components/lock.template.markdown diff --git a/source/_components/lock.template.markdown b/source/_components/lock.template.markdown new file mode 100644 index 00000000000..155ba139001 --- /dev/null +++ b/source/_components/lock.template.markdown @@ -0,0 +1,142 @@ +--- +layout: page +title: "Template Lock" +description: "Instructions on how to integrate Template Locks into Home Assistant." +date: 2018-10-09 19:00 +sidebar: true +comments: false +sharing: true +footer: true +ha_category: Lock +ha_release: 0.81 +ha_iot_class: "Local Push" +logo: home-assistant.png +ha_qa_scale: internal +--- + +The `template` platform creates locks that combines components. + +For example, if you have a garage door with a toggle switch that operates the motor and a sensor that allows you know whether the door is open or closed, you can combine these into a lock that knows whether the garage door is open or closed. + +This can simplify the GUI and make it easier to write automations. You can mark the components you have combined as `hidden` so they don't appear themselves. + +In optimistic mode, the lock will immediately change state after every command. Otherwise, the lock will wait for state confirmation from the template. Try to enable it, if experiencing incorrect lock operation. + +## {% linkable_title Configuration %} + +To enable Template Locks in your installation, add the following to your `configuration.yaml` file: + +{% raw %} +```yaml +# Example configuration.yaml entry +lock: + - platform: template + name: Garage door + value_template: "{{ is_state('sensor.door', 'on') }}" + lock: + service: switch.turn_on + data: + entity_id: switch.door + unlock: + service: switch.turn_off + data: + entity_id: switch.door +``` +{% endraw %} + +{% configuration %} + name: + description: Name to use in the frontend. + required: false + type: string + default: Template Lock + value_template: + description: Defines a template to set the state of the lock. + required: true + type: template + lock: + description: Defines an action to run when the lock is locked. + required: true + type: action + unlock: + description: Defines an action to run when the lock is unlocked. + required: true + type: action + optimistic: + description: Flag that defines if lock works in optimistic mode. + required: false + type: boolean + default: false +{% endconfiguration %} + +## {% linkable_title Considerations %} + +If you are using the state of a platform that takes extra time to load, the Template Lock may get an `unknown` state during startup. This results in error messages in your log file until that platform has completed loading. If you use `is_state()` function in your template, you can avoid this situation. For example, you would replace {% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an unknown result: {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} + +## {% linkable_title Examples %} + +In this section, you find some real-life examples of how to use this lock. + +### {% linkable_title Lock from Switch %} + +This example shows a lock that copies data from a switch. + +{% raw %} +```yaml +lock: + - platform: template + name: Garage Door + value_template: "{{ is_state('switch.source', 'on') }}" + lock: + service: switch.turn_on + data: + entity_id: switch.source + unlock: + service: switch.turn_off + data: + entity_id: switch.source +``` +{% endraw %} + +### {% linkable_title Optimistic Mode %} + +This example shows a lock in optimistic mode. This lock will immediately change state after command and will not wait for state update from the sensor. + +{% raw %} +```yaml +lock: + - platform: template + name: Garage Door + value_template: "{{ is_state('sensor.skylight.state', 'on') }}" + optimistic: true + lock: + service: switch.turn_on + data: + entity_id: switch.source + unlock: + service: switch.turn_off + data: + entity_id: switch.source +``` +{% endraw %} + +### {% linkable_title Sensor and Two Switches %} + +This example shows a lock that takes its state from a sensor, and uses two momentary switches to control a device. + +{% raw %} +```yaml +lock: + - platform: template + name: Garage Door + value_template: "{{ is_state('sensor.skylight.state', 'on') }}" + lock: + service: switch.turn_on + data: + entity_id: switch.skylight_open + unlock: + service: switch.turn_on + data: + entity_id: switch.skylight_close +``` +{% endraw %}