Sonoff DW2 WiFI state change in automation

Hello everyone!
This is my first post here and I’m quite new in HA as well.

I’m trying to set up simple automation.

  1. when DW2 sensor changes from “close” to “open”, switch on light.
  2. when DW2 changes from “open” to “close” delay 2 minutes and switch off light.

I have set up eWeLink, I can see binary sensor binary_sensor.100103b1a6_lock
with state “off” and changing to “on” when doors is open.
Under states I can see:

restored: false
friendly_name: Ardurvis-Lock
device_class: lock
state: 'off'

And the state is changing correctly.
What would be the correct way to add it in automation?
I have added as a trigger - entity binary_sensor.100103b1a6_lock, State from off to on, then activate scene “light on”
The last part is working correctly as if I run manually this automation light switches on, but it doesn’t start automatically on the door opening event.
I’m sure I’m doing something wrong :smiley: would be happy about suggestions :wink:

Try this-

trigger:
  - platform: state
    entity_id: binary_sensor.100103b1a6_lock
    to: 'on'
  - platform: state
    entity_id: binary_sensor.100103b1a6_lock
    to: 'off'
    for: '00:02:00' #This is set for 2 minutes. Adjust it accordingly. The format is HH:MM:SS.
action:
  - service: >-
      light.turn_{{ trigger.to_state.state }}
    target:
      entity_id: light.entity_id #Replace this with your light entity_id

Thanks, for an answer at some point it started to do the job.
As before posting I was trying all-around many things, perhaps there was something stupid like upper/lower case characters or other syntax mistakes.
That was one of the cases when night solves things - it just works in the morning, perhaps last changes before sleep did the thing.
Now I can confirm that it works only with all lower characters - ‘on’ and ‘off’. :smiley: But I’m not sure that was the case.