Sensor which turns on above a value but not off until below another

Hi,

I want to create a helper which to tell me when my dishwasher last completed. I am monitoring the power (W), but I want to make sure I don’t see the false positives. So when someone turns on the dishwasher and then turns it off, it should not be considered the last run. But what I would like to do it consider it running the power goes above x watts and then stops when it goes below.

My dishwasher has a cycle at the beginning where it uses a lot of power and then it drops down for the rest of it (actually my washing machine also does this) So I would like to say that it turns on when it goes above 200W and then turns off if it goes before 10W

Does anyone have any idea how this could be done.
TIA
Gordon.

This will turn on at 200W and above and off at 10W or below:

binary_sensor:
  - platform: threshold
    name: Dishwasher Running
    entity_id: sensor.dishwasher_power
    upper: 105
    hysteresis: 95

392f2b64f3429daba6cede152b96f678e7972034

To get the the last run time end in a sensor:

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.dishwasher_running
        from: 'on'
        to: 'off'
    sensor:
      - name: Dishwasher Last Run
        device_class: timestamp
        state: "{{ now() }}"
2 Likes

Thanks so much, I didn’t think there was something like this. I need to still play with it to understand what is going on.

You are a champion.

I was just going though my data to work out some good figures. I am going to be pushing my luck this time, but I have about 2 minutes in the middle my power figures are below the lower threshold.

Is there a way like automations to say don’t turn off unless the value is below for more that n time.

I do have an idea for using a mean/average sensor to remove this dip if it can’t be confiurged out.

TIA
Gordon

Have you looked at the documentation?

Hi,

Sorry I think you misunderstood. I know automations has the “for” attribute which allows for exactly what I need on an automation trigger but not on threshold.

In my case I have the dip below the minimum power power level for about 2 minutes and then pops back up.

With the normal use of threshold, it would be marked as turned off, and then only turn back on if it goes above the upper limit.

So if I could do something like the following.

binary_sensor:
  - platform: threshold
    name: Dishwasher Running
    entity_id: sensor.dishwasher_power
    upper: 105
    hysteresis: 95
    for: "00:02:00"

Then this dip would just get removed and the threshold would stay on.

Unfortunately the threshold sensor does not support a delay_off option like the template binary sensor does. So I suggest you use a triggered binary template sensor instead. There are two ways to do it. I think the first will cause less triggers/template updates but it is not really significant so which you use is up to you:

configuration.yaml

template:
  - trigger:
      - id: 'off'
        platform: numeric_state
        entity_id: sensor.dishwasher_power
        below: 10
        for:
          minutes: 3
      - id: 'on'
        platform: numeric_state
        entity_id: sensor.dishwasher_power
        above: 200
    binary_sensor:
      - name: Dishwasher
        device_class: running
        state: "{{ trigger.id|bool }}"

Or:

template:
  - trigger:
      - id: 'off'
        platform: numeric_state
        entity_id: sensor.dishwasher_power
      - id: 'on'
        platform: numeric_state
        entity_id: sensor.dishwasher_power
        above: 200
    binary_sensor:
      - name: Dishwasher
        device_class: running
        state: "{{ trigger.id|bool }}"
        delay_off: 180 # seconds

If you don’t like the device class you can choose another one from here: https://www.home-assistant.io/integrations/binary_sensor/#device-class or even drop the device class altogether and use an icon template (state will be on/off):

template:
  - trigger:
      - id: 'off'
        platform: numeric_state
        entity_id: sensor.dishwasher_power
      - id: 'on'
        platform: numeric_state
        entity_id: sensor.dishwasher_power
        above: 200
    binary_sensor:
      - name: Dishwasher Running
        state: "{{ trigger.id|bool }}"
        delay_off: 180 # seconds
        icon: "{{ 'mdi:dishwasher' ~ '-off' if is_state('binary_sensor.dishwasher_running','off') else '' }}"

Screenshot 2024-03-28 at 12-01-40 Material Design Icons - Icon Library - Pictogrammers

1 Like

Thanks so much. Home Assistant is just so amazing on what you can do with it.

This has worked perfectly.

1 Like