Need help for pool pump

Hey there,
I need some help creating an automation for a pool pump.
The pump has three stages (stage 1 = 300W, stage 2 = 550W, stage 3 = 875W).
I have a sensor, which states the current energy consumed/returned from/to the grid. Also there is a sensor telling the current power consumption of the pump.

I want to create an automation which sets the stage of the pump according to the available energy.

I manged to set up a template:

value_template: >
  {% set uberschuss = -1 * (states('sensor.uberschuss_mittel') | float(0)) %}
  {% set leistung1 = 300 %} # Leistung bei Stufe1
  {% set leistung2 = 550 %} # Leistung bei Stufe2
  {% set leistung3 = 875 %} # Leistung bei Stufe3
  {% set puffer = 150 %} # verbleibender Puffer
  {% set aktleistung = states('sensor.garage_schaltsteckdose_leistung') | float(0) %}
#  {% set aktleistung = 300 %}
  {{ 3 if uberschuss + aktleistung - leistung3 > puffer else
     2 if uberschuss + aktleistung - leistung2 > puffer else
     1 if uberschuss + aktleistung - leistung1 > puffer else
     0 }}

Calculation is:
(power returned to grid) + (actual consumption of pump) - (consumption of (new) stage) must be greater than the buffer.

This seems to work.

Now I want to create an automation which monitors the above mentioned sensor (pump stage) and sets a new pump stage only when it was set for more than 5 (or x) minutes. I don’t want to switch stages every x seconds…

Can you help me with that?

THANKS!!!

here is my take

Create a Template Sensor for Desired Pump Stage

template:
  - sensor:
      - name: "desired_pump_stage"
        state: >
          {% set ueberschuss = -1 * (states('sensor.uberschuss_mittel') | float(0)) %}
          {% set leistung1 = 300 %}
          {% set leistung2 = 550 %}
          {% set leistung3 = 875 %}
          {% set puffer = 150 %}
          {% set aktleistung = states('sensor.garage_schaltsteckdose_leistung') | float(0) %}
          {{ 3 if ueberschuss + aktleistung - leistung3 > puffer else
             2 if ueberschuss + aktleistung - leistung2 > puffer else
             1 if ueberschuss + aktleistung - leistung1 > puffer else
             0 }}

and a automation

automation:
  - alias: "Set Pool Pump on Energy"
    mode: single
    trigger:
      - platform: state
        entity_id: sensor.desired_pump_stage
        for: "00:05:00" 
    condition:
      - condition: template
        value_template: >
          {{ states('sensor.current_pump_stage') | int(0) != states('sensor.desired_pump_stage') | int(0) }}
    action:
      - service: switch.turn_on  
        target:
          entity_id: switch.pool_pump_stage_{{ states('sensor.desired_pump_stage') }}

Okay - thank you - I will test it.
At the moment I set up four single automations (set to 1, to 2,… set off) like this:

alias: Poolpumpe ausschalten
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.poolpumpe_stufe
    to: "0"
    for:
      hours: 0
      minutes: 5
      seconds: 0
conditions: []
actions:
  - action: notify.telegram_maik
    metadata: {}
    data:
      message: Stufe 0
mode: single

At the moment I don’t switch anything - just a telegram-message :slight_smile:
But this seems to work.
The only problem is - when the calculated pump-stage is already “3” (or what else) and does not change, the trigger does not work since there is no change (to “3”).
There must be four different actions since each pump stage is controlled via a seperate physical HomematicIP-Switch.
if stage 3 > switch all other stages off > switch 3 on…
if stage 1 > switch all other stages off > switch 1 on…

And the next thing I don’t know how to handle:
I would like to create a virtual switch (“automatic” vs. “manual”). This switch I would like to add to the automation as a condition - only when it is “automatic” then set the pump-stage. In manual mode nothing should happen…

You could probably do all this in your template sensor.
If you store the time the stage changed in an attribute, you can compare that time with the current time. If it’s been more than five minutes you change the stage and update the time attribute.

Yeah - maybe this is possible.
But it won’t be possible for me :wink:
I am neither an expert in programming nor in HomeAssistant-logics, -sensors, -templates…

I have to do all this via copy-paste, try-and-error etc.
Normally I set up a helper, a helper for the helper and maybe some helpers for the helpers-helper to get all this working.

And after all I have to work with lots of #comments to be able to understand all that after a few weeks and months and maybe to do some troubleshooting…

So NO - this is not possible for me :frowning: