I have a 5kw water heater and a 9.6kw solar system with 8.2kW inverter. I would like to regulate the hot water system so that it takes only the power coming from the solar panels. So if panels are producing 3kW then the heater would only use 3kW. If the panels are producing 8kW then the heater would max out at 5 and I could feed 3kW into the grid or use it for something else. I would like to control this with a raspberry pi or arduino. I have the pi reading from my inverter no problem and it is also measuring the current going to the hot water. I just need a way to regulate the hot water system somehow. Is there some sort of PWM device that can handle 5000W and be controlled by a small voltage input? Also, is it feasible to make this legal? I was thinking an electrician could install the PWM device and I could do the raspberry pi side.