ESPHome: DIY Irrigation Controller With Internal Scheduler

Hi Joaquin
The Moment I translate To English The GPIO pins does’nt respond .
Somewhere Im missing something
Converting days to week numbers, change text based on your Language

if (day == "Mon" || day == "mon" || day == "MON") {

      next_wday = 2;

    } else if (day == "Tue" || day == "tue" || day == "TUE") {

      next_wday = 3;

    } else if (day == "Wed" || day == "wed" || day == "WED") {

      next_wday = 4;

    } else if (day == "Thu" || day == "thu" || day == "THU") {

      next_wday = 5;

    } else if (day == "Fri" || day == "Fri" || day == "FRY") {

      next_wday = 6;

    } else if (day == "Sat" || day == "sat" || day == "SAT") {

      next_wday = 7;

    } else if (day == "Sun" || day == "sun" || day == "SUN") {

      next_wday = 1;

    } else if (day == "Tod") { //Today in English

      next_wday = time_wday;

    }

What do have here?


else if (day == "Tod") { //Today in English

Hi I have tried many diff inputs with no response. Should the field match any criteria?

I have this as it is No Idea what it should be …haha

Hi Ockie - I had a similar issue, with it turning off after 60s, and not sure if I have resolved it. Please also check in the esp yaml file. I had to change the “ahora” back to “now” here, and for the other zones. That seems to have fixed it, but I am still testing.

        # Show the "Next Time" as "now".
        - text_sensor.template.publish:
            id: irrigation_zone1_next_watering
            state: "ahora"

I started with Joaquin’s code but spent a lot of time after installing in HA to change it back to English. As I am fairly new to HA, I did not realise that all the entities are very hard to fully rename, as the IDs are deeply set in the HA registry. This made my logs very confusing. My advice to others is to do any re-naming before loading into HA. Also look at Blakes’ repo, which has all the code in one place.

1 Like

HI There Qurm Yes agree I tried Blakes code out of the box and it just worked. U don,t have to change much Next issue is im trying to add zone nr 6 (Copy and paste all the code from zone 5 and rename it to 6 But when I flash the esp ,it goes into a loop. Might be a space issue? or somewhere the code is wrong again. I will re check report back !

2 Likes

Hey all I’m going to replace my existing dumb sprinkler controller with an ESPhome home brew version that you’ve all been creating or contributing to. I have a couple of questions before getting the HW.

Has anyone driven an 8 zone setup with an ESP12 using this method (ESPhome etc), and is it stable ?

Reason I ask is I found this very cheap way into it on Aliexpress.
ESP8266 ESP-12F Wireless WiFi Programmable Module 8 Channel Relay

If an ESP12F is not going to cut it I’ll avoid that option and go with what @bremby did with a regular 8 Ch relay module and ESP32 module separately…
Any advice guys ?
Martin

I think some more time I spent trawling for ESP32 relay board info has obsoleted the previous question… but somebody might answer the ESP12 question for filling in that info for completeness.

Now I stumbled on this ESP32 8 channel relay board, that sort of begs to be an ESPhome irrigation controller with no cobbling up of modules. More expensive but still way less than most store bought eight channel WiFi irrigation controllers. Now I see this I don’t think I’d worry about a ESP12 version that I pondered in the above post question.

Use in Home Assistant here, with I/O listing.
https://www.kincony.com/forum/showthread.php?tid=1008

One seller on Aliexpress.
KC868 A8 Ethernet Relay Network ESP32 Wifi Switch MQTT TCP Web HTTP Schedule ESPhome Home Assistant Tasmota DIY Module|Home Automation Modules| - AliExpress?

Anyone bought one here for a sprinkler system ?

The Ethernet port of the ESP32 sure is a nice feature, and it has open ports available for sensors as well! If you have an Ethernet connection and your Home Assistant is reliable, you could opt to use Automations for scheduling instead of the complex ESPHome scheduler my code uses.

I’ve bought one of the boards via Aliexpress. I guess we’ll see how it goes in about a month when it arrives.
I’d like to add a 16x2 I2C LCD, and use three of four of the inputs for buttons when I box it up.
I’ll have to either run a small 12V DC supply and a 24V AC supply (for the irrigation solenoids), or more likely, I’ll put a small bridge rectifier and 12V regulator off of the 24V AC supply and feed the board from that.

It also occurred to me that the board might be able to run the ESP32 OpenSprinkler port if somebody didn’t want to use ESPhome…

@mr.sneezy, will you drop me a line once you have received it?
I am tempted to buy one as well, but for replacing an old alarm system with ESPHome, like Konnected.

The 8 input sounds perfect fit, plus 1 or 2 outputs.

I like your Irrigation idea as well. But I am not planning to replace the current LinkNode R8 what I built a few years ago. The local buttons would be nice, but I can live without that.

Certainly sir. AliExpress says it’s now left China, on the way to Australia.

Me too. It looks like a great fit for my irrigation system.
Please update here rather than dropping @GSzabados a line :wink:

1 Like

Can anyone say what the ethernet chip is on those kincony relay boards?

They have the schematic on their website here.

That doco shows it’s using a Microchip LAN8720A

Guys the KC868-A8 board arrived today. Well packed which is nice, decent size box and bubble wrap.

PCB looks well made, soldering quality is very good.

The board powered up fine and has a some preloaded code in it that does a relay drive test. It turns on each relay in turn, and leaves them on till reset.
I didn’t look for a webserver AP, I just installed a blank instance of ESPhome via ESPhome Flasher.
All good, it’s alive and HA detected the new ESPhome device in seconds.

Not sure how much I’ll do with it in the next 10 days as this has arrived at a time when I’m maxed out with work 24/7.

I will try buy a box for it tomorrow though. Thinking this one.
BoxCapture

3 Likes

looks good.
I’m tempted.
Only prevented from the old ‘if it ain’t broke, don’t fix it’
:slight_smile:

I’ve done a quick relay and input test. Took a bit longer than I thought because I expected the I2C to be on GPIO 21 & 22 because my ESP32 DevKit V1 datasheet said so. Not…

This test code is everything under my ESPhome header block for a ESP32. Relay fine controls from HA devices, and HA registers a binary sensor button press fine (shorting input 1 terminal to GND).
Now on to work out how to rename GPIO in Blakes config to use the PCF8574’s


# Example configuration entry for ESP32
i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a

# Example configuration entry
pcf8574:
  - id: 'pcf8574_output_hub'
    address: 0x24
    pcf8575: false
  - id: 'pcf8574_input_hub'
    address: 0x22
    pcf8575: false
# Individual outputs
switch:
  - platform: gpio
    name: "Irrigation-Zone1"
    pin:
      pcf8574: pcf8574_output_hub
      # Use pin number 0
      number: 0
      # One of INPUT or OUTPUT
      mode:
        output: true
      inverted: true
      
# Example configuration entry
binary_sensor:
  - platform: gpio
    pin:
      pcf8574: pcf8574_input_hub
      # Use pin number 0
      number: 0
      # One of INPUT or OUTPUT
      mode:
        input: true
      inverted: true
    name: "Irrigation-Button1"
2 Likes

Hey Blake,
I’m trying your irrigation code with the KC868-A8 ESP32 relay board, but having some issues getting it running. I’m not sure where the problem may be because the ESP32 seems to be rebooting (boot looping I guess) after loading the code. It may be an ESPhome compiler issue, maybe something I’ve done.
I’ve removed the pcf8574 code the board needs and tried as close to your code unedited as I can (which is really just the SSID and passwords edited) and still find the ESPhome logs show the ESP32 resets right after I2C initialization. I’m using the latest Hass OS, HA and ESPhome builds on a RPi 3B.
Some logs:

Using 'COM3' as serial port.
Writing at 0x001005cb... (100 %)Wrote 1002096 bytes (568236 compressed) at 0x00010000 in 13.5 seconds (effective 595.0 kbit/s)...
Hash of data verified.

Leaving...
Hard Resetting...
Hard resetting via RTS pin...
Done! Flashing is complete!

Showing logs:
[18:44:00]abort() was called at PC 0x401699bb on core 1
[18:44:00]
[18:44:00]ELF file SHA256: 0000000000000000
[18:44:00]
[18:44:00]Backtrace: 0x40089430:0x3ffb19f0 0x400896ad:0x3ffb1a10 0x401699bb:0x3ffb1a30 0x40169a02:0x3ffb1a50 0x401690cb:0x3ffb1a70 0x4016a533:0x3ffb1a90 0x40169daa:0x3ffb1d30 0x4016a438:0x3ffb1d50 0x400e2876:0x3ffb1d70 0x400e2ad5:0x3ffb1df0 0x400e1ae9:0x3ffb1e30 0x400e1527:0x3ffb1e50 0x4017474f:0x3ffb1e70 0x400e30c3:0x3ffb1e90 0x40173aa3:0x3ffb1eb0 0x400dc05d:0x3ffb1ed0 0x40173dd1:0x3ffb1f20 0x40173ead:0x3ffb1f40 0x400df47a:0x3ffb1f60 0x400e27ee:0x3ffb1f90 0x400f8349:0x3ffb1fb0 0x4008a6be:0x3ffb1fd0
[18:44:00]
[18:44:00]Rebooting...
[18:44:00]ets Jun  8 2016 00:22:57
[18:44:00]
[18:44:00]rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
[18:44:00]configsip: 0, SPIWP:0xee
[18:44:00]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[18:44:00]mode:DIO, clock div:2
[18:44:00]load:0x3fff0018,len:4
[18:44:00]load:0x3fff001c,len:1044
[18:44:00]load:0x40078000,len:8896
[18:44:00]load:0x40080400,len:5828
[18:44:00]entry 0x400806ac
[18:44:01]abort() was called at PC 0x401699bb on core 1
[18:44:01]
[18:44:01]ELF file SHA256: 0000000000000000
[18:44:01]
[18:44:01]Backtrace: 0x40089430:0x3ffb0490 0x400896ad:0x3ffb04b0 0x401699bb:0x3ffb04d0 0x40169a02:0x3ffb04f0 0x401690cb:0x3ffb0510 0x4016a533:0x3ffb0530 0x40169daa:0x3ffb07d0 0x4016a438:0x3ffb07f0 0x400e2876:0x3ffb0810 0x400e2ad5:0x3ffb0890 0x400e1ae9:0x3ffb08d0 0x400e1527:0x3ffb08f0 0x4017474f:0x3ffb0910 0x400e30c3:0x3ffb0930 0x40173aa3:0x3ffb0950 0x400dc05d:0x3ffb0970 0x40173dd1:0x3ffb09c0 0x40173ead:0x3ffb09e0 0x400e0361:0x3ffb0a00 0x400ec2b3:0x3ffb0a50 0x400f833a:0x3ffb1fb0 0x4008a6be:0x3ffb1fd0
[18:44:01]
[18:44:01]Rebooting...
[18:44:01]ets Jun  8 2016 00:22:57
[18:44:01]
[18:44:01]rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
[18:44:01]configsip: 0, SPIWP:0xee
[18:44:01]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[18:44:01]mode:DIO, clock div:2
[18:44:01]load:0x3fff0018,len:4
[18:44:01]load:0x3fff001c,len:1044
[18:44:01]load:0x40078000,len:8896
[18:44:01]load:0x40080400,len:5828
[18:44:01]entry 0x400806ac

The only other useful clue I can see is there is a compiler warning, but it still compiles past it OK.

Compiling /data/irrigation-controller/.pioenvs/irrigation-controller/FrameworkArduino/esp32-hal-rmt.c.o
Compiling /data/irrigation-controller/.pioenvs/irrigation-controller/FrameworkArduino/esp32-hal-sigmadelta.c.o
Compiling /data/irrigation-controller/.pioenvs/irrigation-controller/FrameworkArduino/esp32-hal-spi.c.o
/data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c: In function 'spiTransferBytesNL':
/data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c:922:39: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
                 uint8_t * last_out8 = &result[c_longs-1];
                                       ^
/data/cache/platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-spi.c:923:40: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
                 uint8_t * last_data8 = &last_data;
                                        ^
Compiling /data/irrigation-controller/.pioenvs/irrigation-controller/FrameworkArduino/esp32-hal-time.c.o
Compiling /data/irrigation-controller/.pioenvs/irrigation-controller/FrameworkArduino/esp32-hal-timer.c.o

Blake or anyone have a suggesting to try ?
Also happy to move the questions to your Github repo Blake.
Cheers,
Martin

Did you add the KC868-A8 ESP32 on the ESPHome integration?
image
This is the reason most of the time of the infinite reboot loop