I have a sub-panel, with currently only a single conventional water heater connected (4500 watt non-simultaneous). The sub-panel is protected by a 50amp double-pole breaker in the main panel, wired with 6ga Romex. The water heater is wired with 10ga Romex, protected by a 30amp breaker in the sub-panel. So far, so good. However, I want to add a 5700 watt tankless water heater to the sub-panel; it also requires a 30amp breaker (and 10ga wire). Is this ok ? All wiring is sufficient to the size breaker protecting it, so it should be safe. And we know it's ok for breakers in a panel to sum up to more than the main breaker for that panel (e.g. all the breakers in a main panel typically far exceed the panel's overall rating). But the total wattage (should the tankless be activated while the main one is heating) would be 10.2kw, or 42.5 amps at 240v. That seems to be cutting it close for the 50amp breaker protecting the main panel, so I'm wondering if I'm likely to see it trip. Also don't want to violate code, even though this work will not be inspected.
Go ahead and put both loads on the same subpanel -- you don't need a relay for this, as the tankless heater isn't a continuous load (i.e. I can think of no situation where the domestic hot water should be running in a house for 3 hours straight!).
(The feeder calculations are as per 215.2(A)(1)(a) -- 125% of the 4500W storage heater is 5625W + the 5700W tankless heater yields 11325W, which is 47A@240VAC.)