Getting data from Home Assistant into my program

Yes. Compared to what you weer proposing. It’s orders of magnitude easier than writing and hosting your own C# code and gpio then trying to get it into HA.

Esphome does all the heavy lifting and all your need to figure out is which sensors you are uzintand what needs to happen to expose them in HA.

I integrated my custom photovoltaic system in HA using MQTT. It was quite easy to do, the largest difficulty being MQTT discovery syntax.

  1. 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 :rofl:

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.

I fully agree with that, and that’s the reason of my first question to start with.

Figuring that out is exactly where I have problems.

That’s the way I was thinking of doing it.

Since you guys are so nice, I will allow myself to pick your brains a little more. By the way: not that it matters, but this is not MY sauna. It belongs to an older guy I want to do all this for. And it’s not in my city, I only go physically there like twice a year. This is just as extra information.

Let’s say I have my nice ESP32 board and I have connected all the things I need and I have the software that controls the whole thing. It works great “locally”. Now I need to give the guy the possibility to program his sauna to turn on at a specified time to the desired temperature.
Say also that I have an installation of HA and that I have activated the ESPHome integration. Keeping in mind that the guy doesn’t have WiFi in the floor where the sauna is and he doesn’t want to bring it there, so it would have to go wired, what would be my next steps to get HA to tell the ESP what to do?

Then you should use off the shelf gear that can be maintained by someone else. Otherwise you’ll end up married to it. Doesn’t stop you from using HA to control it, but it should work on its own.

The controls would be exposed in HA as actuators and sensors. There is an automation engine available.

Turn on at 0830 for 45 minutes… Sure thing.
Turn it off manually at the sauna? Great. There esp32 would sense that.

Once it’s IN HA you can pretty much expose that stuff to the users however you want all the way from discrete buttons to a full on sauna console if that’s what you want. (im having an LLM drive my hot tub (yes overkill but it’s fun.) as the ‘interface’

As mentioned already, you can either use WiFi or Ethernet with ESP devices.
Whatever you choose, whether it’s a RPi with HAT or wired/wireless ESP to control: IF you use HA as the user interface, for HA it doesn’t matter what’s behind it, as long as it can reach/control that device.

With the HA companion app they will be able to have control, whether locally, connected to the LAN or remotely IF that was set up.
Even with @bobflux their remark about being married to it: I would dare to do this project because it’s very possible to make this reliable.

1 Like

The idea of MQTT entices me. Care to share some of the code to do that?

Here:

This sends MQTT discovery messages that prompt HA to create the entities for this dash. It doesn’t create the dash or the GUI, you have to arrange that in HA.

1 Like

WOW, thanks. That helps an awful lot indeed.

It’s at least 70% of the project, or at least of the time I would have had to spend figuring it all out myself.

That seems easy enough from what I have read so far: I think I can manage that.

Many thanks again, you sure made my day. Expect to hear from me again with questions as soon as I start digging in the code. :blush:

There are both advantages as well disadvantages for using MQTT or ESPHome and in the end they are both just means to control/read devices.

Hehe, thanks.

I used gmqtt with python. It’s a good library, works well, uses very little resources. But there’s a gotcha: messages are not published immediately in the publish command, they are queued, then publish() returns immediately and gmqtt will send them to the broker in the background almost immediately. “Almost” means if you do not “await mqtt.disconnect” at the end of the program, then the program will exit before the messages are published :rofl:

I just want to say that I agree with those who say you should go for an ESP with ESP-Home.
Doing so means you have lots of people here that can help you and a lot will happily post > 90% of the code you will need to get this working.

However, going with a pie and/or some homebrew code you will limit your possibilities to get help.

You say that there is no wifi and none will be added.
Ok, but this project is to remote control the sauna. How far from the sauna will this remote control be done from?

An ESP can create its own wifi network where you could connect the phone to and remote control the sauna. But this will limit it to 10-15 m, perhaps more if there is good line of sight.

If you wanted to use Ethernet, is there Ethernet cables by the sauna already?

1 Like