ESPHome: DIY Irrigation Controller With Internal Scheduler

Hi. The irrigation device and it’s many entities are listed, automatically as I didn’t manually add it.

If I go into ESPhome config GUI and show ‘logs’ for the device this is what I’m getting.

INFO Reading configuration /config/esphome/irrigation-controller2.yaml...
INFO Detected timezone 'Australia/Adelaide'
INFO Starting log output from irrigation-controller2.local using esphome API
INFO Successfully connected to irrigation-controller2.local
[10:10:43][I][app:102]: ESPHome version 2021.12.3 compiled on Jan  2 2022, 22:29:56
INFO irrigation-controller2.local: Error while reading incoming messages: Error while reading data: [Errno 104] Connection reset by peer
INFO Disconnected from ESPHome API for irrigation-controller2.local
WARNING Disconnected from API
INFO irrigation-controller2.local: Ping Failed: Error while reading data: [Errno 104] Connection reset by peer
INFO Successfully connected to irrigation-controller2.local

In the devices ‘status’ history I see mostly disconnected with frequent brief connected’s.

Also one odd thing I’ve during in multiple firmware builds and loads, is I get compiler fail about 20% of the time, it might be relevant but I’m not sure. Often another subsequent compile attempt passes OK and I can load the binary via ESPhome Flasher, so I’ve been ignoring the messages, maybe I shouldn’t…
This is the fail message section during compilation, when it fails sometimes.

Compiling /data/irrigation-controller2/.pioenvs/irrigation-controller2/libc74/ESPAsyncWebServer-esphome/AsyncEventSource.cpp.o
Compiling /data/irrigation-controller2/.pioenvs/irrigation-controller2/libc74/ESPAsyncWebServer-esphome/AsyncWebSocket.cpp.o
Archiving /data/irrigation-controller2/.pioenvs/irrigation-controller2/libbc6/libUpdate.a
Compiling /data/irrigation-controller2/.pioenvs/irrigation-controller2/libc74/ESPAsyncWebServer-esphome/WebAuthentication.cpp.o
Compiling /data/irrigation-controller2/.pioenvs/irrigation-controller2/libc74/ESPAsyncWebServer-esphome/WebHandlers.cpp.o
Compiling /data/irrigation-controller2/.pioenvs/irrigation-controller2/libc74/ESPAsyncWebServer-esphome/WebRequest.cpp.o
Compiling /data/irrigation-controller2/.pioenvs/irrigation-controller2/libc74/ESPAsyncWebServer-esphome/WebResponses.cpp.o
xtensa-esp32-elf-g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
*** [/data/irrigation-controller2/.pioenvs/irrigation-controller2/src/main.cpp.o] Error 4
========================= [FAILED] Took 199.96 seconds =========================

I have no idea where the message thinks I should send a bug report.

Sorry for the monologue here but I’m still working the on problem as time permits in a busy day.

I have reverted to my modified version of Blakes code, were I added the pcf8574 multiplexer platform that I need on this board to control relays and sense inputs. This also compiles with the same errors as above but also creates a binary after a couple of passes. (PS. I note that after running ‘Clean Build Files’ in the ESPhome GUI the next pass always fails).

With the pcf8574 stuff added I can control my relay entities during the time the ESP32 is connected (so between reboots), this is encouraging.

What doesn’t show anything are the list of sensor entities. They are always ‘unknown’.

Question: Do I need to have a special script or card running with this code that I’m not doing yet (which is causing my rebooting) ?

HI @mr.sneezy , any chance you added your esp to the esphome integration?
without that the esp restarts every 60sec

Hmm, I might need to confirm what added added means to make sure…

So after loading the firmware, I go to into Integrations GUI, click on add+, type in ESPhome, select it in the list, type in the Host IP address of the new device, this then finds it, and loads the entities.
Is that the correct method ?

yes sir, that’s what i mean

Ah, thanks. I’d be happy to be embarrassed to solve this as the project is important to me.
If you have any suggestions, even trivial, let me know and I’ll try ?
Otherwise might have to see if anybody else bought the same board and can try the irrigation code.

I wonder if ESPhome code can be compiled on another platform easily to try out, I’m thinking it might be something to do with using a RPi for my instance of HA and ESPhome…

I’m using this code without any issue, all the time I had the reboot loop was because I missed to add the board in the esphome integration

Could you recompile your code with the latest ESPhome for me and see if there are any build errors ?
Do a Clean Build Files first. No need to reflash it, just see if compiles clean of yellow or red warnings for me.
Is your HA on a RPi ?
Thanks.

I’m using an ESP32 board

Did you check the initial values?

input_text:
  ##Time Schedule
  irrigation_zone_1_times:
    name: Time Schedule - Zone 1
    icon: mdi:chart-timeline
    mode: text
    initial: 01:00 

input_number:
  ##Duration
  irrigation_zone_1_duration:
    name: Duration - Zone 1
    min: 0
    max: 30
    step: 1
    mode: slider
    icon: mdi:timer
    initial: 5

