Turning smart plug off when power is below threshold

Hi folks,

I want to turn my smart plug (Shelly Plug S) off, when the power is under 50 W for 15 minutes.
I’ve tried to create a scene, which sould be activated by an automation.

Scene:

- id: '1674658056631'
  name: 'PDU_KW-PC: Aus'
  entities:
    switch.pdu_kw_pc:
      friendly_name: PDU_KW-PC
      state: 'off'
  icon: hue:room-computer-off
  metadata:
    switch.pdu_kw_pc:
      entity_only: true

Automation:

- id: '1674658163087'
  alias: 'PDU_KW-PC: Aus'
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.pdu_kw_pc_power
    for:
      hours: 0
      minutes: 15
      seconds: 0
    below: 50
  condition: []
  action:
  - service: scene.turn_on
    target:
      entity_id: scene.pdu_kw_pc_aus
    metadata: {}
  mode: single

Home Assistant 2023.1.7
Supervisor 2022.12.1
Frontend 20230110.0 - latest
Running on Debian 11

When I execute the scene or the automation the plug is switched off successfully.
In my opinion the problem is, that automations and scenes have the state on/off. Initially the automation works. But when anyone in the home switches the plug on manually, the automation doesn’t work anymore. This is just a suggestion.
Hopefully there exists a best practice for my use case.

The Numeric State Trigger you created will only trigger at the moment when the sensor’s value crosses the threshold of 50. In other words, it triggers only when the value decreases from above 50 to below 50. It’s the change from above 50 to below 50 that serves as the trigger.

So if the sensor’s value is 51 (or higher) and then changes to 49 (or lower), it will trigger (provided that it remains below 50 for at least 15 minutes and then it triggers).

Reference: Numeric State Trigger