Bit confused by Template Locks

I wanted to create a virtual lock to remind myself to check the door is locked after it has been closed. Closure is detected by a sensor.

In the GUI the Template Lock has an option for state, and locking/unlocking actions. Great - I created a boolean and used that as my state and configured the locking and unlocking actions. However, the lock state does not persist.

The documentation says to add it to your YAML configuration instead. I have done this, and it works - but it has left me wondering if I did it right or whether I simply set up the GUI Template Lock helper wrong. Why is the GUI option available if it does not work? Or is it for some other purpose?

Thanks for any clarifications!

Please post the configuration you are using or screenshot of the Helper config flow popup, so we can see what you actually did.

Yes sorry, I should have done that in the first instance.

This is my working yaml config:
template:
  - lock:
      - name: Kitchen Door Lock
        state: "{{ is_state('input_boolean.is_the_kitchen_door_locked', 'on') }}"
        lock:
          action: input_boolean.turn_on
          target:
            entity_id: input_boolean.is_the_kitchen_door_locked
        unlock:
          action: input_boolean.turn_off
          target:
            entity_id: input_boolean.is_the_kitchen_door_locked
This is my partially working helper:


Both use the same boolean as a state. The helper Kitchen Door Test will turn the boolean On when I click Lock. But it does not maintain its state. If I set the Boolean to Off and click Lock on Kitchen Door Test, then Kitchen Door Lock switches to Locked (as expected), but Kitchen Door Test does not.

I’m not super concerned as the documentation does say it should be done by configuration yaml not in the GUI. It just seems odd and it would be nice if it worked (I prefer my helpers in the GUI).

The state template should not have the quotes around it. Those are for yaml only.

It works! Such a simple error. Thank you, I would have never worked that out on my own.

1 Like