Time-controlled processes - only partially work

Hello,

I am currently trying out ESPHome, I would like to use it for my irrigation.

The structure is that a 4-way relay board makes four switching processes.
a) Irrigation according to the schedule, the Relay1 (power supply 12V DC) should be switched on every day at a desired time, after 2 seconds a (Relay2) solenoid valve should be switched, switch-off vice versa.
The same with the second solenoid valve (Relay3) as well.

In addition, there are two actuators for each solenoid valve, with a shutdown logic (long button press)

It switches on but no longer off …

I have a relatively unstable WiFi in the greenhouse, so it should work independently of the home assistant.

Can someone look over my code to see if I have an obvious mistake?

Thanks!!!
Gerald

esphome:
  name: arrosoir
  comment: Bewässerung im Treibhaus
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  
# Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Regenmaster Fallback Hotspot"
    password: "ZSH3jEUeIAZF"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_user
  password: !secret mqtt_password

web_server:
  port: 80
  
sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 30s  

  - platform: dallas
    address: 0x5E00000535651F28
    name: "Treibhaus"

text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP
    

##Pinbelegung der Platine  
## GPIO0    PU    Taster 1 
## GPI04
## GPIO5
## GPIO15   PD    
## GPIO2    PU    Taster2
## GPIO3    RX    1Wire
## GPIO1    TX  

## GPIO12  Relay3
## GPIO13  Relay4 
## GPIO14  Relay2
## GPIO16  Relay1

## Zeiteinstellung und Timer  
time:
  - platform: homeassistant
    id: homeassistant_time
   
    on_time:  
## Bewässerungsstrang 1     
    - seconds: 0
      minutes: 00
      hours: 4
      days_of_week: MON-SUN
      then:
      - switch.turn_on: b1
 ## Bewässerungsstrang 2        
    - seconds: 0
      minutes: 05
      hours: 5
      days_of_week: MON-SUN
      then:
      - switch.turn_on: b2  
## Dachbelüftung
    - seconds: 0
      minutes: /40
      then:
      - switch.turn_on: rel4
      - delay: 15min
      - switch.turn_off: rel4


## Taster 1 und 2
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Bewässerung 1 manuell"
    on_press:
      then:
        - switch.toggle: b1
    on_click:
      min_length: 2s
      max_length: 4s
      then:
        - switch.turn_off: rel2
        - delay: 2s
        - switch.turn_off: rel1
    
  - platform: gpio
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: True
    name: "Bewässerung 2 manuell"
    on_press:
      then:
        - switch.toggle: b2
    on_click:
      min_length: 2s
      max_length: 4s
      then:
        - switch.turn_off: rel3
        - delay: 2s
        - switch.turn_off: rel1

## Ausgangsschalter (Relais)    
switch:
  - platform: gpio
    name: "12V Versorgung"
    id: "rel1"
    pin: GPIO16
    
  - platform: gpio
    name: "Strang 1"
    icon: "mdi:valve-open"
    id: "rel2"
    pin: GPIO14
    
  - platform: gpio
    name: "Strang 2"
    icon: "mdi:valve-open"
    id: "rel3"
    pin: GPIO12
    
  - platform: gpio
    name: "Dachbelüftung"
    icon: "mdi:fan" 
    id: "rel4"
    pin: GPIO13
    
    
## Automaten 
  - platform: template
    name: "Bewässerung 1"
    id: "b1"
    icon: "mdi:watering-can-outline"
    turn_on_action:
    - switch.turn_on: rel1
    - delay: 2s
    - switch.turn_on: rel2
    - delay: 15min
    - switch.turn_off: rel2
    - delay: 3s
    - switch.turn_off: rel1
    
    
  - platform: template
    name: "Bewässerung 2"
    id: "b2"
    icon: "mdi:watering-can-outline"
    turn_on_action:
    - switch.turn_on: rel1
    - delay: 2s
    - switch.turn_on: rel3
    - delay: 15min
    - switch.turn_off: rel3
    - delay: 3s
    - switch.turn_off: rel1
    

## 1Wire Sensoren
dallas:
  - pin: GPIO3

-lk-

See this note in the FAQ:

ESPHome reboots on purpose when something is not going right, e.g. wifi connection cannot be made

So if you don’t fix your wifi coverage your ESP is going to be unstable as well.

Also the native api component will reboot the ESP when HA can not connect to it for 15 minutes.
Native API Component — ESPHome

You could try to disable both reboot options. But it may become impossible to reconnect then without a reboot.

Thanks!

Does that mean, conversely, if I integrate an RTC and use it as a time source that the ESP would run stably in offline mode?

Alternatively, I can comment out the API completely, then I have to integrate the components via MQTT.
But that is not an obstacle at first, but since the WLAN connection is not permanently stable, it makes sense to install an RTC.
Or is the occasional synchronization with NTP sufficient?

greetings

Gerald

It has nothing to do with not having a RTC.

There’s an upstream issue with the low level wifi stack that requires the ESP to be rebooted to re-establish a wifi connection. So if you wifi is intermittently losing connection the ESP may reboot to reconnect.

You can try without Wifi and api and see if it stable then. (or disable the reboots).