Best way to daily toggle 2 pond pumps alternately

Using an automation to see whether my pumps need to be on in the first place, based on a template sensor:

sensor:
  platform: template
  sensors:

    vijverpomp:
      friendly_name_template: >
        {{states('sensor.temp_current')|float}}°C - Vijverpompen {{'moeten: ' if
          is_state('sensor.vijverpomp','Aan') else 'mogen: '}}
      value_template: >
        {{'Aan' if (states('sensor.temp_current')|float > 6 and
        is_state('binary_sensor.outside_daylight_sensor','on')) else 'Uit'}}
      icon_template: >
        {% if is_state('sensor.vijverpomp','Uit') %} mdi:engine-off-outline
        {% else %} mdi:engine-outline
        {% endif %}

and automartion:

  - alias: Vijverpompen
    id: Vijverpompen
    trigger:
      platform: state
      entity_id: sensor.vijverpomp
    condition:
      - condition: numeric_state
        entity_id: sensor.temp_current
        above: 5
        below: 7
      - >
          {{trigger.to_state.state != trigger.from_state.state}}
      - >
          {{trigger.to_state.state in ['Aan','Uit']}}
      - >
          {{(now() -
            states.sensor.vijverpomp.last_changed|default(0)).total_seconds() > 3600}}
      - condition: state
        entity_id: input_boolean.notify_utility
        state: 'on'
    action:
      service: notify.system
      data:
        title: Vijverpomp
        message: >
          Vijverpompen {{'moeten aan' if is_state('sensor.vijverpomp','Aan') else 'mogen uit'}}

I currently do this manualy.
Installing a Fibaro double switch should allow me to do this automatically, and I was wondering if there would be a’best solution’ for this, some sort of default alternating switching.

Thing is I am not sure if I should trigger on the same triggers as above, or the sensor, or maybe sensor.date, to have the pumps change daily.

action:
  service: switch.toggle
  entity_id: switch.pump_left, switch.pump_right

should do it, if and when the condition is set they don’t have the same state :wink:

a simple binary sensor might help:

binary_sensor:

  platform: template
  sensors:

    vijverpomp:
      value_template: >
        {{states('sensor.temp_current')|float > 6 and
          is_state('binary_sensor.outside_daylight_sensor','on')}}
#      delay_off:
#        minutes: 60

so, both switches should be on if the binary_sensor is ‘on’ (both containing conditions are met).
Switches should alternate during daylight == ‘off’, (even though the temp is above 6 degrees, think spring and summer evenings) or when the temp is below degrees (think winter). This period will vary of course, from a single summers eve, to a long period of cold temp in winter.

Not sure a While construct would work (consider system restarts…), and this might very well be the first situation in my config where a manual switch is easier than figuring out the automation…

please let me know your thoughts?
thanks!

One possible option is to start monitoring the power draw from each pump and store the cumulative KWh’s for each pump and start the pump that has the minimum number of ‘run hours’ (assuming pumps are equivalent). This would round out the run hours per pump better since the cycle times on are based on temperature (which in most places is all over the place). If you use something like a shelly PM1, that data is stored on the shelly device itself and can be pulled by either MQTT, the Shelly integration, or by a REST sensor.

There are options of writing more complicated Automations but I think comparing the total power used and starting the lower run pump is the easiest option overall.

You also have the option of building a switching relay that will alternate pumps, this will require more hardware and some electrical knowledge. It is possible to ‘store’ the last run state through power outages, but this is a way more complicated route then just monitoring power consumption.

o dear, I didnt even think of that, power usage etc etc. that wouldn’t be the way I would check that in real life either/ Id simply think, if they have to be toggled (based on the conditions) and either turn 1 off (c0ming from a state both pumps would be on, or, toggle them both, at day change.

keeping it that simple would give this for starts:

# set an input_boolean to survive restarts, and enter the first run of 'alternating state'
  - alias: Vijverpompen uit
    id: Vijverpompen uit
    trigger:
      platform: state
      entity_id: binary_sensor.vijverpomp
      state: off  #delay is built in the n binary sensor
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.vijverpompen_alterneren
      - service: switch.turn_off
        entity_id: switch.vijverpomp_links

# triggered by day, if boolean is still on, toggle switches
  - alias: Vijverpompen alterneren
    id: Vijverpompen alterneren
    trigger:
      - platform: state
        entity_id: sensor.date
     -  platform: template
        value_template: >
          {% set noon = state_attr('sensor.astral_solar_noon', 'today') %}
          {{ noon is not none and now() > noon }}
    condition:
      - >
          {{is_state('binary_sensor.vijverpomp', 'off')}}
      - >
          {{is_state('input_boolean.vijverpompen_alterneren', 'on')}}
    action:
      service: switch.toggle
      entity_id: switch.vijverpomp_links, switch.vijverpomp_rechts

# both pumps need be on
  - alias: Vijverpompen aan
    id: Vijverpompen aan
    trigger:
      platform: state
      entity_id: binary_sensor.vijverpomp
      to: 'on'
     for:
       minutes: 30
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.vijverpompen_alterneren
      - service: switch.turn_on
        entity_id: switch.vijverpomp_links, switch.vijverpomp_rechts

have to get my head around whether this tackles all situations, be it winter or summer(nights)
what do you think?

wrote these 3 small automations, because I couldn’t find a way to have a While loop use triggers? Otherwise this could be 1 bigger automation maybe.

wait, maybe like this:

  - alias: Vijverpompen uit
    id: Vijverpompen uit
    trigger:
      platform: state
      entity_id: binary_sensor.vijverpomp
      to: 'off'
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.vijverpompen_alterneren
      - service: switch.turn_off
        entity_id: switch.vijverpomp_links
      - repeat:
          while: >
            {{is_state('input_boolean.vijverpompen_alterneren','on')}}
          sequence:
            - wait_for_trigger:
                - platform: state
                  entity_id: sensor.date
            - service: switch.toggle
              entity_id: switch.vijverpomp_links, switch.vijverpomp_rechts

?

I just thought of the simplest way you could do it. (although I still prefer running based on actual run time)
This should be able to be accomplished in one automation.
You have two pumps, so Pump #1 and Pump #2
Pump #1 runs on odd days, Pump #2 runs on even days. Then you can modify for your conditions to run both.
Again, I prefer power monitoring since that will also give an indication of possible pump failure. The most accurate way would be have pressure switches or some type of pressure transducer and then send notifications if Pump X is ‘on’ but no flow/power is detected.

thanks, I like the odd/even days, takes the human arbitrary choice of the first switch.turn_off. Even though

      - service: switch.turn_off
        entity_id: switch.vijverpomp_links

is shorter than

      - service: switch.turn_off
        entity_id: >
          switch.vijverpomp_{{'links' if now().day % 2 else 'rechts'}}

the latter positively ensures a more balanced toggling process, especially in the case off a single nights toggle.

you’ve got me thinking about the other aspect of pump failure. I will add some extra and dedicated logic for that after having physically added the Fibaro switch. Z-wave switches sometimes switch off because of signal failure in the first place, so need to guard that. Secondly the issue of a true pump failure could arise and that warrants some extra care…

second thoughts about the while construct: I don’t think this will survive a restart. Ill go back to where I started, with the 3 separate automations, having sensor.date trigger the toggle, under the condition the input_boolean is on.