ESP8266 Aquarium Controller Part 3

Now that all the hardware is put together (Step 1 and Step 2), it’s time to program the ESP8266.

This is a pretty versatile device and you can make it do just about anything you want. You could add some buttons and dials to control the relays and set timers and make the controller completely autonomous. In my case, I already have a Home Assistant controller so I only needed this new controller to be remotely controllable.

The code at the end of this article sets up the ESP8266 to be an MQTT client. It communicates with Home Assistant through a MQTT server/broker using its built in wifi chip. It publishes the following information:

  • aquarium/1/relayHeater/set
  • aquarium/1/relayLight/set
  • aquarium/1/relayCO2/set
  • aquarium/1/rssi (this is the wifi signal strength)

The code also checks for the following payloads:

  • aquarium/1/relayHeater
  • aquarium/1/relayLight
  • aquarium/1/relayCO2

Before compiling and uploading the code, you will need to insert the following information:

  • WiFi SSID
  • Wifi Password
  • MQTT Server IP Address
  • MQTT User ID
  • MQTT Password

You can also edit the Client_ID (must be unique) and the MQTT_Topic.

Once everything is compiled and loaded onto the ESP8266, you’ll probably want to monitor it through the serial monitor to make sure it’s working correctly. If it looks good you can disconnect it from your PC and power it through the USB adapter that you installed in Step 2.

Setting Up Home Assistant

You can use anything that’s compatible with MQTT to monitor and control your new aquarium controller. In my case, I’m using Home Assistant with the MQTT addon so I can integrate the aquarium with all my other automations and interfaces.

First you’ll need to add MQTT to Home Assistant. There are many guides out there so I won’t go into it here. After that, simply add the following to your configuration.yaml file and reboot:

Now you should have two new sensors – one for the aquarium’s temperature and another one for the aquarium controller’s wifi strength.

You’ll also have three new switches: Light, Heater, and CO2.

And for convenience, I also combined the heater switch and the temperature sensor into a new generic thermostat. Now it can be controlled easily through the Lovelace UI or even through Google Assistant.

I set up my UI using a Horizontal Stack and Glance card. Pressing/clicking on the icons pops up their history and a switch to turn them on or off.

Now you can add the new entities to your automations and your UI. Enjoy!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *