My First Aquarium Project

Hello everyone, I had the pleasure to show you my first simple project for the temperature management of my aquarium and ask you for advice on development.
The design is based on an ESP8266MOD (nodemcu v2), a DALLAS probe and an SSD1306 128x64 i2c display.
If the temperature is lower than 23 then the heater is activated. If it is higher than 27 then it activates the fan. Between 23 and 27 then it turns off everything.
The OLED display shows current temperature with a graph of recent values and the status of switches.

Below the code developed:

esphome:
  name: esp8266mod

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "..."

ota:
  password: "..."

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:

switch:
  - platform: gpio
    pin: D4 #Internal LED switching
    name: "Internal LED"
    id: Internal_LED
    inverted: yes

  - platform: gpio
    pin: D6
    name: "Heat Switch 1"
    id: Heat_Switch_1
    inverted: yes
	
  - platform: gpio
    pin: D7
    name: "Fan Switch 1"
    id: Fan_Switch_1
    inverted: yes

dallas:
  - pin: D5
    update_interval: 10s

sensor:
  - platform: dallas
    address: 0x920312979463c228
    name: "Acquario"
    id: acquario
    on_value_range:
        below: 23
        then:
          - switch.turn_on: Heat_Switch_1
          - switch.turn_off: Fan_Switch_1
      - above: 23
        below: 27
        then:
          - switch.turn_off: Heat_Switch_1
          - switch.turn_off: Fan_Switch_1
      - above: 27
        then:
          - switch.turn_off: Heat_Switch_1
          - switch.turn_on: Fan_Switch_1

i2c:
  sda: D2  
  scl: D1
  scan: true

font:
- file: 'arialblk.ttf'
  id: font1
  size: 18
- file: 'arial.ttf'
  id: font2
  size: 15

graph:
  - id: single_temperature_graph
    sensor: acquario
    duration: 10min
    width: 110
    height: 41
    x_grid: 1min
    y_grid: 1.0
    line_type: SOLID
    line_thickness: 3

display:
  - platform: ssd1306_i2c
    setup_priority: -100
    model: "SSD1306 128x64"
    #address: 0x3C
    update_interval: 1s
    contrast: 90%
    id: sensor_display
    pages:
      - id: page1        
        lambda: |-
          it.printf(20, 1, id(font2), TextAlign::TOP_LEFT , "Current:%.1f°", id(acquario).state);
          it.graph(10, 20, id(single_temperature_graph));
      - id: page2
        lambda: |-
          it.printf(20, 1, id(font2), TextAlign::TOP_LEFT , "Current:%.1f°", id(acquario).state);
          it.printf(5, 30, id(font1), "Heat 1: %s", id (Heat_Switch_1).state? "ON": "OFF");
      - id: page3
        lambda: |-
          it.printf(20, 1, id(font2), TextAlign::TOP_LEFT , "Current:%.1f°", id(acquario).state);
          it.graph(10, 20, id(single_temperature_graph));
      - id: page4
        lambda: |-
          it.printf(20, 1, id(font2), TextAlign::TOP_LEFT , "Current:%.1f°", id(acquario).state);
          it.printf(5, 25, id(font1), " Fan 1: %s", id (Fan_Switch_1).state? "ON": "OFF");

interval:
  - interval: 5sec
    then:
      display.page.show_next: sensor_display

Finally, I created on HA a simple Dashboard with indicator and status switch:

The code:

type: gauge
entity: sensor.acquario
name: Temperature
unit: °C
min: 10
max: 40
segments:
  - from: 10
    color: '#0000B0'
  - from: 23
    color: '#00A000'
  - from: 27
    color: '#db4437'
needle: true

I would like to add two additional temperature bands to duplicate heaters and fans.
Unfortunately to manage two more switches I need additional GPOs that are not available on nodemcu.

What do you suggest I do?

  • Buy an esp32-WROOM?
  • Are there any port replicators that I can insert into the project?

Thank you in advance for your support.
I would like to have your comments since this is my first project. : )

M@t

You must have more pins available, looking at your code it looks like you only using 6 pins. (D1,D2,D4,D5,D6,D7) 17 gpio pins, one analoge looks like is available on that board.

Or do you use more things then in the yaml?

I wonder why you didn’t use a climate component? eg Thermostat Climate Controller — ESPHome

As reported in this table the only pins useful is :

  • D1 and D2 (used for i2c bus → OLED)
  • D5 used for DALLAS probe
  • D6 and D7 used for 2 of 4 relay

It seems that:

    GPIO16: pin is high at BOOT
    GPIO0: boot failure if pulled LOW
    GPIO2: pin is high on BOOT, boot failure if pulled LOW
    GPIO15: boot failure if pulled HIGH
    GPIO3: pin is high at BOOT
    GPIO1: pin is high at BOOT, boot failure if pulled LOW
    GPIO10: pin is high at BOOT
    GPIO9: pin is high at BOOT

What other pins can I use without causing problems?

Thank you so much for your valuable support

M@t

Thanks I’ll try this component!

M@t

What about D3?

If you want more, use esp32.

In my idea I have to set 5 range with 4 switches:

  1. below 20° (Two heat switches powered on)
  2. from 20° to 23° (only one heat switch powered on)
  3. from 23° to 27° (all switches is powered off)
  4. from 27° to 30° (only one Fan switch powered on)
  5. above 30° (Two heat switches powered on)

Screenshot from 2023-02-11 19-35-19

For this I would need additional 2 GPIOs.

Thanks!

I think that you can use any of the pins as long as you let the device boot with the correct state.
After boot you can use the pins for output.
ex. D8 that’s GPIO15 is pulled to GND, but after boot you can turn it high or low as a switch.
D4 can be used, it’s connected to the LED so it will flash etc as you use that as a switch.
Again D4 is GPIO2 boot will fail if pulled to GND, after you can use it as a switch.
Now if you connect a relay to D4 it will boot high which will turn on the relay. but after the board has booted up you can turn it off and on.
D0 looks like its missing PWM, boots high but for a switch should work.

You can see it as a boot sequence of sort. where you will hear some relays click on boot.

Optimal is to avoid those but is possible to use.