Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent relay trigger on boot or reset with esphome code #24

Open
davidusb-geek opened this issue Dec 10, 2023 · 25 comments
Open

Prevent relay trigger on boot or reset with esphome code #24

davidusb-geek opened this issue Dec 10, 2023 · 25 comments

Comments

@davidusb-geek
Copy link

I'm using a very similar code to the one here for esphome and Home Assistant.
Everything works fine except that when the board resets or reboot all the relay are triggered.
Very inconvenient when controlling a garage door for example.
Any suggestions to solve this and avoid these relay triggering?
I have tried some solutions using the relay options on esphome (ALWAYS_OFF, etc.) but without success.
Any help will be much appreciated.

@Misiu
Copy link

Misiu commented Dec 18, 2023

@davidusb-geek what model or relay are you using (T-Relay, T-Relay 8, or T-Relay S3)?
I'm thinking about ordering those relays and I'd like to know did you solved the issue you described.
I also want to use it to control garage doors, so I can't allow random opening.
Thank you for the reply.

@davidusb-geek
Copy link
Author

I'm using the t-relay 8.
The issue is not solved, it's open.
So I disconnected the garage door for now.

@Misiu
Copy link

Misiu commented Dec 18, 2023

Sad to hear that.
Mayby try to contact support via website chat.

@davidusb-geek
Copy link
Author

Oh man, I've just solved this after months looking for a solution!
So the thing is that I've already tested with options mode: INPUT_PULLUP and inverted: True but without good results. But my problem was with indentation in my yaml for esphome. These parameters were just being ignored.
Today I just found that the correct way to pass this parameters and make my switch work without triggering at boot is this:

First define the output pins:

output:
  - platform: gpio
    pin: 
      number: GPIO33
      mode: INPUT_PULLUP
      inverted: True
    id: output_pin_1 # garage door

Then I define my switch for the garage door like this:

switch:
  - platform: output
    restore_mode: ALWAYS_OFF
    id: garage_door_bare_switch
    output: output_pin_1
  - platform: template
    restore_mode: ALWAYS_OFF
    name: "Garage Door Switch"
    icon: "mdi:garage"
    id: garage_door_bare_template_switch
    lambda: 'return id(garage_door_bare_switch).state;'
    turn_on_action:
      - switch.turn_on: garage_door_bare_switch
      - delay: 0.5s
      - switch.turn_off: garage_door_bare_switch
    turn_off_action:
      - switch.turn_on: garage_door_bare_switch
      - delay: 0.5s
      - switch.turn_off: garage_door_bare_switch

And that's it, works like charm.

@Misiu
Copy link

Misiu commented Dec 24, 2023

@davidusb-geek thank you for sharing the solution :)
Now I think I order the boards with confidence.
Did you maybe attach the board to a DIN rail? I was searching for a mounting solution and I would like to know what you choose.

@davidusb-geek davidusb-geek reopened this Dec 24, 2023
@davidusb-geek
Copy link
Author

Wait! I spoke too soon!
Actually the switch is not working. I thought it was fine because it didn't trigger at boot and it was showing fine on Home Assistant (and it was very late yesterday night) . But it is not working, the switch is not responding. My guess is that the INPUT_PULLUP is not supported by the hardware.
I'm reopening the issue :-(

@davidusb-geek
Copy link
Author

Yes I'm using DIN rail. I'll post the aliexpress link for that piece. It is a shame that I have this issue because the board quality is very good.

@davidusb-geek
Copy link
Author

davidusb-geek commented Dec 24, 2023

These DIN supports work fine: 1 Pair DRG-01 PCB Mounting Brackets Screws Green For DIN 35 Mounting Rails Adapter Replacements Parts
https://a.aliexpress.com/_EwgujuV

@lewisxhe
Copy link
Contributor

Relay4/realy8 should not have this problem, but there is indeed a chance that this problem will occur on realy6

@davidusb-geek
Copy link
Author

Ok I will try the INPUT_PULLUP option on relay4 or relay8 and see how it goes.

@davidusb-geek
Copy link
Author

davidusb-geek commented Dec 30, 2023

Relay4/realy8 should not have this problem, but there is indeed a chance that this problem will occur on realy6

I just tested it on relay 4 (ie. GPIO12), still doesn't works.

@Misiu
Copy link

Misiu commented Dec 30, 2023

Relay4/realy8 should not have this problem, but there is indeed a chance that this problem will occur on realy6

@lewisxhe could you please say more about relay6 (T-Relay S3)? I need to be 100% sure that the relays won't switch on/off after power loss. I want to control my garage door, so if this issue occurs my garage will open!

