Condition for average power consumption

I have a sensor for the power consumption of a device (washing machine). I would like to detect if the device is running or not. In standby, it consumer about 2W of power. My idea was to detect a power consumption of above 10W for 30s.

Complication: the power consumption fluctuates a lot when it is on. It goes abover 10W, but then might drop low, the go up again, and so on. So a simple trigger doesn’t work:

alias: Detect ongoing washing
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.shelly_washing_current_consumption
    above: '10'
    for: '0:00:30'
condition:
  - condition: state
    entity_id: input_boolean.washingmachine_running
    state: 'off'
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.washingmachine_running
mode: single

It takes much more than 30s for this automation to detect that the device is active - actually until it stays consistently above 10W for 30s.

Is there a way to put the trigger on the average consumption over the last 30s?

I guess I solved it myself.

The automation then looks like this:

I used the average sensor available in HACS:
Limych/ha-average: Average Sensor for Home Assistant (github.com)

It is configured in configuration.yaml :

sensor:
  - platform: average
    name: Washing average consumption
    duration: 30
    entities:
      - sensor.shelly_washing_current_consumption

The automation to set the helper variable then looks like this:

alias: Detect ongoing washing
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.washing_average_consumption
    above: '10'
condition:
  - condition: state
    entity_id: input_boolean.washingmachine_running
    state: 'off'
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.washingmachine_running
mode: single

Obviously, you would also need an automation to set the input_boolean back to off once the average consumption goes down again.

1 Like