Tankless Water Heater Recirc Pump - How to automate pump toggle-on multiple times within time window

Updated code so it appears correctly

Here’s my problem: I recently upgraded to a tankless water heater and added a Zooz Multirelay to help automate it. I was able to get everything hooked up and can use HA to send a signal to the relay to turn on the water pump no problem.

The way my water heater pump works, I had to adjust the relay settings to have it be a momentary push button. Once “pushed” the pump runs and recircs the water until my temperature preference has been met as seen on the water heater.

Here’s the problem I’m having with how I set up my automation that I’ll include below. I am trying to set it up so that my pump turns on at 5:45 am and runs every 30 minutes until 6:45am. So with this, the pump would turn on at 5:45, 6:15, and then again at 6:45. I tried doing the time_pattern with /30, but this obviously doesn’t work since 45 isn’t evenly disvisible by 30; and therefore the first time it turns on isn’t until 6:00am. How I would like to set up my automation is for it to start at the time I provide, and run at some frequency. I’m hoping that I can make the automation flexible enough that if every 30 minutes isn’t enough, and it needs to be updated in the future to a real random number, like every 17 minutes, that the code will work for me. I did a bunch of digging online and found a lot about turning a pump on for 10 minutes, and then it turns off 10 minutes later and this repeats but I can’t do that since my pump is activated via a momentary push button.

Any help would be greatly appreciated! I’ve spent countless hours scouring the web and can’t find something that works for what I’m trying to do.

description: ""
mode: single
triggers:
   - trigger: time_pattern
     minutes: /30
conditions:
   - condition: time
     after: "05:45:00"
     before: "06:45:00"
     weekday:
       - mon
       - tue
       - wed
       - thu
       - fri
actions:
   - action: switch. toggle
     metadata: {}
     data: {}
     target:
        entitiy_id: switch.hot_water_pump_relay_1

How about using a timer that not only turns on the switch (BTW: why do you toggle it instead of turning it on?) but the timer also restarts itself once it expires?

That should be flexible enough to change the timer value as needed.
You can even create a helper that you can change from the dashboard without having to open the automation in case you need to change the interval.

I toggle it because the way my water heater works, and the way I have it set up, is that the pump kicks on when requested, and it only runs for as long as it needs to in order to get the water in the recirculation line to a set temperature. So it could run for 10 seconds if the water is already fairly warm, or it could run for about a minute to get it up to temperature. So i don’t define the amount of time it runs, just the temperature I want it to be at.

That timer idea seems like it should work, I have just never used one that restarts itself. Do you have any other topics you could link me to that I could try out?

So, you use the toggle, because you know that the switch is off by the time you get back to it - understood.

It’s not a timer that actually resets itself - an automation would do that when the timer expires, at the same time it turns your switch on.

I haven’t futz with extracting components of time, but the direction I would look at first would be to:

  • Changed the trigger to /15 so the timer fires 4 times per hour.
  • Then add an additional condition to check if the number of minutes equals 15 or 45 (in addition to your existing morning time condition)

Ya I could definitely do this with my current setup, but my thought is in the future, I might adjust the time window to something weird like 6:00am-7:00am and i might want the pump to trigger every 17 minutes (just trying to throw crazy numbers out that make “time_pattern” harder to use). I think the timer and restart option might work like @chairstacker mentioned, I’m just now trying to dig through the internet to see the best way to get it to work.

Generally speaking I put something in that “pretty much works” then loop back later when a better solution becomes available (I learn more or someone suggests a better way).

Another thought I had is given your scenario it wouldn’t matter that much if you had one extra trigger per day.

To that end I would just set your main trigger to the interval you want:

  • For example: /17
  • Then add one additional trigger to fire the first time each morning, in your last case at 06:00 am.

Hence the first time you will get a shorter window than 17 minutes (based on however the trigger does the math), but the 17 minutes should fire properly from then on.

With the timer you go like this pseudocode:

1st automation:

  1. Trigger: Time is 6:00AM
  2. Action: Start Pump Timer to run for 17minutes (or for the helper value)

2nd automation

  1. Trigger: Pump Timer expires
  2. Condition: Time is before 11PM (or whenever you want to stop the cycle)
  3. Action: Toggle pump switch
  4. Action: Start Pump Timer to run for 17minutes (or for the helper value)

Or you can put it in one automation with Trigger IDs and Choose and action.

Maybe I understand time_pattern wrong, but I thought if I put /17, it would only trigger on times that are divisible by 17. So for a 5:45am-6:45am time slot, it would only trigger at 6:00am and 6:17am and no other times.

I will have to give something like this a try and see if that helps. I’ve been looking into the timer helper and that seems to be the best way to do it. I’ll post once i’ve had a chance to update and retest.

Generally it is recommended to use / intervals that divide evenly into 60 (other times are not well defined) - I am not sure if there is any kind of randomization in the Python library (some libraries do some don’t).

I would always recommend TIAS, I usually find there is some odd quirk that wasn’t obvious that you need to deal with.

However in your case, it would also trigger at 5:51 assuming no randomization.