Automation does not trigger from button in lovelace

I suspect it does not works at all. When I press activate in cog it works (turn on switch) but despite the delay time does not works. Can you kindly suggest?

- alias: arriving home Raffi

  trigger:

    platform: state

    entity_id: device_tracker.XXX

    from: 'not_home'

    to: 'home'

  condition:

    condition: sun

    after: sunset

  action:

  - service: switch.turn_on

    entity_id: switch.shelly_XXX

  - delay: 04:00

  - service: switch.turn_off

    entity_id: switch.shelly_XXX

solved:
put initial_state= on after alias on all your automations
That’s works