Sonoff DW2 icm with Mini R1 Wifi

Hello all,

I try to automate the combination of a Sonoff DW2 with Mini R2 Wifi.
When the DW2 is off - closed the Mini R2 Wifi has to switch the light on.

This is what I tried so far without success:
IN CONFIG/CONFIGURATION.YAML:

trigger:
- platform: state
  value_template: "{% if is_state('binary_sensor.sonoff_10013988f3', 'on') %}Aberta
                         {% elif is_state('binary_sensor.sonoff_binary_sensor.10013988f3_lock', 'off') %}Fechada
                         {% elif is_state('binary_sensor.sonoff_binary_sensor.10013988f3_lock', 'Unavailable') %}Violada       
                         {% endif %}"
  entity_picture_template: "{% if is_state('binary_sensor.sonoff_10013988f3', 'on') %}/local/windowopen.png
                                  {% elif is_state('binary_sensor.sonoff_binary_sensor.10013988f3_lock', 'off') %}/local/windowclosed.png
                                  {% elif is_state('binary_sensor.sonoff_binary_sensor.10013988f3_lock', 'Unavailable') %}/local/exclamacao.png
                                  {% endif %}"
  for: '00:00:05' #This is set for 5 seconds. Adjust it accordingly. The format is HH:MM:SS.
action:
- service: >-
    light.turn_{{ trigger.to_state.state }}
  target:
    entity_id: switch.100140602a # WC licht HAL entity_id

And in automation I have added the following script:

Thank you in advance for your support.