Constant value of a sensor as trigger

Hi,
is it possible to creat an automation whose trigger is a constant (unknown) value of a sensor during a period (e.g. 30 seconds)? The automation should fire if a power sensor of a smart plug doesn’t change during a few seconds. Of course there will be a few more conditions. :slight_smile:
How can I achieve that?

thanks in advance for any hint!
best regards
Rado

Try a template trigger. E.g.,

- trigger:
    - platform: template
      value_template: >
        {{ states('sensor.XYZ') | float == 30 }}
      for: 30

Note that this trigger will only fire when the template evaluates to true after having evaluated to false, and then stays true for 30 seconds. Of course, like all other triggers, this implies the necessity of a state change (in this case the state of sensor.XYZ changing from a value that causes the template to evaluate to false, to a value that cause the template to evaluate to true.)

Depending on the states of the sensor and exactly what you want, you may need a slightly more complex template, such as testing if the numeric value of the state is between two values.

Hi,
Thanks for your answer. Something seems not to work with this one.
What I am trying to do is this: I have a washing machine and a dryer in the laundry room that are connected to two smart plugs, but to one fuse. This fuse blows from time to time when both devices are running at the same time. I don’t see this in Home Assistant, and the smart plug of the washing machine doesn’t report a “finish” via the automation anymore, but the laundry just stays in the washing drum. If the smart plugs suddenly get no power, the sensors for current and power of the smart plugs continue to display the last measured value constantly. I want to take advantage of this, so that after a few seconds of completely constant power, a message is issued by Home Assistant “fuse blown”. In that case, I can turn the fuse back on and temporarily turn off one of the appliances without the laundry being in the drum for long.
So my idea was to use the constant value over a short period of time as a trigger, and as a condition that the device is on and the power is greater than 0.

Actually, what you wrote me should be enough, but I get an error:

Message malformed: extra keys not allowed @ data[‘entity_id’]
Do you have an idea what might have gone wrong?

Greetings
Rado

Translated with DeepL

What happens to the state of the switches when the fuse blows? If both switch states go to unavailable or unknown, you could use something like:

trigger:
  - platform: state
    entity_id:
      - switch.washing_machine
      - switch.dryer
    to:
      - unknown
      - unavailable
    for: "00:00:45"
condition:
  - condition: state
    entity_id:
      - switch.washing_machine
      - switch.dryer
    state:
      - unknown
      - unavailable
    for: "00:00:30"
action:
...

Can you share the YAML of what you wrote? What I suggested had no entity_id key, so should not have caused such an error.

But, given your further clarification, I would suggest something different. E.g., you could create a template binary sensor that is on whenever the sensor changes state, and then goes off whenever it doesn’t change state for some period of time. E.g.:

template:
  - trigger:
      - platform: state
        entity_id: sensor.XYZ
    binary_sensor:
      - name: Sensor XYZ Active
        unique_id: sensor_xyz_active
        state: "True"
        auto_off:
          seconds: 30

Now, whenever binary_sensor.sensor_xyz_active changes to off, you can take action.

1 Like

Are your “smart plugs” only power sensors? I was asking about the switch entity, not the power sensor…

They don’t go to unavailable. They show the last measured value (power or current) forever, as long as the fuse is off.

I have the Nous A1Z. It can be used as a switch and has sensors for energy consumption, voltage, current and power.

Hi everybody,
I never thought it could be so simple. After a while I asked (just for fun) Chat GPT and immediately a working solution came up that I want to share with you:

trigger:

  • platform: state
    entity_id: sensor.waschkeller_leistung
    for:
    seconds: 20

Thanks to you all for you comments and best regards!
Rado

Reference: State Trigger