Introduction: Smart Integration of a Tesla PowerWall With a Hot Water Cylinder Using HAOS
This project addresses the following problem: The Hot Water Cylinder (HWC) drains the PowerWall at inconvenient times.
NodeRed and ESPHome are used within the Home Assistant Operating System (HAOS) to solve this problem by handling energy monitoring, and managing wireless switching of a HWC relay.
Supplies
- YYG-2 relay board (or similar)
- ESP32 board
- Small power efficient computer
- 5V or 12 V power regulated power supply for the relay
Step 1: Install a Wireless Controlled Relay on Your HWC
⚠️ Important Safety and Legal Notice
This step involves working with 240 V mains electricity at currents up to 15 A, which can cause serious injury, fire, or death if done incorrectly.
All mains-voltage wiring must be carried out by a suitably qualified and licensed electrician, and must comply with all applicable local electrical regulations and building codes.
If you are not legally permitted or appropriately trained to perform mains electrical work in your jurisdiction, do not attempt this step yourself.
Incorrect installation may create a fire hazard, damage equipment, or void home insurance. This project is provided for informational purposes only.
Low-Voltage Control Electronics (ESP32 Side)
The relay used in this project requires an external DC power source and is available in several voltage variants.
I used the 12 V version, combined with a buck converter to supply the ESP32, because I already had a suitable 12 V power supply available. In most cases, the 5 V relay version is more convenient, as many ESP32 boards can run directly from a 5 V supply using their onboard voltage regulator.
If a 12 V supply is used, a suitable buck converter must be included to safely step down the voltage for the ESP32.
Relay Installation and High-Current Considerations
- Ensure the relay breather tab is removed. Relay contact closure at 240 V generates trace amounts of nitrogen oxide gases which must be vented. Failure to remove the breather tab can lead to internal corrosion and premature relay failure.
- The relay board must be reinforced with suitably thick conductors and high-quality solder joints on the high-current paths (see photo). These connections must safely carry >10 A continuous current. Inadequate conductor sizing or poor soldering may result in excessive heating and fire.
- Mount the ESP32, relay, and any buck converter on perfboard or an equivalent carrier, ensuring that one free GPIO pin is routed to the relay control input.
- All components should be securely mounted using spacers or risers, ensuring adequate airflow beneath the relay for heat dissipation and to prevent contact with other surfaces.
- All 240 V terminal screws must be tight and secure. High current combined with poor connections can cause resistive heating, equipment failure, or fire.
Step 2: HAOS Setup
- Purchase a suitable computer with a low power consumption. Get something with 8 Gb ram and at least two cores. You can do better than a Raspberry Pi. HP Thin-Clients are good, and really cheap on ebay.
- Configure the BIOS so that the computer automatically switches on after power failure.
- Follow these instructions to install HAOS.
- Connect the HAOS computer directly to your router with ethernet cable, and access it remotely via the webpage.
- In HAOS go to Settings->Add-ons->Add-on Store and install "Node-Red" and "EspHome Device Builder"
- In HAOS go to ESP-Home-Builder and click "+ New Device" and then follow the instructions to add your ESP32 board. You'll need to add a switch component to the config file. Your configuration, particularly the switch section, should look like this.
- After installing the ESP32, you should be able to switch the HWC remotely from HAOS.
Step 3: PowerWall Setup
- Install the HACS integration using these instructions.
- In HACS install alandtse's custom tesla integration see instructions -> https://github.com/alandtse/tesla
- You should now be able to see, and have full control over the PowerWall from HAOS.
Step 4: Install Node Red Flow
Critical Node-RED Control Flow
This Node-RED flow performs the core decision-making for the system. It resolves a non-trivial, three-way optimisation problem:
- Aggressively charge the hot water cylinder (HWC) when surplus energy is available
- Minimise relay switching to avoid wear and contact fatigue
- Minimise use of the home battery to heat water
Balancing these constraints simultaneously is the key challenge of this project.
Installation and Configuration
Download and import the Node-RED flow using the link below. Before it will operate correctly, you must update all Entity IDs and location-specific values to match your Home Assistant installation.
Entity IDs can be copied directly from Home Assistant:
- Go to Overview
- Click the relevant entity
- Click the cogwheel
- Copy the Entity ID
Be sure to update all Entity IDs, including those used inside the Function nodes.
Definition of “Surplus Power”
In this project, surplus power is defined as:
Solar generation minus household consumption
A positive surplus indicates energy that would otherwise be exported to the grid or absorbed by the battery, making it available for opportunistic water heating.
Control Strategy and Hysteresis
The flow uses explicit hysteresis and time delays to prevent rapid cycling and unnecessary battery discharge.
For example:
- If the HWC is running and a cloud passes over, the battery may briefly begin supplying power (e.g. 3.3 kW).
- Rather than switching immediately, the flow allows this condition to persist for 150 seconds before turning the HWC off.
- Once switched off, the system enters a 5-minute stand-down period, during which no restart is allowed.
- After the stand-down expires, the HWC will only restart once surplus power exceeds a higher restart threshold (surplus_continue), ensuring stability.
This approach dramatically reduces relay wear while avoiding “chatter” caused by short-term solar fluctuations.
Battery-Aware Behaviour
Restart and cutoff thresholds are dynamically adjusted based on the battery state of charge (SoC):
- When the battery is nearly full, the system becomes more aggressive about restarting the HWC.
- As the battery empties, restart thresholds rise and cutoff thresholds fall, prioritising battery preservation.
This adaptive behaviour allows the system to opportunistically harvest surplus solar without treating the battery as a primary heat source.
Seasonal Insight (Important)
One key observation from tuning this system is:
Control parameters that work well in mid-winter also work reliably in summer — but not the other way around.
Winter conditions represent the most constrained operating environment (lower solar availability, tighter margins). Optimising for winter therefore produces a control regime that remains stable year-round.
The default parameters provided here reflect that philosophy.
Tunable Parameters
Most behaviour can be fine-tuned via three nodes:
- Set Hysteresis
- Battery Power Stress
- Stand-Down Delay
The most important logic lives in the Set Hysteresis function node, shown below.
Example: “Set Hysteresis” Function Node
These values work well across seasons in my installation, but every system is different. You may wish to adjust them to reflect:
- Local solar capacity
- Battery size
- Hot water element rating
- Personal tolerance for battery usage versus grid export
Why This Matters
This flow treats the hot water cylinder as a thermal battery, while respecting the physical limitations of relays, the economic value of stored electrical energy, and the inherently noisy nature of rooftop solar.
The result is a system that is predictable, stable, and season-agnostic — exactly what you want for unattended energy automation.
Attachments
Step 5: Add HWC Diagnostics to Home Assistant
It's really helpful to be able to keep track of how long the HWC has been on for today, and how many times the relay has been switched on over its lifetime. Both parameters can be set up within HAOS.
To add a HWC on-time sensor:
- In Settings->Add-ons-> Add-on Store, add the "Studio Code Server" to edit HAOS config files.
- Copy the text from hwc_on_time_sensor.yaml into your HAOS config.yaml file.
- In Developer tools->restart, click Quick-reload for changes to take effect.
To add a relay counter:
- Follow these instructions to create a HWC on counter.
- Go to Settings->Automations & scenes-> then click + Create Automation. Now configure the HWC counter to increment every time the HWC switch turns on. (see picture above)
Step 6: Check the HWC Status Every Evening
On dark rainy winter days, the above Node Red flow ensures that your HWC will not charge during the day. Therefore, you need a mechanism to check the daily HWC on-time, and top up at night when the power is cheap. In this instance, you want the HWC to charge from the grid, and not the battery.
Because you use more hot water in winter, you also want to automatically specify a greater winter HWC on-time compared to the summer.
The following node red flow handles all that. You may need to configure the parameters for your needs.






