Automation based on time a value is below a level

Setup; I have an input.boolean, that is on when the washing machine goes on (the logic for that is in another automation). I want to turn that input boolean off if the following conditions are met:

  • The power is below 20 watts for more then 2 minutes
    OR
  • The power is below 40 watts for more then 2 minutes AND the machine (that is the input boolean) has been on for at least and hour.

I tried the automation underneath, but it seems like “for:” is not allowed for “numeric state” only “state”. Any suggestions on how to solve this?

- alias: Vaskemaskin av
#triggers when the machhine goes on
  trigger:
    - platform: state
      entity_id: input_boolean.kjellerbad_vaskemaskin
      to: 'on'
  condition:
    condition: or
#conditon 1
    conditions:
      - condition: numeric_state
        entity_id: sensor.kjellerbad_vaskemaskin_power
        below: 20
        for:
          seconds: 120
#condition 2
      - condition: and
        conditions:
          - condition: numeric_state
            entity_id: sensor.kjellerbad_vaskemaskin_power
            below: 40
            for:
              seconds: 120
          - condition: state
            entity_id: input_boolean.kjellerbad_vaskemaskin
            state: 'on'
            for:
              minutes: 60
  action:
    service: input_boolean.turn_off
    entity_id: input_boolean.kjellerbad_vaskemaskin

Based off what you wrote here, and the previous chat on Discord, if you’re on 0.110 this will work:

- alias: Vaskemaskin av
  trigger:
    - platform: numeric_state
      entity_id: sensor.kjellerbad_vaskemaskin_power
      below: 20
      for: '00:02:00'
    - platform: numeric_state
      entity_id: sensor.kjellerbad_vaskemaskin_power
      below: 40
      for: '00:02:00'
    - platform: state
      entity_id: input_boolean.kjellerbad_vaskemaskin
      to: 'on'
      for: '01:00:00'
  condition:
  - condition: state
    entity_id: input_boolean.kjellerbad_vaskemaskin
    state: 'on'
  - condition: or
    conditions:
      - condition: and
        conditions:
        - condition: numeric_state
          entity_id: sensor.kjellerbad_vaskemaskin_power
          below: 20
        - condition: not
          conditions:
          - condition: state
            entity_id: input_boolean.kjellerbad_vaskemaskin
            state: 'on'
              for: '01:00:00'
      - condition: and
        conditions:
          - condition: numeric_state
            entity_id: sensor.kjellerbad_vaskemaskin_power
            below: 40
          - condition: state
            entity_id: input_boolean.kjellerbad_vaskemaskin
            state: 'on'
            for: '01:00:00'
  action:
    service: input_boolean.turn_off
    entity_id: input_boolean.kjellerbad_vaskemaskin

Thanks, but what will happen for that suggestion if after 1 hours and 5 minutes, it goes below 40 for 3 seconds. Won’t it trigger then? In my first automation (besides the fact that it doesn’t work :)) it will only trigger if more than an hour has passed and it is below 40 for 2 minutes.

You’re missing how triggers work.

Triggers cause an automation to be considered when they become true. Not after. When input_boolean.kjellerbad_vaskemaskin has been on for one hour, that trigger will become true, and the automation will start processing. One second later when it is still true it won’t cause the automation to start processing.

So, the automation will only process at the exact points that:

  1. sensor.kjellerbad_vaskemaskin_power has gone from above 20 to below 20 for 2 minutes
  2. sensor.kjellerbad_vaskemaskin_power has gone from above 40 to below 40 for 2 minutes
  3. input_boolean.kjellerbad_vaskemaskin has been on for one hour

So, at one hour and 5 minutes, there’s nothing to cause it to trigger if the sensor goes below 40 for 3 seconds…

Ok, so then one could just remove the last trigger then, right? And how about the “below” condition? That might not be necessary as it if checked for in the trigger itself?

The automation covers the logic you described in the opening post. If you remove any of the triggers, or conditions, you won’t get the behaviour you described.

Thanks, but it still seem to me like it is not quite doing the same:

  1. I still don’t get usefulness of trigger 3? (the time 1), why should it trigger exactly at 1 hour?
  2. Lets say after 45 minutes it will be at 30 (below 40 and above 20) for 2 minutes, and the goes over to 10 for 5 seconds. Trigger 2 will activate, it will check if it is below 20 in condition 2 (which it is), and thus run the action. But it shouldn’t because because it hasn’t been below 20, 2 minutes in a row within the first hour?
  3. Ideally the “below 20”-condition should be active after 1 hour as well, it just should add the “below 40 for 2 minutes” as an added situation.
  1. You use this trigger so that when the switch has been on for an hour it’ll check to see if the power has been below 40 watts for at least 2 minutes
  2. This is rather the whole point of the conditions - maybe you should go and read the automation documentation again
  3. Then add it :man_shrugging:
  1. It checks all the time if it has been below 40 for 2 minutes? That is your trigger 2? That will check that all of the time, no matter if it has been an hour or not, right? So what does trigger 3 do?
  2. No, the point is for it to activate if it has been below 20 for 2 minutes. OR if it has been been below 40 for 2 minutes after an hour has elapsed. But the first one fails in the example I have provided right? It will activate even if it hasn’t been below 20 for 2 minutes the first hour?

I’ve explained this enough here, and over in Discord. Now it’s time for you to read the automation docs, and try stuff out. I don’t think repeating myself is going to help.

Hi, @ATWindsor I’m in a similar boat where I want to smartify my washing machine. Would you mind sharing the other automation you have that sets the input boolean when the machine is powered on? I’m trying to replicate the setup here.