ESpHome delta function


I’ve few Sonoff S31 flashed with ESPHome around the house connected to appliances. In the initial configuration I set these devices to update electrical characteristics (current, voltage & power) every 15s but that seems inefficient as the appliances run run for a very short duration of time in a day. So started experimenting with ESPHome delta feature using following configuration:

  electrical_updates: 15s
  name: $name_of_board
  platform: ESP8266
  board: esp01_1m

  - platform: gpio
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: ${name_of_board}
      - switch.toggle: relay
  - platform: template
    name: ${name_of_board} Running
    device_class: running
      - delayed_off: 15s
    lambda: |-
      if (isnan(id(power).state)) {
        return {};
      } else if (id(power).state > 4) {
        // Running
        return true;
      } else {
        // Not running
        return false;

  - platform: gpio
    name: ${name_of_board}
    pin: GPIO12
    id: relay
    restore_mode: ALWAYS_ON
  - platform: cse7766
    #update_interval: $electrical_updates
      name: ${name_of_board} Current
      id: current
        - delta: 0.5
      name: ${name_of_board} Voltage
      id: voltage
      name: ${name_of_board} Power
      id: power
        - delta: 5.0

    number: GPIO13
    inverted: yes
# UART is needed for cse7766
  rx_pin: RX
  baud_rate: 4800

The above file is a template file that I am importing into each config file for an appliance and it is working. But the “delta feature” seems to take its own sweet time, sometimes 30s or whereas I was expecting it near real-time.

So few questions:

  1. What is the default trigger time for “delta” function?
  2. Did I use the “delta” function correctly for current and power?
  3. Is it better to use “update_interval” for appliances with heavy load versus “delta” feature?

Any other suggestions or omission from my code are welcome!

It doesn’t have a trigger time of itself. Its about the frequency of the incoming values, which it filters down.

As delta is a filter, you start with data updates coming in at the update_interval (60sec by default for your cse7766), then delta filter will only let one of these values through if the change is more than the delta value.

I’m not sure if sampling at a higher rate reduces sensor lifetime. Perhaps. Often people want to reduce traffic to HA though…

An or: filter with a fast update Interval (5sec etc) and a throttle of say 1min is a way you can reduce traffic but have low latency for changes.

1 Like

Ok so you are saying that I need to use filter in conjunction with update_interval not one over the other?

So if I’ve followed your rationale correctly, I can leave update_interval at say 5s but add filters. The device will only reports value once a variation crosses the threshold but not every 5s. Since these are connected to appliances, the values are zeros for most part of the day but when the device is running of stopping I do need to know (quickly) about the change of state for automations.

1 Like