LilyGo-T-Relay icon indicating copy to clipboard operation
LilyGo-T-Relay copied to clipboard

Prevent relay trigger on boot or reset with esphome code

Open davidusb-geek opened this issue 1 year ago • 17 comments

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.

davidusb-geek avatar Dec 10 '23 20:12 davidusb-geek

@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.

Misiu avatar Dec 18 '23 09:12 Misiu

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

davidusb-geek avatar Dec 18 '23 09:12 davidusb-geek

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

Misiu avatar Dec 18 '23 09:12 Misiu

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.

davidusb-geek avatar Dec 23 '23 21:12 davidusb-geek

@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.

Misiu avatar Dec 24 '23 07:12 Misiu

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 avatar Dec 24 '23 12:12 davidusb-geek

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 avatar Dec 24 '23 12:12 davidusb-geek

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

davidusb-geek avatar Dec 24 '23 12:12 davidusb-geek

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

lewisxhe avatar Dec 25 '23 03:12 lewisxhe

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

davidusb-geek avatar Dec 25 '23 06:12 davidusb-geek

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.

davidusb-geek avatar Dec 30 '23 18:12 davidusb-geek

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!

Misiu avatar Dec 30 '23 21:12 Misiu

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.

davidusb-geek avatar Dec 31 '23 11:12 davidusb-geek

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

Misiu avatar Dec 31 '23 15:12 Misiu

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!!!

davidusb-geek avatar Jan 01 '24 17:01 davidusb-geek

@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.

Misiu avatar Jan 01 '24 17:01 Misiu

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

szab0lcs avatar Apr 03 '24 11:04 szab0lcs