Keep Recirculated Hot Water Hot by Out Smarting Your Smart Tankless Heater

I had several posts asking for advice on how to activate a contact switch virtually. I want to post my use case and the solution I came up with so others can benefit from my use.

I had a tank water heater with a separate recirculation pump that I was controlling using a smart plug and several automations. I just switched to a tankless water heater - which is great. It has built-in recirculation features - but it left some holes in my needs.

My recirculation loop is VERY long - it takes nearly 2 minutes at 3.5gpm water flow to get hot water back to the heater. Built-in recirculation routines are designed to turn OFF the recirc pump as soon as a faucet is opened. The idea is, water is flowing TO the open faucet so why continue to pull water around the loop. Well, if the loop is long and the faucet opened is near the beginning, the water at the later faucets is stuck without immediate hot water.

In my previous configuration I used a combination of physical and/or virtual switches to turn on the recirc pump for 20 minutes (baths and kitchen) or 2.5 hours for dishwasher. The pump would run regardless of whether any faucets were open and the lines stayed (relatively) hot.

My new tankless water heater has several options - scheduled times of day where it recirculates for some amount of time every x minutes to keep the lines warm. "Smart" schedule where it "watches" your usage patterns over time and anticipates when you might want hot water (good for very regular people). And "push button" recirculation - where physical (door bell) buttons can be placed near faucets that will start a single manual recirc cycle to prime the lines. This is the most efficient method as you only recirculate just at time of need.

A few of problems arise out of the push button method (which I am using) in that if you push the button and then turn on a faucet before it primes, the pump turns off and you have to wait for the hot water to arrive. If the button (or another) is pushed while water is flowing, that request is ignored. If you start water flow before the ENTIRE line is primed the downstream faucets will still have to wait for the water to get there. And for high efficiency dishwashers - that only pull in a small amount of water, but do it every 15-20 minutes - it really sucks, especially if it is literally at the last stop in the line!

That was a lot - here is my (at least initial) solution:
Water Heater: Navien NPE-240A2
Smart Contact Switch: Fibaro FGBS-222 Smart Implant
Rule Machine:
1 Rule that activates based on multiple physical/virtual switches - starts a 20 minute timer and activates repeating rule
1 Repeating rule that activates the output of FGBS 222 and "pushes the recirc button on the water heater" which, if water is not flowing recirculates and if water is flowing is ignored - this repeats every 3 minutes (it takes 2 minutes to prime).
1 Rule that activates based on virtual "dishwasher" switch that starts a 2:30 timer to keep the recirc rule running
1 Rule that stops all the action based on two virtual switches (cancels all timers)

Initial testing looks good - if any timer is triggered after another the timers reset and whenever water is not actively flowing the recirc triggers every 3 minutes - that fills in the gaps and keep the water lines hot for the duration.

I have no doubt my 4 rules could be combined into a single rule - or an app written, but the logic of 3 of my rules has served me well for a couple of years and adding the repeating rule for the recirc was pretty easy.

If anyone is interested here are my rules:

HW - On
If any of these switches turns on
On: The Hot Water (virtual switch)
Set Global1 to true
Run Actions: HW - Recirc
Cancel Delayed Actions
Delay 0:20:00 (cancelable)
IF (Global2 = false) Off: The Hot Water
Set Global1 to false

HW - Recirc
Repeat every 0:03:00
	On: FGBS Implant - Output 1
END-REP

HW - Dishwasher
If Dishwasher (virtual switch) turn on
Set Global2 to true
On: The Hot Water
Cancel Delayed Actions
Delay 2:30:00 (cancelable)
If (Global1 = false) Off: The Hot Water
Set Global2 to false

HW - Off
If The Hot Water or The Dishwasher any turns off
Off: The Hot Water, The Dishwasher
Cancel Timed Actions: HW - Dishwasher, HW - On, HW - Recirc
Set Global1 to false
Set Global2 to false