I integrated my custom photovoltaic system in HA using MQTT. It was quite easy to do, the largest difficulty being MQTT discovery syntax.
- Decide who will be the brains of the system. For example:
- The sauna only contains dumb sensors and actuators, all controlled by HA, like “turn on heater”
- Or the sauna has a local controller that takes orders from HA, like “adjust temperature setpoint”.
IMO the latter is preferable since a heater is involved: you want it to be controlled by a local thermostat, with HA setting the thermostat’s setpoint. So it will still regulate temperature and not start a fire if HA is down, network is down, etc. For the same reason, there should at least be an over temperature safety switch (mechanical, no software involved) and a local safety timer.
So you need a controllable thermostat and timer. These could be off the shelf, using Zigbee or other protocol, or DIY with an ESP32 for example.
This also applies to the other items in your project: the lights could be controlled by an off the shelf dimmer/switch (located outside of the sauna), you can use door sensors, etc, all of this controlled by HA using for example Zigbee. Or you could connect all this to a board with GPIOs like an ESP32 and roll your own code, your choice.
IMO it is best to combine several tools and use each tool for what it does best.
HA’s strength are:
- Compatible with pretty much every device on the market
- Bells and whistles, phone app, remote access, etc
- Great for UI and dashboards
- Great community
- Documentation
- etc
HA’s weaknesses are:
- Automation
Thus if you want to integrate a DIY system into HA it makes sense to leverage its strengths and have the DIY system doing only the local automations it should be is concerned about. This keeps the code simple.
It’s much simpler to keep things separate. Full fledged computers like a Pi are okay with I2C, USB and serial, but not suited for low level work like GPIO, sensors, or anything hard real-time. Especially bit banged protocols like 1wire will not work. This stuff works much better on a microcontroller that is dedicated to the task. ESP32 is nice for this because on one hand it’s a microcontroller, it can do all the low level stuff, but on the other hand it also has WiFi, which means MQTT, so it is very easy to interface with a “real” computer. With other MCUs you would be restricted to serial communication, which offers much less options, or USB, which is annoying and overkill most of the times.
Another option is the Pi Pico W, which has WiFi and micropython.
By implementing the UI and all the other stuff like sending alarm messages in HA you will save a lot more time than it will take to interface HA with a microcontroller.
Here’s an example:
The photovoltaic system has 2 inverters and batteries. Everything speaks Modbus, so this is controlled by an Orange Pi with off the shelf Waveshare USB-RS485 interfaces (8 ports). It runs python code which controls everything, the EV charger, the water heater, etc. However, to control the relays and PWM fans providing extra cooling to the inverters, I used a Pi Pico, which talks to the main Pi via serial. It took me very little time to write the micropython code to use a Pico as IO expander, which is something a Pi can’t do. Basically use each tool for what it does best, which is what everyone else is saying in the topic.
HA runs on a Nuc. It does not handle low level details at all, like adjusting EV charging power every 2 seconds when a cloud comes. It doesn’t even log the solar stuff because that would blow up the database. What HA does is show a nice dashboard with controls like set priority between EV and house battery, force charge the EV from the grid with a setting for start time and energy etc. Then it sends high level commands to the “Solar Pi” via MQTT, and this Pi controls all the other systems, inverters, EVSE, etc.