Track sensor states in an automation over time before executing actions

I’m looking to create an automation that listens for changes in a single sensor’s value, tracks when it crosses certain thresholds a specified number of times, and only then executes an action. In example - I want to listen to when the smart plug connected to my non-smart dishwasher exceeds a current power consumption threshold 3 times so I can trigger it to turn off before it enters its heated drying cycle. Essentially, is there a way to trigger an automation and then:

  • keep the automation active while it listens for further changes to that sensor
  • keep a running count of how many times that sensor exceeds specified thresholds
  • finally execute an action once a certain count has been reached?

Can you show a history graph of the power zoomed in to one wash cycle?

Certainly, see below. I want to trigger an action once the cycle hits the highlighted area below. I originally tried setting a timer based on the time it takes to hit that point in the cycle, but sometimes the cycles run longer (or shorter) than what’s shown below.

I want logic that says something to the effect of “after the washer has drawn >1000W for 10 minutes twice and then drops below 50W, turn off the plug”

Here’s another simpler way to do it:

# configuration.yaml
template:
  - binary_sensor:
      - name: Dishwasher Running
        unique_id: dishwasher_running
        icon: "mdi:dishwasher"
        device_class: moving
        state: "{{ states('sensor.dishwasher_plug_power_here')|float(0) > 50 }}"
        availability: "{{ has_value('sensor.dishwasher_plug_power_here') }}"
        delay_off:
          minutes: 5

The delay_off should bridge those short low power sections so it will continue to show as running.

Trigger your automations on that binary sensor turning 'on' or 'off'. The final off state will be delayed by 5 minutes but that shouldn’t be important.

2 Likes

I spaced and realized I had already posted about this (thanks so much, brain) to which you had already given some ideas. The original post actually has a more correct power graph - there are two large >1100W sustained peaks, a ~30m period of ~150w, then a final peak of around >1100W for about 15 minutes. As soon as that final peak drops off to below 50w, that’s the period I want to catch.

I’m not sure the logic you suggested here would hold true in this case, but it may require some experimentation. Thanks for the new tool to try.