Not sure why you need the “above” line in the trigger. As I understand it, the actual trigger is dropping below 50 for 5 minutes.
Multiple conditions are “and” by default, so you don’t need that line.
You don’t really need to test to see whether the plug is on - if it’s off already the switch.turn_off command won’t make any difference.
To make it more concise you might consider using a threshold helper in the trigger and a time of day helper in the condition.
The automation as it is now will trigger when power falls below 50W for five minutes. If the time is before 00:30 it will stop. It will not trigger again until power goes above 50W and falls below 50W for a second time.
Crossing the threshold means that the trigger only fires if the state wasn’t previously within the threshold.
If the consumption is below the thresold before the period in which I want to detect it, nothing triggers.
I would need a sensor like a numeric value with a duration attribute.
Perhaps should I try to cron every 5 minutes a check of the value, keep the previous one in something like a variable, compare with the current, and trigger if both are below 50W.
I’m surprised this doesn’t already exist in HA !? Because this can be apply to multiple circumstances.
Definitely not. Do as Stiltjack suggests: two triggers, matching conditions, so that both have to be true before proceeding. Here you go, with lots of unnecessary cruft removed:
alias: Shutdown Home Cinema
trigger:
- platform: numeric_state
entity_id: sensor.plug_num3_power
for: "00:05:00"
below: 50
- platform: time
at: "00:30:01"
condition:
- condition: time
after: "00:30:00"
before: "06:00:00"
- condition: numeric_state
entity_id: sensor.plug_num3_power
below: 50
- condition: state
entity_id: switch.plug_num3
state: "on"
action:
- service: switch.turn_off
entity_id: switch.plug_num3
mode: single