@davidusb-geek
Copy link
Author

Relay4/realy8 should not have this problem, but there is indeed a chance that this problem will occur on realy6

So I completely misinterpreted this reply.

@Misiu
Copy link

Misiu commented Dec 31, 2023

Relay4/realy8 should not have this problem, but there is indeed a chance that this problem will occur on realy6

So I completely misinterpreted this reply.

I'm not sure if I understand it right. I'm assuming it was related to product types and not to relay in T-Relay 8

@davidusb-geek
Copy link
Author

Ok, got it working now! Tested it for real and everything is working fine and as expected.

I tested many options and finally got it working with this configutaion:

output:
  - platform: gpio
    pin: 
      number: GPIO12
      inverted: True
      mode:
        pullup: True
        output: True
    id: output_pin_1 # garage door

The switch part of the yaml code is the same that I posted earlier in this issue.

Cheers!!!

@Misiu
Copy link

Misiu commented Jan 1, 2024

@davidusb-geek thank you for sharing a solution. Yesterday I ordered a T-relay 8 board, it should arrive in about 3-4 weeks so I'll also test all the options.

@szab0lcs
Copy link

szab0lcs commented Apr 3, 2024

I got it working with an easier method, the mode: OUTPUT was the key part:

sn74hc595:
  - id: "sn74hc595_hub"
    data_pin: 7
    clock_pin: 5
    latch_pin: 6
    sr_count: 2

# Individual outputs
switch:
  - platform: gpio
    # SN74HC595 Pin #0
    name: "Switch 1"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 0
      number: 0
      inverted: false
      mode: OUTPUT
    id: relay1

@forgotmyprozac
Copy link

forgotmyprozac commented Nov 17, 2024

@davidusb-geek

Ok, got it working now! Tested it for real and everything is working fine and as expected.

I tested many options and finally got it working with this configutaion:

output:
  - platform: gpio
    pin: 
      number: GPIO12
      inverted: True
      mode:
        pullup: True
        output: True
    id: output_pin_1 # garage door

The switch part of the yaml code is the same that I posted earlier in this issue.

Cheers!!!

Hey mate, I really like this board but the relays triggering on boot is killing me. What's the issue and how did you deal with it? I'm using ESPHome on the Lilygo T-Relay with Home Assistant. Thanks a bunch.

@davidusb-geek
Copy link
Author

@davidusb-geek

Hey mate, I really like this board but the relays triggering on boot is killing me. What's the issue and how did you deal with it? I'm using ESPHome on the Lilygo T-Relay with Home Assistant. Thanks a bunch.

Sorry to hear that. I also liked this board.
At first that solution that I posted worked and then some of these flickering came back.
I had enough with that so I changed to another board. I changed for the Kincony A4, working like charm, no more flickering problems.

Of course that requires changing the board. So probably try the solution proposed by @szab0lcs

@lewisxhe
Copy link
Contributor

@forgotmyprozac Can you please tell me what version of your board is? Can you take a picture of the front of the board for me to see?

@forgotmyprozac
Copy link

@lewisxhe

@forgotmyprozac Can you please tell me what version of your board is? Can you take a picture of the front of the board for me to see?

Images below. Thank you.

https://i.ibb.co/Hzg5BXc/PXL-20241118-064935332.jpg
https://i.ibb.co/19ZnpMT/PXL-20241118-064929583.jpg
https://i.ibb.co/h1c5ypK/PXL-20241118-064924938.jpg

@lewisxhe
Copy link
Contributor

This is an early version and can be solved by adding a resistor, see the picture
Relay
@forgotmyprozac

@lewisxhe
Copy link
Contributor

After this change, 74HC595 will be enabled through GPIO4, and only GPIO4 low level can drive the relay

@forgotmyprozac
Copy link

@lewisxhe
@davidusb-geek

After this change, 74HC595 will be enabled through GPIO4, and only GPIO4 low level can drive the relay

Thank you very much for the help. What wattage for the resistor and what AWG wire for IO4?

What do you mean "after normal power on, set IO4 to LOW" > Do I need to set this in my code? So it will boot up and be high, then the code will pull it low, then relays can be used?

How can we tell what version the board is? I have another one coming from Aliexpress and want to know if it will have the same problem.

https://www.aliexpress.com/item/1005005576226160.html?spm=a2g0o.order_list.order_list_main.5.2e521802TrkVnZ

Thank you

@lewisxhe
Copy link
Contributor

lewisxhe commented Nov 18, 2024

There is no requirement for the resistor wattage since it consumes very little current.

ESPHOME:


ARDUINO:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants