feature-requests icon indicating copy to clipboard operation
feature-requests copied to clipboard

delayed_on_off: different on and off

Open Erelen-Laiquendi opened this issue 5 years ago • 3 comments

Thanks for delayed_on_off - https://github.com/esphome/esphome/pull/700

Describe the problem you have/What new integration you would like Current syntax:

filters:
  - delayed_on_off: 40s

Please, add ability to define different on and off time. For example, like this:

filters:
  - delayed_on_off:
      on: 5s
      off: 30s

Please describe your use case for this integration and alternatives you've tried: In one mode, my washing machine has power consumtion pattern like this (simplified for clear example):

10 seconds > 0W 20 seconds = 0W 10 seconds > 0W 20 seconds = 0W ...

And (!) from time to time there is very short random consumtion spikes, when machine don't work.

I want to make binary sensor "machine is on". So, I need short delay on filter (~5s) to ignore random spikes, but not more than 10s. And long (>20s) delay off filter.

In simplified example above, something like this can work (thanks to your explanation about pipeline - https://github.com/esphome/issues/issues/463):

filters:
  - delay_on: 5
  - delay_off: 25

But real power consumtion is more complex - in middle of working cycle there is periods (for a several minutes) like this:

2 seconds > 0W 20 seconds = 0W So, in this period delay_on never pass "on", and after some time delay_off will be trigged.

But something like this totally solve my case:

filters:
  - delayed_on_off:
      on: 5s
      off: 25s

Turn on when "on" condidion is done and never turn off until off condition is done. Simple, clear logic. Equal to HA delay_on + delay_off.

Alternative solutions:

  1. Send power consumtion to HA and create template binary sensor with delay_on and delay_off (it's pity - I can simple do it in HA, but can't in ESPHome).
  2. In ESPHome create two sensors - one with delay_on and second with delay_off, and binary_sensor.template.publish from them to third binary sensor. Ugly :(

Erelen-Laiquendi avatar Dec 22 '19 02:12 Erelen-Laiquendi

sounds like a job for the multi click filter

glmnet avatar Dec 30 '19 03:12 glmnet

Implemented separate delayed_on and delayed_off: https://esphome.io/components/binary_sensor/index.html#delayed-on

nagyrobi avatar Jul 07 '22 12:07 nagyrobi

Separate delayed_on and delayed_off is not the same because filters are processed in a pipeline. That's explanation by OttoWinter: https://github.com/esphome/issues/issues/463#issuecomment-503959711 Please, reopen this issue.

Erelen-Laiquendi avatar Jul 07 '22 16:07 Erelen-Laiquendi

@Erelen-Laiquendi did you ever find a solution for this?

SalexSun avatar Jan 05 '23 08:01 SalexSun

Current ugly solution:

binary_sensor:
  - platform: template
    id: activity_moment
    lambda: |-
      if (isnan(id(power).state)) {
        return {};
      } else if (id(power).state > 2.5) {
        return true;
      } else {
        return false;
      }

  - platform: template
    id: activity_on
    lambda: 'return id(activity_moment).state;'
    filters:
      - delayed_on: 2s
    on_press:
      - binary_sensor.template.publish:
          id: activity
          state: ON

  - platform: template
    id: activity_off
    lambda: 'return id(activity_moment).state;'
    filters:
      - delayed_off: 30s
    on_release:
      - binary_sensor.template.publish:
          id: activity
          state: OFF

  - platform: template
    id: activity
    name: "Washer Activity"
    icon: mdi:washing-machine

Erelen-Laiquendi avatar Jan 06 '23 03:01 Erelen-Laiquendi

@Erelen-Laiquendi I just found your issue searching for a solution for the same problem and by random discovered that it might have actually been implemented almost secretly a few months ago together with making delays templatable: https://github.com/esphome/esphome/pull/5029
It also gets mentioned in the docs by now (time_on and time_off): https://esphome.io/components/binary_sensor/index.html#delayed-on-off

I have not had a chance to try it out yet, but from looking at the code it sounds very promising. What do you think?

felixstorm avatar Oct 07 '23 07:10 felixstorm