Need help with very complex scheduling

Here is the background to the project.
We have solar panels and a saline pool. The pool circulation pump should go x hrs a day and more if the pool is used.

I would like to start the poolpump for an hour with start at 9am if we are exporting more than 1700Watt (ie if sensor.grid_active_power > 1700 ). Then it should rest for about an half hour and then start again if we export more than 1700W to the grid.

I would also turn of if we export less than 1700W (so we do not drain the battery on the poolpump)

The problem is that I want a delay in the action for about 5 minutes ie we export more than 1700W 5 minutes go and we still do that - Fine start the pool pump.

And also if the export less than 1700W five minutes ago and still export less - Turn off the pump.
This so we could make a Coffee without turning of the pump :slight_smile:

How can I create this automation.

Use automations-gui and the ‘choose’ in actions to manage the various trigger/conditions

I see the need for several triggers:

Time Trigger at 09:00
Numeric State Trigger when sensor.grid_active_power is above 1700 for 5 minutes
Numeric State Trigger when sensor.grid_active_power is below 1700

Several conditions will also be needed to ensure the pump’s operation complies with your requirements.

There are some aspects of your requirements that are unclear. For example, let’s say the pump starts at 09:00 because power production is above 1700. You said it should rest afterwards for a half hour. However, how long should the pump run before the rest period? Should it be allowed to run until power production decreases below 1700?

Sorry to be unclear, The pump should run 1 hour untuil it turns off for 30 minutes

Do you mean it should run for a fixed duration of 1 hour, even if power production decreases below 1700? Or can it stop earlier, if power production decreases below 1700?

No if power export to the grid is under 1700w for 5 minutes it should turn of and then not start until 30 minutes has passed and the power export has been over 1700w for 5 minutes

The turn on should be something like this this I think


 alias: Turn on poolpump when Export to Grid is more than 1700W
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.grid_active_power
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: '1700'
condition:
  - condition: state
    entity_id: switch.poolpump
    state: 'off'
    for:
      hours: 0
      minutes: 30
      seconds: 0
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.poolpump
mode: single

That automation doesn’t support most of the requirements you listed. In addition, if it triggers when the pump hasn’t been off for a half hour yet, it won’t trigger again until power production first decreases below 1700 then increases above it (that’s how a Numeric State Trigger works; it only triggers when the value crosses the threshold). That means power production might be above 1700 but the pump will not be started after a half hour’s rest.

I know but thats how far I have come the rest I need help with :slight_smile:

This is the flowchart I want to accomplish

Home Assistant is event-based so you need to translate the loops in the flowchart into an event-based model.

The following example demonstrates how to implement your requirements as an event-based system. it may require further adjustments to meet all of your requirements. There is no 5-minute “waiting time” because this is exclusively event-based.

alias: example 123
id: example_123
trigger:
  - id: 'scheduled_on'
    platform: time
    at: '09:00:00'
  - id: 'scheduled_off'
    platform: time
    at: '20:00:00'
  - id: 'exporting'
    platform: numeric_state
    entity_id: sensor.energy_production
    above: 1700
    for: '00:00:05'
  - id: 'not_exporting'
    platform: numeric_state
    entity_id: sensor.energy_production
    below: 1700
    for: '00:00:05'
  - id: 'duration_on'
    platform: state
    entity_id: switch.pump
    to: 'on'
    for: '01:00:00'
  - id: 'duration_off'
    platform: state
    entity_id: switch.pump
    to: 'off'
    for: '01:00:00'
action:
  - choose:
      - conditions:
          - "{{ trigger.id == 'scheduled_on' }}"
          - "{{ states('sensor.energy_production') | float(0) >= 1700 }}"
          - "{{ is_state('switch.pump', 'off') }}"
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.pump
      - conditions:
          - "{{ trigger.id == 'exporting' }}"
          - "{{ 9 <= now().hour < 20 }}"
          - "{{ is_state('switch.pump', 'off') }}"
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.pump
      - conditions:
          - "{{ trigger.id == 'not_exporting' }}"
          - "{{ is_state('switch.pump', 'on') }}"
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.pump
      - conditions:
          - "{{ trigger.id == 'duration_on' }}"
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.pump
      - conditions:
          - "{{ trigger.id == 'duration_off' }}"
          - "{{ states('sensor.energy_production') | float(0) >= 1700 }}"
          - "{{ 9 <= now().hour < 20 }}"
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.pump
      - conditions:
          - "{{ trigger.id == 'scheduled_off' }}"
          - "{{ is_state('switch.pump', 'on') }}"
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.pump
    default: []

Thank you I try this and explore from that.