Nope, hadn’t realized that it was essential, thanks for the pointer. In fact I have nothing in HA yet other than the ESPhome device/entities, nothing in configuration.yaml and no card for irrigation.
With my past ESPhome projects I got the HW running first, then configured HA to use it, I made an assumption that this would be the same.

This project is a lot more complex now that I try to follow it in detail as a non programmer person ( realize I probably should have just built stand alone OpenSprinker in hindsight).

I’m using Blakes version of Brians code. This is not making it easier for myself either I think…

I’ve looked at the files on Blakes repo and don’t see what I need to add to configuration.yaml (with the initial values you mention).

If you are using Blakes version could you paste me the whole yaml block I need to add to HA configuration.yaml ?

Blake does have his card yaml in post #68 which I was going to use.

Still working on this irrigation project here when I get time. bremby has been assisting me behind the scenes to get the code together as it’s a bit fragmented when you actually look at whats been posted before and try to tie it all together.
This is how the hardware looks. Happy with the box size, plenty of space for getting access. Eventually there should be manual zone buttons and and I2C 16x2 LCD.

2 Likes

May you please confirm exact procedure you used to flash that board ? as I have issues with mine and Kincony is not really helpful :frowning: Right now I power the board with supply included with it (I get the init sequence with all relays going on) and plug the USB to my ESP box to flash it but no success in getting any communications with it ! Got no problems to flash other Kincony devices but not that one :frowning:

OK, what is an ‘ESP box’ ?
I have only used a USB cable direct from this board to my Win10 PC USB port running ESPhome Flasher 1.4.0 to program my board. With that setup I have had no problem getting code into the board.

While I’m here, I should add that I have never got my eight station code to compile without compiler errors (based on code from this thread), and the resulting code boot loops the ESP32 at about a 2 second rate. Debugging the compiler issue is above my knowledge level.

I have got basic ESPhome test code running fine though with treating the relays as switches and getting HA to do the timing.

Hi everyone

I have a 4CHPRO R2, and I like to use this project, but installing it via esphome keeps failing, I got this error, please any help is welcome.
PS: I am using the irrigation.h and irrigation.yaml and other files in common dir from {brianhanifin] GitHub

