Automation stopped working or I messed up something

In general, the delay stopped working. Everything used to work! Below I will show examples that don’t work:
Example # 1
There is a xiaomi button and a relay. When you press the button, the ventilation turns on, when you press the button again, the ventilation turns off. If you do not press the button, then after 10 minutes the ventilation turns itself off.

description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: e786d9c40f50cc77441cd90c09580692
    type: click
    subtype: single
    discovery_id: 0x00158d0001d87cb4 click_single
condition: []
action:
  - type: toggle
    device_id: 8446042dfdd4dfe2ad33a406427b9488
    entity_id: switch.vytiazhka_i_teplyi_pol_l2
    domain: switch
  - if:
      - condition: state
        entity_id: switch.vytiazhka_i_teplyi_pol_l2
        state: "on"
        for:
          hours: 0
          minutes: 10
          seconds: 0
    then:
      - type: turn_off
        device_id: 8446042dfdd4dfe2ad33a406427b9488
        entity_id: switch.vytiazhka_i_teplyi_pol_l2
        domain: switch

How can I fix the code so that it works without creating a separate shutdown automation?
Example # 2
There is a xiaomi socket with a power button, a light sensor, a motion sensor. When motion is detected, if the light level is less than 600, the light turns on. If there is no movement for 3 minutes, then the light turns off. Additionally, if I turn on the light with the button on the outlet, the light will work constantly.

alias: Автоматическое включение светом над раковиной
trigger:
  - platform: state
    entity_id: binary_sensor.datchik_dvizheniia_rakoviny_occupancy
    to: "on"
  - platform: state
    entity_id: binary_sensor.datchik_dvizheniia_rakoviny_occupancy
    to: "off"
    for:
      minutes: 3
condition:
  - condition: numeric_state
    entity_id: sensor.datchik_osveshcheniia_illuminance_lux
    below: 600
  - condition: state
    entity_id: switch.rozetka_osveshcheniia_rakoviny
    state: "off"
action:
  - service: >-
      switch.turn_{{
      states('binary_sensor.datchik_dvizheniia_rakoviny_occupancy') }}
    entity_id: switch.rozetka_osveshcheniia_rakoviny

A month ago, these automations worked, but after the updates they stopped working. Or I’m confusing something. Please help me!

at first glance I don’t see any reason why the second one shouldn’t work as you describe.

But the first one I don’t think should have worked as you explained it should.

as soon as you push the button the switch will toggle.

But then it will immediately test that the switch has been on for 10 minutes which, in either case of the toggle just turning the switch on or off, won’t ever be true so the automation ends.