Relay won´t go "off" when asked to

So I have a ventilation system with 4 positions 0,1,2, and 3. I connected 4 relayboard to it. That I connected to a ESP8266 and loaded with this sketch:

esphome:

  name: "wesp5"

esp8266:

  board: esp01_1m

# Enable logging

logger:

  baud_rate: 0

# Enable Home Assistant API

api:

ota:

wifi:

  ssid: !secret wifi_ssid

  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: "Esphome-Web-D7E69D"

    password: "pAPakYpmsgzC"

switch:

 

  - platform: gpio

    name: "Relay_1"

    pin: GPIO14

    inverted: True

    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio

    name: "Relay_2"

 

    pin: GPIO12

    inverted: True

    restore_mode: RESTORE_DEFAULT_OFF

   

  - platform: gpio

    name: "Relay_3"

    pin: GPIO13

    inverted: True

    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio

    name: "Relay_4"

    pin: GPIO15

    inverted: True

    restore_mode: RESTORE_DEFAULT_OFF

It doesn´t get any simpeler. And it works a treat! When I push button one in HA it goes to position 1 etc.

Now I want to have the ventilation react on the Co2 level in a room and I connected a Co2 sensor to a ESP8266 and had that working.

Made an automation in HA to have it go on:

Trigger

type: carbon_dioxide
platform: device
device_id: e05baeb2a6dce5fe7161124e9c559691
entity_id: sensor.senseair_co2_value
domain: sensor
above: 600

Action:

type: turn_on
device_id: 2fe28959819a45af0813c33184f5f725
entity_id: switch.relay_4
domain: switch

And off:

Trigger.

type: carbon_dioxide
platform: device
device_id: e05baeb2a6dce5fe7161124e9c559691
entity_id: sensor.senseair_co2_value
domain: sensor
below: 600

Action

type: turn_off
device_id: 2fe28959819a45af0813c33184f5f725
entity_id: switch.relay_4
domain: switch

(I used the visual editor to do this)

And it works. I expanded it to all the positions and CO2 levels.

But…
When it comes down to position 1, the automation tells the switch to go off, (I get confirmation in the ESPhome log of the ESP board that is connected to the relais), the light on the relaisboard goes out, but the ralais won´t fall off. I first thought it was a fault on the board, but changing to the spare relais (4) didn´t help.
Now if i hammer the switch on my phone a few times I can get it to go off, you hear a different click on the relaisboard. When I use the button to control the relay, it works 100 out of 100 times, on and off.
Could it be that the automation gets the relais to bounce? I learned about debouncing when getting familiar with Arduino. I tried to figure out how to debounce in this situation, but I don´t see how.

The relaisboard is this one
https://nl.banggood.com/Geekcreit-5V-4-Channel-Relay-Module-For-PIC-ARM-DSP-AVR-MSP430-Geekcreit-for-Arduino-products-that-work-with-official-Arduino-boards-p-87987.html?rmmds=myorder&cur_warehouse=CN
And I removed the jumper and used 3.3v for the control of the board and 5v for controlling the relays.

Any help for this newby is much appriciated!

Willem

A couple questions:

When you say it works when you “use the button” but not the automation, do you mean that flipping the switch in HA always works but the automation doesn’t?

Have you tried using a different pin on the ESP device?

How much current is going through these relays? One may be a bit sticky.

Hi Ben, yes I mean by flipping the switch it works, the automation works also, but not when the lowest position is shut off. I changed the pins of the relayboard-ESP, that didn´t do the trick. I am baffled because the switch works, I thought it must have something to do with the automation. on the other hand, HA responds with all the correct commands and confirmations and even the light on the relayboard turns of, that would indicate something on the relayboard, but why does the switch works well when the relayboard is the problem…

Hi Nickrout,
I had to dig in the papers of the ventilation, the position one is stated as average of 0,05A or 8 watt. Now when I start the unit it first runs the bypassvalve open/close and then it slowly starts the ventilator. So the start-amps might be higher then that. Can it be that if there is too low current over the relay, it won´t shut?
It´s a Songle SRD-05VDC-SL-C 5v/230v 10A relay and I checked the specs on the internet, there is not something like a minimum switching capacity. The drop-out voltage on the coil must be at least 10%, but I measure 5 to 0 volts drop of on the pin, and then again it drops off, but with a different sound…
I figured out there is a way to check this. I tested shutting off from position 1 to off by first putting it into position 2 and the shutting position 1 first.(position one shuts off the whole system) and the position 2.
I will try to put that in the automation and see what happens. Thanks for the input.

Try service calls rather than device stuff in your action. Usually works better.

I just took the position 1 out of the automation and switched on position 2 and the it works. So it seems the relay is not able to switch such a low current. Solution is to mount a smaller relay (2A) or make an automation where the switching from 1 to 0 will mean to first switch to pos 2 and then switch pos 1 and 2 off in that order.
Thanks for the input that helped me to a solution!
Willem.