This automation was working but it stopped - can't figure out why

Probably missing something obvious but I can’t see it.

- alias: LockFrontDoorNight
  trigger:
    platform: template
    value_template: "{% if is_state('lock.front_door_lock_locked', 'unlocked') %}true{% endif %}"
  condition:
    condition: time
    after: '21:00'
    before: '08:00'
  action:
    service: lock.lock
    entity_id: group.all_locks

probably because ‘after’ has been removed? Not sure if that’s true for template/condition, but for sure for platform: time.

I have a similar problem, my automation doesn’t work anymore. It used to work with after:, now I changed it to at: and it still doesn’t work (syntax error)

  • alias: ‘open gate at 8.00’
    initial_state: false
    trigger:
    platform: time
    at: ‘08:00:00’

It was removed as a trigger, as I understand it…But it is still valid as a condition. I was on .50.1 when it was working.

OK. Sorry then.

Strange enough, my problem suddenly went away.
Another automation was apparently broken that had been working before, too, but as I don’t use that anymore I just commented it out and now everything is back to normal.
Sometimes one should probably stick to ‘never change a running system’ :slight_smile:

Interesting. I just triggered my front door to lock from the front end and then unlocked it from the front end. The automation then triggered and locked the door.

I then went up and manually unlocked the door and it shows the event in the logbook “Front Door Changed to Unlocked” . Right after that it says “LockFrontDoorNight Triggered” but the lock is still unlocked so it never actually triggered the locking.

So there is something wonky with the state detection going on if I manually unlock the door.

Try it like the below.

  • alias: LockFrontDoorNight
    trigger:
    platform: template
    value_template: “{% if is_state(‘lock.front_door_lock_locked’, ‘unlocked’) %}true{% endif %}”
    condition:
    condition: or
    conditions:
    - condition: time
    after: ‘21:00’
    - condition: time
    before: ‘08:00’
    action:
    service: lock.lock
    entity_id: group.all_locks

The below is one of mine. You can also refer to it.

  • alias: Prince Room Veranda Auto Light
    trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d0001548730
    condition:
    condition: or
    conditions:
    - condition: sun
    after: sunset
    after_offset: “-0:30:00”
    - condition: sun
    before: sunrise
    before_offset: “0:30:00”

Updated the code to your suggestion but it still behaves the same way.

If I lock/unlock from the front end it will trigger the automation and lock the door.

if I manually unlock the door the automation doesn’t trigger and lock it even though in the logbook it says “LockFrontDoorNight has been triggered”