src/main.cpp: In function ‘void setup()’:
src/main.cpp:597:66: error: reference to ‘optional’ is ambiguous
597 | sensor_lambdafilter = new sensor::LambdaFilter([=](float x) → optional {
| ^~~~~~~~
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
from src/esphome/core/component.h:4,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: ‘template class std::optional’
60 | class optional;
| ^~~~~~~~
In file included from src/esphome/core/component.h:7,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note: ‘template class esphome::optional’
36 | template class optional { // NOLINT
| ^~~~~~~~
src/main.cpp:597:74: error: expected ‘{’ before ‘<’ token
597 | sensor_lambdafilter = new sensor::LambdaFilter([=](float x) → optional {
| ^
src/main.cpp:597:75: error: expected primary-expression before ‘float’
597 | sensor_lambdafilter = new sensor::LambdaFilter([=](float x) → optional {
| ^~~~~
/config/esphome/irrigation.yaml:559:47: error: reference to ‘optional’ is ambiguous
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
from src/esphome/core/component.h:4,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: ‘template class std::optional’
60 | class optional;
| ^~~~~~~~
In file included from src/esphome/core/component.h:7,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note: ‘template class esphome::optional’
36 | template class optional { // NOLINT
| ^~~~~~~~
/config/esphome/irrigation.yaml:559:55: error: expected ‘{’ before ‘<’ token
/config/esphome/irrigation.yaml:559:56: error: expected primary-expression before ‘bool’
/config/esphome/irrigation.yaml:273:47: error: reference to ‘optional’ is ambiguous
273 | lambda: return id(relay2).state;
| ^
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
from src/esphome/core/component.h:4,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: ‘template class std::optional’
60 | class optional;
| ^~~~~~~~
In file included from src/esphome/core/component.h:7,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note: ‘template class esphome::optional’
36 | template class optional { // NOLINT
| ^~~~~~~~
/config/esphome/irrigation.yaml:273:55: error: expected ‘{’ before ‘<’ token
273 | lambda: return id(relay2).state;
| ^
/config/esphome/irrigation.yaml:273:56: error: expected primary-expression before ‘bool’
273 | lambda: return id(relay2).state;
| ^
/config/esphome/irrigation.yaml:235:53: error: reference to ‘optional’ is ambiguous
235 | unit_of_measurement: minutes
| ^
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
from src/esphome/core/component.h:4,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: ‘template class std::optional’
60 | class optional;
| ^~~~~~~~
In file included from src/esphome/core/component.h:7,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note: ‘template class esphome::optional’
36 | template class optional { // NOLINT
| ^~~~~~~~
/config/esphome/irrigatie.yaml:235:61: error: expected ‘{’ before ‘<’ token
235 | unit_of_measurement: minutes
| ^
/config/esphome/irrigatie.yaml:235:62: error: expected primary-expression before ‘float’
235 | unit_of_measurement: minutes
| ^
/config/esphome/irrigation.yaml:250:53: error: reference to ‘optional’ is ambiguous
250 | - platform: restart
| ^
In file included from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/node_handle.h:39,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/hashtable.h:37,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/unordered_map:46,
from /data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/functional:61,
from src/esphome/core/component.h:4,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/optional:60:11: note: candidates are: ‘template class std::optional’
60 | class optional;
| ^~~~~~~~
In file included from src/esphome/core/component.h:7,
from src/esphome/components/api/api_connection.h:3,
from src/esphome.h:3,
from src/main.cpp:3:
src/esphome/core/optional.h:36:28: note: ‘template class esphome::optional’
36 | template class optional { // NOLINT
| ^~~~~~~~
/config/esphome/irrigation.yaml:250:61: error: expected ‘{’ before ‘<’ token
250 | - platform: restart
| ^
/config/esphome/irrigation.yaml:250:62: error: expected primary-expression before ‘float’
250 | - platform: restart
| ^
Compiling /data/irrigation/.pioenvs/irrigation/lib67b/ESP8266WiFi/ESP8266WiFiAP.cpp.o
Compiling /data/irrigation/.pioenvs/irrigation/lib67b/ESP8266WiFi/ESP8266WiFiGeneric.cpp.o
Compiling /data/irrigation/.pioenvs/irrigation/lib67b/ESP8266WiFi/ESP8266WiFiGratuitous.cpp.o
*** [/data/irrigation/.pioenvs/irrigation/src/main.cpp.o] Error 1
========================= [FAILED] Took 37.32 seconds =========================

Out of curiosity does the irrigation.yaml validate with out errors before you compile ?

Yes, the irrigation.yaml validates without any error…

any ideas?

I did more digging up and I found that it is an Esphome issue. It is reported here…

I did a framework downgrade to make it work, it is not a neat solution, but a temporary one, until Esphome corrects the code.

Trouble with more than 6 zones.
Hi all,
Even though this thread seems to have gone very quiet I hope somebody may have some experience about taking this code past 6 zones. I need to use 8 zones, the KC868-A8 board supports 8 relays for zones, and my old dumb controller has all 8 of it’s zones in use…

The trouble is that this code with internal scheduler craps out at above 6 zones (i.e. Code with 7 or 8 zones configured does not run on the ESP32).

Can anybody confirm they have 7 or more zones working ?

Here is my code below in a Github link for 7 zones that stops the ESP32 booting properly (i.e. repeating debug error messages from the ESP32 after USB serial flashing at about a 1hz rate, and all entities go unknown on HA GUI).
If I cut out all zone 7 code blocks to reduce it to 6 zones, the code the ESP32 and all zones and timer function perform perfectly (when flashed via .bin and USB cable) , and I’ve run functional tests on the bench for days with no issues.
When compiling 6, 7 or 8 zone code there are no compiler warnings, and ESPhome validates all three codes fine. Running the latest ESPhome and HA core versions on an RPi4B.
Reported build size for 7 zones is
RAM: [= ] 13.1% (used 42896 bytes from 327680 bytes)
Flash: [===== ] 51.5% (used 945026 bytes from 1835008 bytes)
so does not seem to be an issue…

It’s like the ESP32 has run out of some other resources that are not being reported.

Can anybody confirm they have 7 or more zones working so I know it’s possible ?

Forum won’t let me paste the 1200 odd lines so added to my Github as yaml.
irrigation.yaml

I have successfully combined the code I got from here, with the code from bruxy70, with some modification to satisfy my need, using the nextion screen to show some useful information.
Thanks

5 Likes

I finally have got 8 zones running on the ESP32 relay board !
It was a low level problem with the size of the code when using 8 zones, and ESP32 stack size, (no wonder I had trouble resolving this…).
The issue causes the ESP32 to crash and boot-loop forever, and unless you have USB serial connected you won’t get much of a clue as to why.
The fix was found on the ESPhone issue forums when this tip was suggested, to force the ESP stack size to be increased.

This is the top section of my code showing the changes to the esphome: and ESP32: sections.

# 8 Zone Version
substitutions:
  devicename: irrigation-controller

esphome:
  name: $devicename
  platformio_options:
    build_flags: 
      - -DCONFIG_ARDUINO_LOOP_STACK_SIZE=16384
  includes:
    - irrigation.h

esp32:
  board: nodemcu-32s
  variant: esp32
  framework:
    type: arduino
    version: 2.0.2
    source: https://github.com/espressif/arduino-esp32.git#2.0.2
    platform_version: https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream

Edit: Forgot to mention it won’t compile in ESPhome on HASSOs on my Raspberry Pi4. I had to setup ESPhome under Windows10 on my PC and compile from that installation. Seems to be an issue with the required library install for the RPi. Bit of a PITA…

2 Likes