Drawer lock template

Hi all,

I have a small solenoid motor lock in my drawer that works really well. When it is given power (via a Sonoff 4CH R3) for 2 seconds it unlocks then locks again, enough time to open the drawer. I have a door sensor in the drawer which tells me if the drawer is open or closed.

I would like to create a lock template that actually shows the status of the drawer lock based on the status of the binary door sensor not if there is power going to the solenoid as this is only powered for 2 secs so as not to burn the small 24v motor.

I assume you’ve looked at the lock template docs?

Just use your door sensor in the value template.

I did see the lock template docs but still couldn’t figure it out. Now I’ve spent a little time working it out I have it working.

lock:
  - platform: template
    name: My Drawer Lock Patio
    value_template: "{{ is_state('binary_sensor.mie4aaec5f8ac7','off') }}"
    lock:
      service: switch.turn_on
      target:
        entity_id: switch.sonoff_my_drawer_lock
    unlock:
      service: switch.turn_on
      target:
        entity_id: switch.sonoff_my_drawer_lock

Thanks