Tasmota automatically turning off switch

I have smart switch Blitzwolf SPH6 with Tasmota 8.1 firmware connected to dishwasher.
My goal is to turn it off after 5 min. if there is power consumption below 5W for 5 minutes. So i wrote automation:

- alias: 'Wyłącz zmywarkę po spełnieniu określonych warunków'
  trigger:
      - platform: numeric_state
        entity_id: sensor.gniazdko_kuchnia_zmywarka_energy_power
        below: 5
        for: 00:05:00
  condition:
    - condition: state
      entity_id: switch.gniazdko_kuchnia_zmywarka
      state: 'on'
      for: 00:02:00
  action:
      - service: switch.turn_off
        entity_id: switch.gniazdko_kuchnia_zmywarka

Unfortunatelly if the switch is turned on manually it doesn’t turn off after 5 minutes (I checked history of sensor.gniazdko_kuchnia_zmywarka_energy_power and it shows 1-2W for 5 minutes period and nothing happens - it’s still on, logs don’t show anything). What am I missing or doing wrong?

Your trigger for the automation is using a sensor value, so if that value is not being met, the automation will not run.

This is an automation of mine that does the same thing you are looking for, adjust to suit your sensors/names.

# DRYER IS ON STANDBY - TURN OFF #
- alias: Dryer is on Standby - Turn Off
  initial_state: true
  trigger:
    platform: template
    value_template: "{{ states('sensor.kogan_pow_2_energy_power') | int < 10 }}"
    for:
      minutes: 5
  condition:
    condition: template
    value_template: '{{ states.sensor.uptime.state > "0.02" }}'
  action:
    service: switch.turn_off
    entity_id: switch.kogan_pow_2

Any reason you are using templates for both the trigger and condition when you could use the numeric_state platform?

I don’t understand this line. I tried to find a sensor which shows how long the switch is on but I’ve not found it. Is it a template sensor? - it still doesn’t work if my code looks like that:

- alias: 'Wyłącz mikrofalówkę po spełnieniu określonych warunków'
  initial_state: true
  trigger:
    platform: template
    value_template: "{{ states('sensor.gniazdko_kuchnia_mikrofalowka_energy_power') | default(0) | int < 5 }}"
    for:
      minutes: 5
  condition:
    condition: template
    value_template: '{{ states.sensor.uptime.state > "0.02" }}'
  action:
    service: switch.turn_off
    entity_id: switch.gniazdko_kuchnia_mikrofalowka

This is just checking that HA has been online for at least 2 mins before this automation can run - protects against 0 values when HA is restarting and possibly triggering the automation to run.

Are you sure your switch value is staying under 5 constantly for 5 mins? I have found that some appliances of mine, dryer, dishwasher etc, can have little spikes sometimes that cause the value to jump and not stay below the threshold for the time it takes to trigger the automation.

6 one, 1/2 dozen the other. Achieves the same result. It’s just easy to copy/paste from other automations I have that use that config already.