Auto Lock/Unlock Automation for Door

I have 2 Eqiva Door Locks with ESP32 and Keyble with MQTT to HAS.
I use an Automation for automatic daily open and close the Door Lock.

It only works sometimes.
I also want to have on Saturday and Sunday another Time.

Currently it looks like this:

Is there and fault in my config? Maybe i have to use different ID´s for the Locks? Thanks for help.

LOCK 1:

alias: Auto Lock Haustüre
description: “”
trigger:

  • platform: time
    id: “21”
    at: “20:45:00”
  • platform: time
    at: “06:10:00”
    id: “6”
    condition: []
    action:
  • choose:
    • conditions:
      • condition: trigger
        id: “21”
        sequence:
      • service: lock.lock
        data: {}
        target:
        entity_id: lock.tuerschloss
    • conditions:
      • condition: trigger
        id: “6”
        sequence:
      • service: lock.unlock
        data: {}
        target:
        entity_id: lock.tuerschloss
        mode: single

LOCK 2:

alias: Auto Lock Schuppen
description: “”
trigger:

  • platform: time
    id: “21”
    at: “20:40:00”
  • platform: time
    at: “06:00:00”
    id: “6”
    condition: []
    action:
  • choose:
    • conditions:
      • condition: trigger
        id: “21”
        sequence:
      • service: lock.lock
        data: {}
        target:
        entity_id: lock.tuerschloss2
    • conditions:
      • condition: trigger
        id: “6”
        sequence:
      • service: lock.unlock
        data: {}
        target:
        entity_id: lock.tuerschloss2
        mode: single

Check the automation’s trace when the lock fails to open or close. If there are no errors in the trace then it means the problem may be due to weak Wi-Fi communication to the door lock.

Reference: Automation Troubleshooting

If you want to simplify the automation, you can do this:

alias: Auto Lock Haustüre
description: ""
trigger:
  - id: 'lock'
    platform: time
    at: '20:45:00'
  - id: 'unlock'
    platform: time
    at: '06:10:00'
condition: []
action:
  - service: 'lock.{{ trigger.id }}'
    target:
      entity_id: lock.tuerschloss

I suggest you use the Schedule integration to create a schedule entity indicating when the lock should be unlocked each day of the week.

The automation to control the lock becomes as simple as this:

alias: Auto Lock Haustüre
description: ""
trigger:
  - platform: state
    entity_id: schedule.hausture
condition: []
action:
  - service: 'lock.{{ 'unlock' if trigger.to_state.state == 'on' else 'lock' }}'
    target:
      entity_id: lock.tuerschloss

EDIT

Correction. Fixed the trigger.

1 Like

Thank you so much for the perfect Explanation

1 Like